Anarchy.Toolkit.Testing.MockServer 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Anarchy.Toolkit.Testing.MockServer --version 2.0.0
                    
NuGet\Install-Package Anarchy.Toolkit.Testing.MockServer -Version 2.0.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="Anarchy.Toolkit.Testing.MockServer" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anarchy.Toolkit.Testing.MockServer" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Anarchy.Toolkit.Testing.MockServer" />
                    
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 Anarchy.Toolkit.Testing.MockServer --version 2.0.0
                    
#r "nuget: Anarchy.Toolkit.Testing.MockServer, 2.0.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 Anarchy.Toolkit.Testing.MockServer@2.0.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=Anarchy.Toolkit.Testing.MockServer&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Anarchy.Toolkit.Testing.MockServer&version=2.0.0
                    
Install as a Cake Tool

Anarchy.Toolkit.Testing.MockServer

Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Testing kit · Package catalog

Test helpers for Anarchy.Toolkit.Web.MockServer: assert which requests the mock server received.

dotnet add package Anarchy.Toolkit.Testing.MockServer
  • MockServerClient talks to the server's /__mock control API: received requests, runtime expectations, resets.
  • RecordedRequestAssertions assert on what was received (ShouldHaveReceived, ShouldNotHaveReceived, ShouldAllHaveBeenMatched, AssertReceivedAsync), with failures listing the requests that were actually received.
  • RecordedRequestsFile.Read reads the JSON-lines file written with --record, so you can assert after the server stopped.
  • MockServerFixture connects to the server at MOCKSERVER_URL (set by the Anarchy IMockServerBuild targets), or spawns one with MockServerProcess.

When to use it

Use it in integration and end-to-end tests whose application calls HTTP services that the mock server stands in for. Most of the time the mock server is started outside the tests (by Anarchy automation or a Makefile), so tests only assert. Spawning it from the tests is there for when they run on their own, e.g. from an IDE.

How to use it

public sealed class IdentityMockServer : MockServerFixture
{
    // Only used when MOCKSERVER_URL is not set and the fixture spawns the server itself.
    protected override void Configure(MockServerProcessOptions options) => options.ExpectationPaths.Add("mocks");
}

public class UserRegistrationTests(IdentityMockServer mock) : IClassFixture<IdentityMockServer>
{
    [Fact]
    public async Task Register_CreatesTheUserInTheIdentityService()
    {
        await mock.Client.ResetAsync();
        await mock.Client.AddExpectationAsync("POST", "/clients/{id}/users", 201);

        // … call the application, configured to reach the identity service at mock.BaseAddress …

        var requests = await mock.Client.AssertReceivedAsync("POST", "/clients/{id}/users", times: 1);
        requests[0].BodyAs<CreateUserRequest>()!.Email.Should().Be("jane.doe@example.com");
    }
}

Paths in assertions are exact, {param} templates or regular expressions, as in expectations. MockServerProcess runs the Anarchy.Toolkit.Web.MockServer assembly copied next to the tests, or dotnet runs MockServerProcessOptions.ProjectPath when you have a host of your own; it stops the server, and everything it started, on dispose.

Releases

2.0.0

  • feat(automation): establish onboarding and layering conventions
  • feat(telemetry)!: introduce provider-neutral application telemetry
  • refactor(packages)!: restructure persistence and automation packages
  • refactor(infrastructure.correlationid)!: decouple correlation scopes from Serilog
  • refactor(core)!: reshape telemetry, event and health contracts
  • refactor(telemetry)!: remove legacy APIs and simplify namespaces

1.1.0

  • feat(Web.MockServer): keep an in-memory log and describe plugged-in middlewares

1.0.1

  • docs(packages): identify each package's pillar and layer
  • build(packages): attribute the copyright to Leandro Melão Medeiros
  • build: relicense under Apache-2.0 and update the package metadata
  • fix(mock-server): default to port 6001, which browsers allow

1.0.0

  • Initial release.
Product 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. 
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
2.0.1 0 11/21/2026
2.0.0 0 11/20/2026
1.1.0 52 11/17/2026
1.0.1 52 11/17/2026
1.0.0 44 11/17/2026

Initial release.