MockH 1.13.0
dotnet add package MockH --version 1.13.0
NuGet\Install-Package MockH -Version 1.13.0
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.13.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MockH" Version="1.13.0" />
<PackageReference Include="MockH" />
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.13.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MockH, 1.13.0"
#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.13.0
#: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.13.0
#tool nuget:?package=MockH&version=1.13.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MockH
This library provides a .NET / C# HTTP mock server for integration, component and acceptance tests by returning configured responses.
- Fast and thread safe, based on https://genhttp.org
- Only a few dependencies
- No configuration needed
- Does not interfere with Kestrel or ASP.NET
- Independent of 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 | 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. net11.0 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- GenHTTP.Core (>= 11.0.0)
- GenHTTP.Modules.Functional (>= 11.0.0)
- GenHTTP.Modules.Redirects (>= 11.0.0)
-
net11.0
- GenHTTP.Core (>= 11.0.0)
- GenHTTP.Modules.Functional (>= 11.0.0)
- GenHTTP.Modules.Redirects (>= 11.0.0)
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.13.0 | 43 | 9/10/2026 |
| 1.12.3 | 167 | 2/19/2026 |
| 1.12.2 | 219 | 12/23/2025 |
| 1.12.1 | 216 | 11/26/2025 |
| 1.12.0 | 330 | 11/12/2025 |
| 1.11.0 | 229 | 11/3/2025 |
| 1.10.0 | 216 | 1/31/2025 |
| 1.9.0 | 198 | 11/18/2024 |
| 1.7.0 | 200 | 6/4/2024 |
| 1.6.0 | 334 | 11/23/2023 |
| 1.5.0 | 293 | 7/3/2023 |
| 1.4.0 | 595 | 7/6/2022 |
| 1.3.0 | 484 | 12/22/2021 |
| 1.2.0 | 475 | 12/20/2021 |
| 1.1.0 | 454 | 12/3/2021 |
| 1.0.0 | 2,549 | 11/25/2021 |