Fluent HttpClient test extensions for readable assertions on HttpResponseMessage. Provides lightweight helpers for ASP.NET Core integration testing, including ProblemDetails, ValidationProblemDetails, and JSON body assertions.
$ dotnet add package Gabbium.HttpClientTestExtensions
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:
HttpResponseMessage (e.g., ShouldBeOkWithBody<T>(), ShouldBeNoContent()).System.Text.Json with JsonSerializerDefaults.Web.ProblemDetails and ValidationProblemDetails.HttpClient.dotnet add package Gabbium.HttpClientTestExtensions
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");
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();
Constants.DefaultJsonOptions (configured with JsonSerializerDefaults.Web and JsonStringEnumConverter).Shouldly or FluentAssertions for body-level comparisons.xUnit or NUnit integration test suites.This project is licensed under the MIT License — see LICENSE for details.