Fluent.Unions.TUnit
1.1.0
dotnet add package Fluent.Unions.TUnit --version 1.1.0
NuGet\Install-Package Fluent.Unions.TUnit -Version 1.1.0
<PackageReference Include="Fluent.Unions.TUnit" Version="1.1.0" />
<PackageVersion Include="Fluent.Unions.TUnit" Version="1.1.0" />
<PackageReference Include="Fluent.Unions.TUnit" />
paket add Fluent.Unions.TUnit --version 1.1.0
#r "nuget: Fluent.Unions.TUnit, 1.1.0"
#:package Fluent.Unions.TUnit@1.1.0
#addin nuget:?package=Fluent.Unions.TUnit&version=1.1.0
#tool nuget:?package=Fluent.Unions.TUnit&version=1.1.0
![]()
Fluent.Unions.TUnit
Adds IsOk, IsError, IsSome and IsNone for Result, Result<T> and Option<T> to TUnit assertions. Awaiting an assertion returns the value or the error, and a failure message names the actual state.
Installation
dotnet add package Fluent.Unions.TUnit
Usage
using TUnit.Assertions.Extensions;
Result<Order> placed = await orders.PlaceAsync(request);
Order order = await Assert.That(placed).IsOk();
// passes when the order was placed, and returns it
Result missing = await orders.DeleteAsync(unknownId);
NotFoundException error = await Assert.That(missing).IsError<NotFoundException>();
// passes when the error is a NotFoundException, and returns it
await Assert.That(customer.Nickname).IsNone();
// passes when the customer has no nickname
The extension methods are generated into TUnit.Assertions.Extensions, which TUnit projects import globally. The package depends on TUnit.Assertions only, so the assertions also work in a test project of another framework.
With your own result type
Assert a result type you declare with [FluentResult<TError>] through AsResult(). C# does not allow the result interface as a type argument, so the generated assertions cannot take your type directly. The default types keep Assert.That(result).IsOk(). See Your own Result type.
await Assert.That(result.AsResult()).IsOk();
await Assert.That(result.AsResult()).IsError();
NotFound notFound = await Assert.That(result.AsResult().ErrorCase<NotFound>()).IsSome(); // a case of an error union
The assertion methods behind Assert.That(...) are not public extensions, so result.IsOk(); does not compile instead of asserting nothing.
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Fluent.Unions (>= 1.1.0)
- TUnit.Assertions (>= 1.87.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.