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

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

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.Http for 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.ContractPact
  • Rig.TUnit.Microservices.Contracts.ContractInteraction
  • Rig.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 — set StrictMatching = false if the extra field is a deliberate backward- compatible addition.
  • ContractInteraction.Request.Body is null after read — call ContractInteraction.ReadBodyAsync() before asserting; the raw stream is read lazily.

See docs/troubleshooting.md.

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.

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