Enhanced.Testing.Component.WireMock 1.6.0

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

Enhanced.Testing.Component.WireMock

NuGet

A WireMock.Net harness for Enhanced.Testing.Component: fakes external HTTP APIs with an in-process server instead of calling real services. No Docker needed.

dotnet add package Enhanced.Testing.Component.WireMock

Usage

var quotesApi = new WireMockHarness { ConfigurationKey = "QuotesApi:BaseUrl" };

var component = ComponentBuilder.Create<Program>()
                                .AddHarness(quotesApi)
                                .AddHarness(http)
                                .Build();

The server starts with the component on a free port, and its URL is passed to the application as the QuotesApi:BaseUrl setting. Point the application's HttpClient at that setting.

In a test, stub the external API, call the application, and verify the calls:

quotesApi.Server
         .Given(Request.Create().WithPath("/quote").UsingGet())
         .RespondWith(Response.Create().WithStatusCode(200).WithBody("Stay hungry"));

var response = await http.CreateClient().GetStringAsync("/quote");

Assert.Equal("Stay hungry", response);
Assert.Single(quotesApi.Server.LogEntries);
  • Server is the WireMockServer, for stubbing and verification.
  • Reset() removes stubs, scenarios and the request log; call it between tests that share the harness.
  • BaseAddress and CreateClient() give the test the server's address or an HttpClient for it.
  • ConfigureServer customizes the WireMockServerSettings before the server starts.

Service discovery

An application that finds its dependencies by name with Microsoft.Extensions.ServiceDiscovery needs no extra configuration key. Give the harness the service name, and it registers the server as that service:

var payments = new WireMockHarness { ServiceName = "payments" };
var greeter = new WireMockHarness { ServiceName = "greeter", EndpointName = "grpc", UseHttp2 = true };
The application calls Harness
http://payments or https+http://payments ServiceName = "payments"
http://_api.payments (a named endpoint) ServiceName = "payments", EndpointName = "api"

The address is passed to the application as Services:{ServiceName}:{EndpointName}:0; EndpointName is http unless set. The server speaks plain HTTP, so a client fixed to https://payments cannot be pointed at it. Endpoints of the same service listed in the application's own configuration are not removed.

Faking a gRPC service

The same harness fakes a gRPC service the application calls. Set UseHttp2, and describe calls and responses with the generated message types:

var greeter = new WireMockHarness { ConfigurationKey = "Greeter:Address", UseHttp2 = true };
greeter.Server
       .Given(Request.Create()
                     .UsingGrpc(Greeter.Descriptor, nameof(Greeter.GreeterClient.SayHelloAsync))
                     .WithGrpcMessage<HelloRequest>(request => request.Name == "world"))
       .RespondWith(Response.Create().WithGrpcMessage(new HelloReply { Message = "Hello, world" }));
  • UsingGrpc(service, method) takes the service descriptor from the generated code and a method name. Name the method with nameof on the generated client, so a wrong name does not compile. Without generated code, pass the full method name as a string: UsingGrpc("greet.Greeter/SayHello").
  • WithGrpcMessage<TRequest>(predicate) matches the request message; leave it out to match every call of the method.
  • WithGrpcMessage(message) responds with a message, and WithGrpcStatus(StatusCode.NotFound, "...") fails the call with a status.
  • WithGrpcStatus(code, message, details) adds error details to the status and WithGrpcTrailer(key, value) adds a trailer; see Error details and trailers.
  • A call that no stub matches fails on the client with the Unimplemented status. The status detail tells whether the method has stubs and shows the request message, for example the request did not satisfy the 1 stub(s) of this method. Request: { "name": "someone else" }.
  • A stub whose message type is not the one the method takes throws when it is created, instead of never matching.
  • The extensions cover unary calls, not streaming.
  • A server with UseHttp2 does not answer HTTP/1.1 requests. Use one harness for gRPC and another for HTTP APIs.

Error details and trailers

A service that follows the gRPC rich error model sends a google.rpc.Status with details next to the status code. Pass the details to WithGrpcStatus:

greeter.Server
       .Given(Request.Create().UsingGrpc(Greeter.Descriptor, nameof(Greeter.GreeterClient.SayHelloAsync)))
       .RespondWith(Response.Create()
                            .WithGrpcStatus(StatusCode.FailedPrecondition, "The person is blocked",
                                new ErrorInfo { Reason = "PERSON_BLOCKED", Domain = "greeter" }));

The application reads them as it does from the real service, for example with GetRpcStatus() of the Grpc.StatusProto package:

var error = exception.GetRpcStatus()?.GetDetail<ErrorInfo>();
  • A detail is any protobuf message: a standard one such as ErrorInfo (package Google.Api.CommonProtos) or a message of the service's own. Each one is packed into Any; an Any is sent as it is.
  • To send a Google.Rpc.Status you already have, pass its parts: WithGrpcStatus((StatusCode)status.Code, status.Message, [.. status.Details]).
  • WithGrpcTrailer(key, value) adds any other trailer, after a message or with a failure status. A text value is printable ASCII; a trailer whose name ends with -bin takes bytes and is sent base64-encoded, as gRPC requires. The client reads trailers from RpcException.Trailers, or from GetTrailers() of a call that succeeded. Names that start with grpc- are reserved: set the status, its message and its details with WithGrpcStatus.
  • WithGrpcStatus called again replaces the status set before, with its message and details.
Response.Create()
        .WithGrpcStatus(StatusCode.PermissionDenied, "Blocked")
        .WithGrpcTrailer("error-code", "PERSON_BLOCKED")
        .WithGrpcTrailer("signature-bin", signature);

The package depends on WireMock.Net.Minimal. Add the full WireMock.Net package if you need its extra matchers (GraphQL, ProtoBuf).

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.  net11.0 is compatible. 
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.6.0 62 11/22/2026
1.5.0 78 11/20/2026
1.4.0 115 11/13/2026