VOOZH about

URL: https://www.nuget.org/packages/MockH/

⇱ NuGet Gallery | MockH 1.12.3




MockH 1.12.3

dotnet add package MockH --version 1.12.3
 
 
NuGet\Install-Package MockH -Version 1.12.3
 
 
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.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MockH" Version="1.12.3" />
 
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.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MockH, 1.12.3"
 
 
#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.3
 
 
#: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.3
 
Install as a Cake Addin
#tool nuget:?package=MockH&version=1.12.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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.3 136 2/19/2026
1.12.2 203 12/23/2025
1.12.1 199 11/26/2025
1.12.0 316 11/12/2025
1.11.0 214 11/3/2025
1.10.0 201 1/31/2025
1.9.0 183 11/18/2024
1.7.0 183 6/4/2024
1.6.0 319 11/23/2023
1.5.0 279 7/3/2023
1.4.0 578 7/6/2022
1.3.0 468 12/22/2021
1.2.0 452 12/20/2021
1.1.0 441 12/3/2021
1.0.0 2,530 11/25/2021