Trellis.Testing
3.0.0-alpha.158
See the version list below for details.
dotnet add package Trellis.Testing --version 3.0.0-alpha.158
NuGet\Install-Package Trellis.Testing -Version 3.0.0-alpha.158
<PackageReference Include="Trellis.Testing" Version="3.0.0-alpha.158" />
<PackageVersion Include="Trellis.Testing" Version="3.0.0-alpha.158" />
<PackageReference Include="Trellis.Testing" />
paket add Trellis.Testing --version 3.0.0-alpha.158
#r "nuget: Trellis.Testing, 3.0.0-alpha.158"
#:package Trellis.Testing@3.0.0-alpha.158
#addin nuget:?package=Trellis.Testing&version=3.0.0-alpha.158&prerelease
#tool nuget:?package=Trellis.Testing&version=3.0.0-alpha.158&prerelease
Testing Utilities
FluentAssertions extensions, test builders, and fake implementations for testing Railway Oriented Programming patterns with Trellis.
Installation
dotnet add package Trellis.Testing
Quick Start
Result Assertions
using Trellis.Testing;
// Success
result.Should().BeSuccess()
.Which.Value.Should().Be(expected);
// Failure by type
result.Should().BeFailureOfType<NotFoundError>()
.Which.Should().HaveDetail("User not found");
Validation Error Assertions
result.Should()
.BeFailureOfType<ValidationError>()
.Which.Should()
.HaveFieldCount(3)
.And.HaveFieldError("firstName")
.And.HaveFieldError("email")
.And.HaveFieldErrorWithDetail("age", "Must be 18 or older");
Maybe Assertions
maybe.Should().HaveValue().Which.Should().Be("hello");
maybe.Should().BeNone();
Test Builders
using Trellis.Testing.Builders;
// Quick Result creation
var result = ResultBuilder.NotFound<User>("User not found");
// Complex validation errors
var error = ValidationErrorBuilder.Create()
.WithFieldError("email", "Email is required")
.WithFieldError("age", "Must be 18 or older")
.Build();
Fake Repository
using Trellis.Testing.Fakes;
var repo = new FakeRepository<User, UserId>();
var sut = new UserService(repo);
var result = await sut.CreateUserAsync(command, CancellationToken.None);
result.Should().BeSuccess();
repo.Exists(result.Value.Id).Should().BeTrue();
repo.PublishedEvents.Should().ContainSingle()
.Which.Should().BeOfType<UserCreatedEvent>();
TestActorProvider — Scoped Actor Switching
Eliminates try/finally boilerplate in authorization tests. WithActor temporarily switches the actor and restores the previous one on dispose.
using Trellis.Testing.Fakes;
var actorProvider = new TestActorProvider("admin", "Orders.Read", "Orders.Write");
// Temporarily switch to a restricted user
await using var scope = actorProvider.WithActor("user-1", "Orders.Read");
var result = await mediator.Send(new CreateOrderCommand());
result.Should().BeFailure();
// scope disposes → actor reverts to admin
ReplaceResourceLoader — DI Registration Replacement
Replaces existing IResourceLoader<TCommand, TResource> registrations in one call — no manual RemoveAll needed. Registered as scoped, matching the production lifetime.
using Trellis.Testing;
// Stateless fake — capture a pre-created instance
var fakeLoader = new FakeOrderResourceLoader(fakeRepo);
builder.ConfigureServices(services =>
{
services.ReplaceResourceLoader<CancelOrderCommand, Order>(_ => fakeLoader);
});
// Scoped dependency — resolve from the container
builder.ConfigureServices(services =>
{
services.ReplaceResourceLoader<CancelOrderCommand, Order>(
sp => new FakeOrderResourceLoader(sp.GetRequiredService<AppDbContext>()));
});
CreateClientWithActor — Integration Test HttpClient
Creates an HttpClient with the X-Test-Actor header pre-set for authorization integration tests.
using Trellis.Testing;
var client = _factory.CreateClientWithActor("user-1", "Orders.Create", "Orders.Read");
var response = await client.PostAsync("/api/orders", content);
Assertion API Reference
Result
| Method | Description |
|---|---|
BeSuccess() |
Assert result is success |
BeFailure() |
Assert result is failure |
BeFailureOfType<TError>() |
Assert failure with specific error type |
HaveValue(expected) |
Assert success value equals expected |
HaveValueMatching(predicate) |
Assert success value satisfies predicate |
HaveValueEquivalentTo(expected) |
Assert success value using structural comparison |
HaveErrorCode(code) |
Assert failure has specific error code |
HaveErrorDetail(detail) |
Assert failure has specific error detail |
HaveErrorDetailContaining(substring) |
Assert failure error detail contains substring |
Async variants (BeSuccessAsync, BeFailureAsync, BeFailureOfTypeAsync) are available for Task<Result<T>> and ValueTask<Result<T>>.
Error
| Method | Description |
|---|---|
Be(expected) |
Assert error equals expected (by Code) |
HaveCode(code) |
Assert error code |
HaveDetail(detail) |
Assert error detail message |
HaveDetailContaining(substring) |
Assert error detail contains substring |
HaveInstance(instance) |
Assert error instance identifier |
BeOfType<TError>() |
Assert error is of a specific type |
ValidationError
| Method | Description |
|---|---|
HaveFieldError(fieldName) |
Assert field has error |
HaveFieldErrorWithDetail(field, detail) |
Assert field has specific error |
HaveFieldCount(count) |
Assert number of field errors |
Maybe
| Method | Description |
|---|---|
HaveValue() |
Assert Maybe has a value |
BeNone() |
Assert Maybe has no value |
HaveValueEqualTo(expected) |
Assert value equals expected |
HaveValueMatching(predicate) |
Assert value satisfies predicate |
HaveValueEquivalentTo(expected) |
Assert value using structural comparison |
Before & After
| Before | After |
|---|---|
result.IsSuccess.Should().BeTrue() |
result.Should().BeSuccess() |
result.Error.Should().BeOfType<NotFoundError>() |
result.Should().BeFailureOfType<NotFoundError>() |
maybe.HasValue.Should().BeTrue() |
maybe.Should().HaveValue() |
Related Packages
- Trellis.Results — Core
Result<T>andMaybe<T>types - Trellis.DomainDrivenDesign — DDD building blocks
- Trellis.Authorization —
Actor,IActorProvider, authorization primitives
License
MIT — see LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- FluentAssertions (>= 7.2.2)
- Microsoft.AspNetCore.Mvc.Testing (>= 10.0.5)
- Microsoft.EntityFrameworkCore (>= 10.0.5)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.0.0)
- Microsoft.Identity.Client (>= 4.83.3)
- Trellis.Authorization (>= 3.0.0-alpha.158)
- Trellis.DomainDrivenDesign (>= 3.0.0-alpha.158)
- Trellis.Results (>= 3.0.0-alpha.158)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Trellis.Testing:
| Package | Downloads |
|---|---|
|
Trellis.Testing.AspNetCore
ASP.NET Core integration test utilities for Trellis - WebApplicationFactory helpers, DI service replacement, fake time providers, and MSAL token acquisition |
|
|
Trellis.Testing.Worker
Integration-test harness for BackgroundService workers built on Trellis - prewired IHost, FakeTimeProvider, TestActorProvider, domain-event capture, and tick-completion primitives |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-alpha.428 | 43 | 7/3/2026 |
| 3.0.0-alpha.425 | 130 | 6/27/2026 |
| 3.0.0-alpha.419 | 69 | 6/24/2026 |
| 3.0.0-alpha.418 | 151 | 6/23/2026 |
| 3.0.0-alpha.417 | 65 | 6/23/2026 |
| 3.0.0-alpha.397 | 97 | 6/18/2026 |
| 3.0.0-alpha.396 | 66 | 6/18/2026 |
| 3.0.0-alpha.394 | 81 | 6/18/2026 |
| 3.0.0-alpha.385 | 70 | 6/15/2026 |
| 3.0.0-alpha.382 | 70 | 6/12/2026 |
| 3.0.0-alpha.372 | 72 | 6/10/2026 |
| 3.0.0-alpha.360 | 86 | 6/7/2026 |
| 3.0.0-alpha.342 | 85 | 6/5/2026 |
| 3.0.0-alpha.337 | 77 | 6/3/2026 |
| 3.0.0-alpha.336 | 60 | 6/3/2026 |
| 3.0.0-alpha.304 | 79 | 5/29/2026 |
| 3.0.0-alpha.158 | 115 | 4/5/2026 |
| 3.0.0-alpha.157 | 73 | 4/4/2026 |
| 3.0.0-alpha.140 | 80 | 3/30/2026 |
| 3.0.0-alpha.137 | 84 | 3/27/2026 |