Rig.TUnit.Http 0.1.0-beta.2

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

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 HttpClient with an injected HttpMessageHandler or named IHttpClientFactory registration.

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.HttpMock
  • Rig.TUnit.Http.Builders.HttpMockSetupBuilder
  • Rig.TUnit.Http.Builders.HttpMockResponseBuilder
  • Rig.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 disable StrictMatching.
  • Record mode captures nothingHttpMock.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.Json evaluator — it accepts a narrower subset than Newtonsoft.Json's JSONPath; stick to basic dotted-path + array-index forms.
  • Delay injection is driven by TimeProvider; freeze time via FakeTimeProvider for deterministic retry-policy tests.

Benchmarks

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