Rig.TUnit.Mediator
0.1.0-beta.2
dotnet add package Rig.TUnit.Mediator --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Mediator -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Mediator" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Mediator" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Mediator" />
paket add Rig.TUnit.Mediator --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Mediator, 0.1.0-beta.2"
#:package Rig.TUnit.Mediator@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Mediator&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Mediator&version=0.1.0-beta.2&prerelease
Rig.TUnit.Mediator
Pipeline-inspection helpers and an in-memory
IMediatorfake for Martin Othamar'sMediatorlibrary.
What this package is
A thin layer over the Mediator / Mediator.Abstractions packages that lets
you (a) assert the order and composition of pipeline behaviours executed for a
given request, (b) replace individual handlers with NSubstitute-backed fakes
without rewiring DI, and (c) capture every handled request/response pair for
after-the-fact assertions.
It does not wrap MediatR — the two libraries have incompatible source generators. See ADR-005 — family-level contracts for why contract tests live at the family base.
When to use it
- Testing a CQRS slice where a command/query goes through MediatR pipeline behaviours (validation, logging, retry).
- Asserting the behaviour-chain composition is what you expect.
- Stubbing a single handler while leaving the rest real.
- Not for: testing the generated source code of
Mediator.SourceGenerator— that is the library's job.
Prerequisites
- .NET 10 SDK
- Project under test references
Mediator+Mediator.SourceGenerator.
Quick start
using Rig.TUnit.Mediator.Helpers;
using Mediator;
var probe = new MediatorPipelineProbe();
var mediator = probe.BuildMediator(services =>
{
services.AddSingleton<IRequestHandler<Ping, Pong>>(
_ => new PingHandler());
});
var pong = await mediator.Send(new Ping("hi"));
await Assert.That(probe.RequestsHandled).HasCount(1);
Options
| Property | Type | Default | Description |
|---|---|---|---|
CaptureResponses |
bool |
true |
Record every handler's return value on the probe. |
FailOnUnhandled |
bool |
true |
Throw if a request reaches Send without a registered handler. |
Fixture + helper APIs
Rig.TUnit.Mediator.Helpers.MediatorPipelineProbe— inspectionRig.TUnit.Mediator.Helpers.RequestSpy<TRequest, TResponse>— record callsRig.TUnit.Mediator.Helpers.BehaviourOrderAssert— pipeline-order assertion
Per-test isolation
MediatorPipelineProbe is scoped — each test instantiates its own; handlers
and behaviours register per-probe. No static state.
Parallelism + performance
- Probe construction: ~5 ms (one DI container per probe).
- Handler dispatch: zero overhead vs bare Mediator — the probe intercepts via a pipeline behaviour registered at position 0.
- Safe under full test parallelism.
Troubleshooting
NoHandlerForRequest— the source generator did not discover your handler. Ensure it ispublic(orinternalwith[InternalsVisibleTo]for the test project).- Pipeline behaviour skipped —
Mediatorcomposes behaviours in DI registration order; checkservices.AddTransientorder.
Provider quirks + edge cases
Mediator.SourceGeneratorwrites the dispatcher at compile time — a handler added at runtime without source-gen re-run will not be found.- The probe's order assertion ignores framework-internal behaviours (exception interception, logging).
Benchmarks
See MediatorPipelineBenchmarks.cs;
tracked in benchmarks/baseline-005.json.
Related docs
License
MIT. See LICENSE.
| 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
- Bogus (>= 35.6.1)
- Mediator.Abstractions (>= 3.0.2)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Rig.TUnit.Core (>= 0.1.0-beta.2)
- TUnit.Core (>= 1.34.5)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Rig.TUnit.Mediator:
| Package | Downloads |
|---|---|
|
Rig.TUnit.WebAPI
TUnit fixture for ASP.NET Core Web APIs - WebApplicationFactory-style host, OpenAPI drift assertions, and per-test client isolation. |
|
|
Rig.TUnit.Grpc
TUnit fixture for gRPC clients and servers - channel reconnection, deadline assertion, streaming helpers. |
|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
|
|
Rig.TUnit
Convenience meta-package bundling Core + Mediator + Grpc + WebAPI — the default entry point for most projects. Use Rig.TUnit.All only when you need every package. |
|
|
Rig.TUnit.Microservices
Meta-package: Core + Mediator + Grpc + Outbox + Tracing + Jwt + Seq — the opinionated microservice testing kit. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 45 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 47 | 4/26/2026 |