MVFC.Aspire.Helpers.WireMock 6.4.1

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

MVFC.Aspire.Helpers.WireMock

🇧🇷 Leia em Português

Helpers for integrating WireMock.Net in .NET Aspire projects, facilitating API mocking for development, testing, and integration.

Motivation

Mocking HTTP APIs locally often involves:

  • Running WireMock.Net manually or as a separate console app.
  • Scattering mock configuration across JSON files or test projects.
  • No clear place to manage the mock lifecycle with the rest of your topology.

With .NET Aspire you can orchestrate resources, but you still need to:

  • Start/stop the mock along with your app.
  • Configure endpoints, methods and auth consistently.
  • Wire other projects to talk to the mock.

MVFC.Aspire.Helpers.WireMock addresses this by:

  • AddWireMock(...) to run WireMock.Net as an embedded server in Aspire.
  • A fluent API to configure endpoints, auth, headers, body types and responses.
  • WithReference(...) to make projects wait for the mock and consume its URL.

Overview

This project allows easily adding a WireMock.Net server as a managed resource in distributed .NET Aspire applications. It simplifies provisioning, lifecycle management, and exposing mocked HTTP endpoints, while also allowing custom configuration and publishing state/log events.

WireMock helper advantages

  • Simulates external/local APIs for testing and integration.
  • Allows defining endpoints, methods, authentication, and custom responses.
  • Facilitates decoupled development and automated testing.
  • Manages the WireMock resource lifecycle within the Aspire environment.

Project Structure

Features

  • Adds a WireMock resource to the Aspire application with managed lifecycle.
  • Allows detailed configuration of mocked endpoints.
  • Support for authentication (Bearer, custom headers).
  • Configuration of body types, headers, status codes, and errors.
  • Publishes resource state and log events.

Compatible Images

  • Uses WireMock.Net as an embedded server (no Docker image required).

Installation

dotnet add package MVFC.Aspire.Helpers.WireMock

Endpoint configuration examples

You can configure mocked endpoints with different HTTP methods, body types, authentication, headers, and custom responses.

  • Bearer authentication:
server.Endpoint("/api/secure")
       .RequireBearer("mytoken", "Unauthorized", BodyType.String)
       .OnGet(() => ("Secret Data", HttpStatusCode.OK, BodyType.String));
  • Custom headers:
server.Endpoint("/api/headers")
      .WithResponseHeaders(new() { { "X-Test", ["v1", "v2"] } })
      .OnGet(() => ("Headers OK", HttpStatusCode.OK, BodyType.String));

Supported body types include String, Json, Bytes, FormUrlEncoded, etc.

Ports and access

  • Port: defined via port parameter (e.g. 8080).
  • Access: http://localhost:<port>/api/....

Public methods

  • AddWireMock – adds the WireMock resource to the distributed application and lets you configure endpoints.
var wireMock = builder.AddWireMock("wireMock", port: 8080, configure: ...);

Complete Aspire usage example (AppHost)

using Aspire.Hosting;
using MVFC.Aspire.Helpers.WireMock;

var builder = DistributedApplication.CreateBuilder(args);

var wireMock = builder.AddWireMock("wireMock", port: 8080, configure: (server) =>
{
    server.Endpoint("/api/echo")
          .WithDefaultBodyType(BodyType.String)
          .OnPost<string, string>(body => ($"Echo: {body}", HttpStatusCode.Created, null));

    server.Endpoint("/api/test")
          .WithDefaultBodyType(BodyType.String)
          .OnGet<string>(() => ("Aspire GET OK", HttpStatusCode.OK, null));

    server.Endpoint("/api/secure")
           .RequireBearer("mytoken", "Unauthorized", BodyType.String)
           .OnGet(() => ("Secret Data", HttpStatusCode.OK, BodyType.String));

    server.Endpoint("/api/put")
           .WithDefaultBodyType(BodyType.String)
           .OnPut<string, string>(req => ($"Echo: {req}", HttpStatusCode.Accepted, BodyType.String));

    server.Endpoint("/api/customauth")
        .WithDefaultErrorStatusCode(HttpStatusCode.Forbidden)
        .RequireCustomAuth(req => (req.Headers!.ContainsKey("X-Test"), "Forbidden", BodyType.String))
        .OnGet(() => ("Authorized", HttpStatusCode.OK, BodyType.String));

    server.Endpoint("/api/headers")
        .WithResponseHeaders(new() { { "X-Test", ["v1", "v2"] } })
        .WithResponseHeader("X-Other", "v3")
        .OnGet(() => ("Headers OK", HttpStatusCode.OK, BodyType.String));

    server.Endpoint("/api/error")
        .WithRequestBodyType(BodyType.String)
        .WithDefaultErrorStatusCode((HttpStatusCode)418)
        .OnGet(() => ("I am a teapot", (HttpStatusCode)418, BodyType.String));

    server.Endpoint("/api/delete")
       .WithResponseBodyType(BodyType.String)
       .WithResponseHeader("v1", "v1")
       .WithResponseHeaders(new() { { "v1", ["v2", "v3"] } })
       .WithResponseHeader("v1", "v4")
       .OnDelete<string>(() => (null!, HttpStatusCode.NoContent, null));

    server.Endpoint("/api/form")
        .WithDefaultBodyType(BodyType.FormUrlEncoded)
        .OnPost<Dictionary<string, string>, IDictionary<string, string>>(body => (body, HttpStatusCode.OK, BodyType.FormUrlEncoded));

    server.Endpoint("/api/form-wrong")
       .WithDefaultBodyType(BodyType.FormUrlEncoded)
       .OnPost<string, string>(body => (body, HttpStatusCode.OK, BodyType.FormUrlEncoded));

    server.Endpoint("/api/patch")
        .WithDefaultBodyType(BodyType.String)
        .OnPatch<string, string>(body => ($"Patched: {body}", HttpStatusCode.OK, BodyType.String));

    server.Endpoint("/api/bytes")
        .WithDefaultBodyType(BodyType.Bytes)
        .OnPost<byte[], byte[]>(body => (body, HttpStatusCode.OK, BodyType.Bytes));

    server.Endpoint("/api/unsupported")
        .WithDefaultBodyType((BodyType)999)
        .OnPost<string, string>(_ => ("Not Supported", HttpStatusCode.NotImplemented, null));

    server.Endpoint("/api/json")
        .WithDefaultBodyType(BodyType.Json)
        .OnPost<JsonModel, JsonModel>(body => (body, HttpStatusCode.OK, BodyType.Json));
});

await builder.Build().RunAsync();

Requirements

  • .NET 9+
  • Aspire.Hosting >= 9.5.0
  • WireMock.Net.minimal >= 1.14.0

License

Apache-2.0

Product Compatible and additional computed target framework versions.
.NET 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
6.4.1 72 3/10/2026
6.4.0 74 3/9/2026
6.3.0 74 3/8/2026
6.2.0 79 3/8/2026
6.1.1 76 3/7/2026
6.0.0 79 3/7/2026
5.1.0 88 2/28/2026
5.0.3 91 2/17/2026
5.0.2 92 2/17/2026
5.0.1 98 2/17/2026
5.0.0 97 2/16/2026
4.3.0 96 2/15/2026
4.2.0 96 2/3/2026
4.1.0 286 11/16/2025
4.0.2 133 11/1/2025
4.0.1 118 11/1/2025
4.0.0 132 11/1/2025
3.0.0 193 10/30/2025