Anarchy.Toolkit.Testing.MockServer
1.1.0
See the version list below for details.
dotnet add package Anarchy.Toolkit.Testing.MockServer --version 1.1.0
NuGet\Install-Package Anarchy.Toolkit.Testing.MockServer -Version 1.1.0
<PackageReference Include="Anarchy.Toolkit.Testing.MockServer" Version="1.1.0" />
<PackageVersion Include="Anarchy.Toolkit.Testing.MockServer" Version="1.1.0" />
<PackageReference Include="Anarchy.Toolkit.Testing.MockServer" />
paket add Anarchy.Toolkit.Testing.MockServer --version 1.1.0
#r "nuget: Anarchy.Toolkit.Testing.MockServer, 1.1.0"
#:package Anarchy.Toolkit.Testing.MockServer@1.1.0
#addin nuget:?package=Anarchy.Toolkit.Testing.MockServer&version=1.1.0
#tool nuget:?package=Anarchy.Toolkit.Testing.MockServer&version=1.1.0
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
MockServerClienttalks to the server's/__mockcontrol API: received requests, runtime expectations, resets.RecordedRequestAssertionsassert on what was received (ShouldHaveReceived,ShouldNotHaveReceived,ShouldAllHaveBeenMatched,AssertReceivedAsync), with failures listing the requests that were actually received.RecordedRequestsFile.Readreads the JSON-lines file written with--record, so you can assert after the server stopped.MockServerFixtureconnects to the server atMOCKSERVER_URL(set by the FalloutIMockServerBuildtargets), or spawns one withMockServerProcess.
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 Fallout 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
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 | 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. |
-
net10.0
- Amazon.Extensions.Configuration.SystemsManager (>= 7.1.1)
- Amazon.Lambda.APIGatewayEvents (>= 3.0.1)
- Amazon.Lambda.Core (>= 3.4.0)
- Amazon.Lambda.TestUtilities (>= 4.3.0)
- Anarchy.Toolkit.Testing (>= 1.1.1)
- Anarchy.Toolkit.Web.MockServer (>= 1.1.0)
- AwesomeAssertions (>= 9.6.0)
- AWSSDK.Core (>= 4.1.0.1)
- AWSSDK.KeyManagementService (>= 4.1.0)
- AWSSDK.SecretsManager (>= 4.1.1)
- Humanizer (>= 3.0.10)
- Microsoft.Identity.Client (>= 4.92.0)
- Microsoft.NET.Test.Sdk (>= 18.12.0)
- Moq (>= 4.21.0)
- Newtonsoft.Json (>= 13.0.4)
- Serilog (>= 4.4.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Spectre.Console (>= 0.57.2)
- xunit.v3.extensibility.core (>= 4.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release.