Rig.TUnit.Microservices.Saga
0.1.0-beta.2
dotnet add package Rig.TUnit.Microservices.Saga --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Microservices.Saga -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Microservices.Saga" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Microservices.Saga" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Microservices.Saga" />
paket add Rig.TUnit.Microservices.Saga --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Microservices.Saga, 0.1.0-beta.2"
#:package Rig.TUnit.Microservices.Saga@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Microservices.Saga&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Microservices.Saga&version=0.1.0-beta.2&prerelease
Rig.TUnit.Microservices.Saga
SagaHarness— multi-step orchestration asserter that drives a saga through its state machine and asserts each compensating action fires on failure.
What this package is
A test harness for orchestration sagas (the long-running, eventually-
consistent cousin of a transaction). SagaHarness replays a sequence of
events and commands against the saga-under-test, lets you inject failures
at any step, and asserts that the correct compensating commands are issued.
Typical tests verify the happy path, each failure branch, and the
idempotency of compensations.
Works with any mediator-dispatched saga (Mediator or MediatR); you plug
the saga instance in and drive it via the harness' public methods.
When to use it
- Testing a checkout-style saga with N steps (reserve inventory, charge card, book shipping, notify customer).
- Verifying the compensation graph is complete and symmetric.
- Fuzzing failure timing — "if step 3 fails after step 4 commits, are we still consistent?"
- Not for: choreography-style sagas (each service handles its own events); those do not have a central orchestrator to test.
Prerequisites
- .NET 10 SDK
- Your saga is a class the harness can instantiate (parameterless or via provided factory delegate).
Quick start
using Rig.TUnit.Microservices.Saga;
var harness = new SagaHarness<CheckoutSaga>(
factory: () => new CheckoutSaga());
await harness.Advance(new InventoryReserved());
await harness.Advance(new PaymentCaptured());
await Assert.That(harness.PublishedCommands)
.Contains(c => c is BookShipping);
Options
| Property | Type | Default | Description |
|---|---|---|---|
DefaultTimeout |
TimeSpan |
5s |
Per-Advance deadline. |
ThrowOnUnexpectedPublish |
bool |
true |
Fail fast when the saga emits a command the test never expected. |
RecordCompensations |
bool |
true |
Capture compensating commands for assertions. |
Fixture + helper APIs
Rig.TUnit.Microservices.Saga.SagaHarness<TSaga>Rig.TUnit.Microservices.Saga.Assertions.CompensationAssertRig.TUnit.Microservices.Saga.Helpers.FailureInjector
Per-test isolation
Each SagaHarness owns its own saga instance and state machine. Harness
state is disposed at the end of the test; nothing bleeds across tests.
Parallelism + performance
- Harness construction: ~1 ms.
- Per-step cost: one saga method invocation + state snapshot — sub-millisecond for typical 5–10 step sagas.
- Safe under full parallelism.
Troubleshooting
UnexpectedPublishException— the saga emitted a command the test did not anticipate. Either add the expectation or assert the saga is correct.- Compensation missing —
harness.PublishedCommandsincludes both forward and compensating commands; filter withOfType<>to isolate.
Provider quirks + edge cases
- The harness does not persist saga state — if your saga uses
SnapshotStorefor durable state, stub it or the test will try to touch a real store. - Timer-triggered saga timeouts are simulated via
TimeProvider; advance virtual time withharness.AdvanceTime(TimeSpan).
Benchmarks
See SagaBenchmarks.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)
- 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 (2)
Showing the top 2 NuGet packages that depend on Rig.TUnit.Microservices.Saga:
| Package | Downloads |
|---|---|
|
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 46 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 47 | 4/26/2026 |