MockH 1.12.2

dotnet add package MockH --version 1.12.2
                    
NuGet\Install-Package MockH -Version 1.12.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="MockH" Version="1.12.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MockH" Version="1.12.2" />
                    
Directory.Packages.props
<PackageReference Include="MockH" />
                    
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 MockH --version 1.12.2
                    
#r "nuget: MockH, 1.12.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 MockH@1.12.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=MockH&version=1.12.2
                    
Install as a Cake Addin
#tool nuget:?package=MockH&version=1.12.2
                    
Install as a Cake Tool

MockH

Build Coverage nuget Package

This library allows to mock HTTP responses for integration, component and acceptance tests of your projects written in C# / .NET 8/9/10 by hosting a webserver returning configured responses.

  • Fast and thread safe
  • Only a few dependencies
  • No configuration needed
  • Does not interfere with Kestrel or ASP.NET
  • Independent from the testing framework in place

Usage

using MockH;

[TestMethod]
public async Task TestSomething() 
{
   await using var server = await MockServer.RunAsync
   (
       On.Get("/users/1").Return(new User(...)),
       On.Get("/users/2").Respond(ResponseStatus.NoContent)
   );

   // access the server in your code via HTTP
   using var client = new HttpClient();

   await client.GetStringAsync(server.Url("/users/1"));
}

Basic Usage

// return a specific status code
On.Get("/ifail").Respond(ResponseStatus.InternalServerError);

// redirect the client
On.Get().Redirect("https://github.com");

// execute logic and return some simple text value
On.Get().Run(() => "42");

// execute logic and return some JSON
private record MyClass(int IntValue, string StringValue);

On.Get().Run(() => new MyClass(42, "The answer"));

// execute logic asynchronously
On.Get().Run(async () => await ...);

// access query parameters (GET /increment?=1)
On.Get("/increment").Run((int i) => i + 1);

// access path parameters (GET /increment/1)
On.Get("/increment/:i").Run((int i) => i + 1);

// access request body
On.Post().Run((MyClass body) => body);

// access request body as stream
On.Post().Run((Stream body) => body.Length);

Advanced Usage

// directly access request and response
On.Get().Run((IRequest request) => request.Respond().Status(ResponseStatus.BadRequest));

// return a handler provided by the GenHTTP framework, e.g. a website
// see https://genhttp.org/documentation/content/
// can be useful if you want to test some kind of website crawler
On.Get().Run(() => Listing.From(ResourceTree.FromDirectory("/var/www")));
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.12.2 72 12/23/2025
1.12.1 170 11/26/2025
1.12.0 278 11/12/2025
1.11.0 183 11/3/2025
1.10.0 170 1/31/2025
1.9.0 151 11/18/2024
1.7.0 156 6/4/2024
1.6.0 287 11/23/2023
1.5.0 256 7/3/2023
1.4.0 552 7/6/2022
1.3.0 438 12/22/2021
1.2.0 431 12/20/2021
1.1.0 417 12/3/2021
1.0.0 2,501 11/25/2021