Fluent.Client.AwesomeAssertions
1.2.0
dotnet add package Fluent.Client.AwesomeAssertions --version 1.2.0
NuGet\Install-Package Fluent.Client.AwesomeAssertions -Version 1.2.0
<PackageReference Include="Fluent.Client.AwesomeAssertions" Version="1.2.0" />
<PackageVersion Include="Fluent.Client.AwesomeAssertions" Version="1.2.0" />
<PackageReference Include="Fluent.Client.AwesomeAssertions" />
paket add Fluent.Client.AwesomeAssertions --version 1.2.0
#r "nuget: Fluent.Client.AwesomeAssertions, 1.2.0"
#:package Fluent.Client.AwesomeAssertions@1.2.0
#addin nuget:?package=Fluent.Client.AwesomeAssertions&version=1.2.0
#tool nuget:?package=Fluent.Client.AwesomeAssertions&version=1.2.0
Fluent.Client.AwesomeAssertions
Created in Poland by Leszek Pomianowski and open-source community.
Assertion extensions for HttpResponseMessage and Task<HttpResponseMessage> built on top of AwesomeAssertions.
Getting started
dotnet add package Fluent.Client.AwesomeAssertions
https://www.nuget.org/packages/Fluent.Client.AwesomeAssertions
Fluent.Client is optional. This library works with standard HttpClient.PostAsync(), GetAsync(), etc.
dotnet add package Fluent.Client
using Fluent.Client;
using Fluent.Client.AwesomeAssertions;
[Fact]
public async Task CreateUser_ReturnsSuccess()
{
await client
.Post("/api/users", new { Name = "John" })
.Should()
.Succeed("because valid user data was provided");
}
Asserting responses
Assert 2xx:
await client
.Post("/api/users", new { Name = "John" })
.Should()
.Succeed("because the server returned 200 OK");
Assert specific status code:
await client
.Delete("/api/users/123")
.Should()
.HaveStatusCode(HttpStatusCode.NoContent, "because delete should return 204");
Assert failure (any non-2xx):
await client
.Post("/api/basket", new { CartItem = "esp32-dev-board" })
.Should()
.Fail("because the server returned 400 Bad Request");
Assert on the response body:
await client
.Authorize(token: "abc123")
.Get("/api/users/1", new { includeDetails = true })
.Should()
.Satisfy<User>(user =>
{
user.Name.Should().Be("John");
user.Id.Should().Be(1);
}, "because the server returned the expected JSON body");
Authorization
// Bearer token
await client
.Authorize(token: "abc123")
.Post("/v1/api/basket")
.Should()
.Succeed();
// Basic authentication
await client
.Authorize(username: "john", password: "potato")
.Get("/v1/api/basket", new { page = 1, limit = 2, sortBy = "dateAsc" })
.Should()
.HaveStatusCode(HttpStatusCode.Unauthorized, "because the credentials are invalid");
| Method | Header |
|---|---|
.Authorize(token: "...") |
Authorization: Bearer {token} |
.Authorize(token: "...", kind: AuthorizationType.OAuth) |
Authorization: OAuth {token} |
.Authorize(username, password) |
Authorization: Basic {base64(user:pass)} |
.Authorize(key: "...") |
api-key: {key} |
.Authorize(..., header: "X-Auth-Token") |
X-Auth-Token: {value} |
Integration testing
[Collection("Integration Tests")]
public sealed class OrderWorkflowTests(AspireAppHostFixture app)
{
[Fact]
public async Task Order_WhenCreatedAndProcessed_CompletesSuccessfully()
{
Guid orderId = Guid.NewGuid();
await app.Client
.Authorize(token: "jwt-token")
.Put($"v1/orders/{orderId}", new { ProductId = "SKU-001", Quantity = 2 })
.Should()
.Succeed("because order creation should be accepted");
await app.Client
.Authorize(token: "jwt-token")
.Get($"v1/orders/{orderId}")
.Should()
.Satisfy<OrderResponse>(order =>
{
order.Status.Should().Be("Pending");
order.Id.Should().Be(orderId);
});
await app.Client
.Authorize(token: "jwt-token")
.Put($"v1/orders/{orderId}/confirm")
.Should()
.Succeed("because order confirmation should succeed");
await app.Client
.Authorize(token: "jwt-token")
.Put($"v1/orders/{orderId}/complete", new { Note = "Delivered" })
.Should()
.Succeed("because order completion should succeed");
}
}
API reference
| Method | Description |
|---|---|
Succeed() |
Asserts 2xx status code |
Succeed(HttpStatusCode) |
Asserts specific success status code |
Fail() |
Asserts non-2xx status code |
HaveStatusCode(HttpStatusCode) |
Asserts exact status code |
Satisfy<T>(Action<T>) |
Deserializes body to T and runs assertions |
Satisfy<T> uses the following JsonSerializerOptions by default:
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
AllowTrailingCommas = true,
WriteIndented = true,
IncludeFields = false,
Converters = { new JsonStringEnumConverter() }
}
License
Fluent.Client.AwesomeAssertions is free and open source software licensed under the MIT License. You can use it in private and commercial projects.
Keep in mind that you must include a copy of the license in your project.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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 is compatible. 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. |
| .NET Framework | net472 is compatible. net48 was computed. net481 is compatible. |
-
.NETFramework 4.7.2
- AwesomeAssertions (>= 9.0.0)
- System.Text.Json (>= 6.0.11)
-
.NETFramework 4.8.1
- AwesomeAssertions (>= 9.0.0)
- System.Text.Json (>= 6.0.11)
-
net10.0
- AwesomeAssertions (>= 9.0.0)
-
net8.0
- AwesomeAssertions (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.