Rig.TUnit.Microservices.Saga 0.1.0-beta.2

This is a prerelease version of Rig.TUnit.Microservices.Saga.
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
                    
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.Microservices.Saga" 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.Microservices.Saga" Version="0.1.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="Rig.TUnit.Microservices.Saga" />
                    
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.Microservices.Saga --version 0.1.0-beta.2
                    
#r "nuget: Rig.TUnit.Microservices.Saga, 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.Microservices.Saga@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.Microservices.Saga&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rig.TUnit.Microservices.Saga&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Tool

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.CompensationAssert
  • Rig.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 missingharness.PublishedCommands includes both forward and compensating commands; filter with OfType<> to isolate.

See docs/troubleshooting.md.

Provider quirks + edge cases

  • The harness does not persist saga state — if your saga uses SnapshotStore for 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 with harness.AdvanceTime(TimeSpan).

Benchmarks

See SagaBenchmarks.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 (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