Functional.xunit
UnambitiousFx.Functional.xunit adds fluent assertions for Result and Maybe<T> in xUnit tests.
Introduction
Use this package to make tests expressive and intention-revealing:
- Assert success and failure without verbose boilerplate.
- Inspect typed failures with fluent chaining.
- Keep async and sync assertions consistent.
Install
dotnet add package UnambitiousFx.Functional.xunit
Core Concepts
Every assertion starts from ShouldBe() and then narrows the expected case:
result.ShouldBe().Success()for success branchesresult.ShouldBe().Failure()for failure branchesmaybe.ShouldBe().Some()andmaybe.ShouldBe().None()for optional values
This style keeps tests readable while still enabling deep checks through Where, WhichIs<TFailure>(), and And(...).
Simple Example
using UnambitiousFx.Functional.Failures;
using UnambitiousFx.Functional.xunit;
[Fact]
public void Parse_InvalidValue_ReturnsValidationFailure()
{
var result = Parse("abc");
result.ShouldBe()
.Failure()
.WhichIs<ValidationFailure>()
.And(failure => Assert.Contains("integer", failure.Message));
}
Advanced Concepts
- Result Assertion Patterns
- Maybe Assertion Patterns
- Async Assertion Patterns
- Test Organization and Diagnostics
Async Support
The package includes assertion extensions for ValueTask<Result<T>> and ValueTask<Maybe<T>>.
Use the same ShouldBe() pattern after awaiting values in your tests.