Gabbium.HttpClientTestExtensions 1.0.1

dotnet add package Gabbium.HttpClientTestExtensions --version 1.0.1
                    
NuGet\Install-Package Gabbium.HttpClientTestExtensions -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Gabbium.HttpClientTestExtensions" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gabbium.HttpClientTestExtensions" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Gabbium.HttpClientTestExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Gabbium.HttpClientTestExtensions --version 1.0.1
                    
#r "nuget: Gabbium.HttpClientTestExtensions, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Gabbium.HttpClientTestExtensions@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Gabbium.HttpClientTestExtensions&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Gabbium.HttpClientTestExtensions&version=1.0.1
                    
Install as a Cake Tool

HttpClient Test Extensions

GitHub last commit Sonar Quality Gate Sonar Coverage


๐Ÿ“Œ About

Gabbium.HttpClientTestExtensions provides fluent, readable assertions for HttpResponseMessage in integration and functional tests. It focuses on clarity (response.ShouldBeOkWithBody<T>()) and common web testing scenarios, including ProblemDetails and ValidationProblemDetails.

Use it to:

  • Make readable and expressive HTTP assertions in tests.
  • Standardize JSON body reading and type checks across test suites.
  • Assert ProblemDetails-based error responses consistently.

โœจ Highlights

  • โœ… Fluent assertions for HttpResponseMessage (e.g., ShouldBeOkWithBody<T>(), ShouldBeNoContent()).
  • ๐Ÿ“ฆ Built-in JSON handling using System.Text.Json with JsonSerializerDefaults.Web.
  • ๐Ÿงฐ First-class support for ProblemDetails and ValidationProblemDetails.
  • ๐Ÿงช Designed for ASP.NET Core integration/functional tests with HttpClient.
  • ๐Ÿชถ Lightweight and dependency-minimal.

๐Ÿ“ฆ Installation

dotnet add package Gabbium.HttpClientTestExtensions

๐Ÿš€ Quick Start

using System.Net;
using System.Net.Http.Json;
using HttpClientTestExtensions; // your library namespace

public sealed record UserDto(Guid Id, string Name);

var response = await client.PostAsJsonAsync("/api/users", new { Name = "Alice" });

// Created with body + checks Location header against the created resource
var created = await response.ShouldBeCreatedWithBodyAndLocation<UserDto>(x => $"/api/users/{x.Id}");

// Later on...
var get = await client.GetAsync($"/api/users/{created.Id}");
var body = await get.ShouldBeOkWithBody<UserDto>();
body.Name.ShouldBe("Alice");

๐Ÿ”Ž Common Scenarios

response.ShouldBeOk();
await response.ShouldBeOkWithBody<MyDto>();

response.ShouldBeCreated();
await response.ShouldBeCreatedWithBody<MyDto>();
await response.ShouldBeCreatedWithBodyAndLocation<MyDto>(x => $"/api/items/{x.Id}");

response.ShouldBeNoContent();

await response.ShouldBeBadRequestWithValidation();
await response.ShouldBeBadRequestWithProblem();

response.ShouldBeUnauthorized();
response.ShouldBeForbidden();

await response.ShouldBeNotFoundWithProblem();
await response.ShouldBeConflictWithProblem();
await response.ShouldBeUnprocessableEntityWithProblem();

๐Ÿ’ก Notes

  • Uses Constants.DefaultJsonOptions (configured with JsonSerializerDefaults.Web and JsonStringEnumConverter).
  • Works seamlessly with Shouldly or FluentAssertions for body-level comparisons.
  • Perfect for xUnit or NUnit integration test suites.

๐Ÿชช License

This project is licensed under the MIT License โ€” see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 161 10/11/2025