Rig.TUnit.Mediator 0.1.0-beta.2

This is a prerelease version of Rig.TUnit.Mediator.
dotnet add package Rig.TUnit.Mediator --version 0.1.0-beta.2
                    
NuGet\Install-Package Rig.TUnit.Mediator -Version 0.1.0-beta.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rig.TUnit.Mediator" Version="0.1.0-beta.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rig.TUnit.Mediator" Version="0.1.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="Rig.TUnit.Mediator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rig.TUnit.Mediator --version 0.1.0-beta.2
                    
#r "nuget: Rig.TUnit.Mediator, 0.1.0-beta.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rig.TUnit.Mediator@0.1.0-beta.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rig.TUnit.Mediator&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rig.TUnit.Mediator&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Tool

Rig.TUnit.Mediator

Pipeline-inspection helpers and an in-memory IMediator fake for Martin Othamar's Mediator library.

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 — inspection
  • Rig.TUnit.Mediator.Helpers.RequestSpy<TRequest, TResponse> — record calls
  • Rig.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 is public (or internal with [InternalsVisibleTo] for the test project).
  • Pipeline behaviour skipped — Mediator composes behaviours in DI registration order; check services.AddTransient order.

See docs/troubleshooting.md.

Provider quirks + edge cases

  • Mediator.SourceGenerator writes 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.

License

MIT. See LICENSE.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Rig.TUnit.Mediator:

Package Downloads
Rig.TUnit.Grpc

TUnit fixture for gRPC clients and servers - channel reconnection, deadline assertion, streaming helpers.

Rig.TUnit.WebAPI

TUnit fixture for ASP.NET Core Web APIs - WebApplicationFactory-style host, OpenAPI drift assertions, and per-test client isolation.

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.Microservices

Meta-package: Core + Mediator + Grpc + Outbox + Tracing + Jwt + Seq — the opinionated microservice testing kit.

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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta.2 132 4/27/2026
0.0.0-alpha.0.14 84 4/26/2026