Fluent.Unions.FluentAssertions
1.1.0
dotnet add package Fluent.Unions.FluentAssertions --version 1.1.0
NuGet\Install-Package Fluent.Unions.FluentAssertions -Version 1.1.0
<PackageReference Include="Fluent.Unions.FluentAssertions" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.FluentAssertions" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.FluentAssertions" />
paket add Fluent.Unions.FluentAssertions --version 1.1.0
#r "nuget: Fluent.Unions.FluentAssertions, 1.1.0"
#:package Fluent.Unions.FluentAssertions@1.1.0
#addin nuget:?package=Fluent.Unions.FluentAssertions&version=1.1.0
#tool nuget:?package=Fluent.Unions.FluentAssertions&version=1.1.0
![]()
Fluent.Unions.FluentAssertions
Adds Should() for Result, Result<T> and Option<T> to FluentAssertions version 8. It builds on Fluent.Unions, and a failure message names the actual state.
License notice. FluentAssertions version 8 and later is commercial software from Xceed. It is free for open-source projects and non-commercial use, and commercial use requires a paid license. This package itself stays under the license of Fluent.Unions, but it depends on FluentAssertions 8. For commercial work without a FluentAssertions license, use Fluent.Unions.AwesomeAssertions, which has the same assertions for AwesomeAssertions (Apache-2.0).
Installation
dotnet add package Fluent.Unions.FluentAssertions
Usage
Assert on an Ok result and its value.
using FluentAssertions;
using Fluent.Unions.FluentAssertions;
Result<Order> placed = await orders.PlaceAsync(request);
placed.Should().BeOk().Which.Total.Should().Be(49.90m);
Assert on the exception inside an error. * and ? are wildcards in the message pattern.
Result<Order> missing = await orders.FindAsync(unknownId);
missing.Should().BeError<NotFoundException>().WithMessage("Order * was not found");
Assert on an option.
Option<string> nickname = customer.Nickname;
nickname.Should().BeSomeWithValue("ada");
Assert on the inner exceptions of an aggregate error, such as the output of Validate.
registered.Should().BeAggregateError().WithInnerCount(2);
With your own result type
Should() works on a result type you declare with [FluentResult<TError>] when it has a value. There are no assertions for the value-less Result of your own type. BeError<TCase>() also matches a case inside an error union. See Your own Result type.
StockResult<Reservation> reserved = await stock.ReserveAsync(sku, quantity);
reserved.Should().BeError<OutOfStock>().Which.Sku.Should().Be("KB-1");
A default result counts as an error, so BeError() passes for it and BeOk() fails.
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- FluentAssertions (>= 8.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.