Rig.TUnit.Microservices.Contracts
0.1.0-beta.2
dotnet add package Rig.TUnit.Microservices.Contracts --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Microservices.Contracts -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Microservices.Contracts" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Microservices.Contracts" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Microservices.Contracts" />
paket add Rig.TUnit.Microservices.Contracts --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Microservices.Contracts, 0.1.0-beta.2"
#:package Rig.TUnit.Microservices.Contracts@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Microservices.Contracts&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Microservices.Contracts&version=0.1.0-beta.2&prerelease
Rig.TUnit.Microservices.Contracts
Pact-style contract-test harness:
ContractPact+ContractInteraction+ builders that replay consumer expectations against a provider host.
What this package is
A lightweight in-process alternative to Pact.Net. A ContractPact captures
the set of HTTP or gRPC interactions a consumer expects; the harness replays
them against the provider's actual WebApplicationFactory host and verifies
every response matches the expectation. Shipped as a family-level contract
(ADR-005) so every microservice in the estate has the same verifier surface.
It does not broker files with a remote Pact Broker — the assumption is that contracts are versioned alongside the consumer code in a shared package.
When to use it
- Provider-side verification: "does my microservice still satisfy what the consumer recorded last week?"
- Consumer-side recording: capture the expected interactions inside a unit
test; commit the
.contract.json. - Not for: end-to-end tests where you want a real network between parties — that's an integration test, not a contract test.
Prerequisites
- .NET 10 SDK
- Consumer project has
Rig.TUnit.Httpfor building interactions.
Quick start
using Rig.TUnit.Microservices.Contracts;
var pact = new ContractPact(
consumer: "orders-web",
provider: "orders-api",
interactions: Array.Empty<ContractInteraction>());
// Verify against the running provider fixture.
await pact.VerifyAsync(providerBaseUri: new Uri("http://localhost:5097"));
Options
| Property | Type | Default | Description |
|---|---|---|---|
StrictMatching |
bool |
true |
Reject responses with unexpected extra fields. |
TimeoutPerInteraction |
TimeSpan |
10s |
Per-replay HTTP timeout. |
CaseSensitiveHeaders |
bool |
false |
Off-by-default per HTTP spec. |
Fixture + helper APIs
Rig.TUnit.Microservices.Contracts.ContractPactRig.TUnit.Microservices.Contracts.ContractInteractionRig.TUnit.Microservices.Contracts.Helpers.PactFileReader/PactFileWriter
Per-test isolation
Each ContractPact is a value-type recording; verification runs against the
provider-supplied base URI. No shared state.
Parallelism + performance
- Per-interaction replay: ~2-5 ms (in-process
HttpClient). - Safe under full parallelism — each test owns its pact instance.
Troubleshooting
- Verification fails with
ExtraField(s) present in response— setStrictMatching = falseif the extra field is a deliberate backward- compatible addition. ContractInteraction.Request.Bodyis null after read — callContractInteraction.ReadBodyAsync()before asserting; the raw stream is read lazily.
Provider quirks + edge cases
- JSON comparison is structural (property-set equality), not byte-exact — field ordering is ignored.
- gRPC interactions serialise via Protobuf wire format; message equality is byte-exact because that is what the wire sees.
Benchmarks
See ContractsBenchmarks.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.Http (>= 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.Contracts:
| 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 | 45 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 55 | 4/26/2026 |