Rig.TUnit.Http
0.1.0-beta.2
dotnet add package Rig.TUnit.Http --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Http -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Http" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Http" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Http" />
paket add Rig.TUnit.Http --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Http, 0.1.0-beta.2"
#:package Rig.TUnit.Http@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Http&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Http&version=0.1.0-beta.2&prerelease
Rig.TUnit.Http
In-memory HTTP mock with matcher matrix, response builders, scenario state machine, delay / jitter / failure injection, and record/replay.
What this package is
A rich in-memory HTTP mock. Supports:
- Matcher matrix — method, path, headers, query, JSONPath, SOAP body.
- Response builders — status, headers, JSON, binary, server-sent events.
- Scenario state machine — per-call sequential responses (first call returns A, second B, …).
- Failure injection — delay + jitter + intermittent-5xx for resilience testing.
- Record / replay — capture real exchanges and replay offline.
- Call verification —
mock.Verify(method, path).Called(N).
Every setup must end with .And() so the fluent chain materialises
into the mock.
When to use it
- Testing any HTTP client code — service SDK wrappers, retry policies, circuit breakers.
- Replay-testing production-shape responses without hitting the real service.
- Verifying resilience policies (retries, timeouts) against synthetic failure patterns.
- Not for: integration tests requiring real HTTP semantics (TLS,
HTTP/2, connection pooling) — use
WebApplicationFactory.
Prerequisites
- .NET 10 SDK
- Consumer uses
HttpClientwith an injectedHttpMessageHandleror namedIHttpClientFactoryregistration.
Quick start
using Rig.TUnit.Http;
using System.Net;
var mock = new HttpMock();
mock.When.Post().Path("/orders")
.JsonPathEquals("customer.id", "c-1")
.Responds()
.WithStatus(HttpStatusCode.Created)
.WithJson("{\"id\":42}")
.And();
var client = mock.CreateClient();
Options
| Property | Type | Default | Description |
|---|---|---|---|
DefaultBaseAddress |
Uri |
new Uri("http://mock") |
Base URI for CreateClient |
StrictMatching |
bool |
true |
Fail on request with no matching setup |
CaseSensitiveHeaders |
bool |
false |
Match headers case-insensitively per HTTP spec |
Fixture + helper APIs
Rig.TUnit.Http.HttpMockRig.TUnit.Http.Builders.HttpMockSetupBuilderRig.TUnit.Http.Builders.HttpMockResponseBuilderRig.TUnit.Http.Helpers.HttpMockRecorder
Per-test isolation
Each HttpMock instance is scoped. No shared state; parallel tests
each own their mock. Safe under full parallelism.
Parallelism + performance
- Zero container startup.
- Per-request: matcher evaluation + response build ~500 µs.
- Safe under full parallelism.
Troubleshooting
- 404 / handler returns default — missing
.And()terminator. Every setup chain must end with.And()to register. UnmatchedRequestException— a request arrived with no matching setup. Either add a matcher or disableStrictMatching.- Record mode captures nothing —
HttpMock.RecordAgainst(handler)must be called BEFORE the test's HTTP calls; recording a completed exchange log is not supported.
See docs/troubleshooting.md#http.
Provider quirks + edge cases
- Scenario state machine resets on
mock.Reset(); between tests is implicit (each test owns its mock). - JSONPath matching uses the
System.Text.Jsonevaluator — it accepts a narrower subset thanNewtonsoft.Json's JSONPath; stick to basic dotted-path + array-index forms. - Delay injection is driven by
TimeProvider; freeze time viaFakeTimeProviderfor deterministic retry-policy tests.
Benchmarks
See HttpMockBenchmarks.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.Http:
| Package | Downloads |
|---|---|
|
Rig.TUnit.Microservices.Contracts
TUnit fixture for consumer-driven contract tests - Pact-friendly helpers and contract-drift assertions. |
|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 43 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 48 | 4/26/2026 |