Rig.TUnit.Microservices.EventSourcing
0.1.0-beta.2
dotnet add package Rig.TUnit.Microservices.EventSourcing --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Microservices.EventSourcing -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Microservices.EventSourcing" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Microservices.EventSourcing" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Microservices.EventSourcing" />
paket add Rig.TUnit.Microservices.EventSourcing --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Microservices.EventSourcing, 0.1.0-beta.2"
#:package Rig.TUnit.Microservices.EventSourcing@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Microservices.EventSourcing&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Microservices.EventSourcing&version=0.1.0-beta.2&prerelease
Rig.TUnit.Microservices.EventSourcing
Given/When/Then harness for event-sourced aggregates with
AggregateAssert.Raised<T>().WithData(…)andEventCatalogueAssertfor schema-evolution verification.
What this package is
The testing harness for event-sourced aggregates. EventSourcingHarness <TAggregate> lets you rehydrate an aggregate from a list of past events,
execute a command, and assert on the events it raises.
EventCatalogueAssert takes a declared catalogue (version → event-type
list) and verifies the aggregate's rehydration path still accepts every
historical event shape — the load-bearing check for additive schema
evolution.
When to use it
- Unit-testing an event-sourced aggregate.
- Verifying schema-evolution compatibility after a new event version lands.
- Not for: integration tests that require a real event store — layer
with
Rig.TUnit.Databases.NoSql.KurrentDb.
Prerequisites
- .NET 10 SDK
- Your aggregate exposes a
Rehydrate(events)factory and aPending/ClearPendingraised-event pattern (or equivalent).
Quick start
using Rig.TUnit.Microservices.EventSourcing;
var harness = new EventSourcingHarness<Order>(
rehydrate: events => Order.Rehydrate(events),
getRaised: o => o.Pending,
clearRaised: o => o.ClearPending());
harness.Given(new OrderCreated("O-1", 100m))
.When(o => o.Approve())
.Then(new OrderApproved("O-1"));
Options
| Property | Type | Default | Description |
|---|---|---|---|
RequireExactEventOrder |
bool |
true |
Fail if raised event order does not match Then(…) |
IgnoreEventMetadata |
bool |
true |
Scrub EventId / Timestamp in comparisons |
CatalogueSourceType |
Type? |
null |
Optional EventCatalogue type for schema checks |
Fixture + helper APIs
Rig.TUnit.Microservices.EventSourcing.EventSourcingHarness<TAggregate>Rig.TUnit.Microservices.EventSourcing.Assertions.AggregateAssertRig.TUnit.Microservices.EventSourcing.Assertions.EventCatalogueAssert
Per-test isolation
Each harness instance owns its own aggregate state — no shared statics, no cross-test bleed. Safe under full parallelism.
Parallelism + performance
- Harness construction: ~1 µs.
- Rehydrate + apply: dominated by aggregate's own logic, typically sub-millisecond.
- Safe under full parallelism.
Troubleshooting
Then(expected)fails with length mismatch — aggregate raised more or fewer events than expected. Strict mode is the default; switch toRequireExactEventOrder=falseif the contract allows extras.EventCatalogueAssertfails after version bump — a new event type was added to the code but not to the catalogue declaration; update both in lockstep.
See docs/troubleshooting.md#event-sourcing.
Provider quirks + edge cases
- The harness does not persist events between
Whencalls — each call reapplies the full event stream. Aggregates that cache state across calls break this assumption; seeWithCarriedStateopt-in. - Event IDs are typically scrubbed in comparisons because they are
generated at raise-time; the
IgnoreEventMetadataflag controls this.
Benchmarks
See EventSourcingBenchmarks.cs;
baseline 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.EventSourcing:
| 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 | 50 | 4/26/2026 |