MockServerClient 7.1.0
dotnet add package MockServerClient --version 7.1.0
NuGet\Install-Package MockServerClient -Version 7.1.0
<PackageReference Include="MockServerClient" Version="7.1.0" />
<PackageVersion Include="MockServerClient" Version="7.1.0" />
<PackageReference Include="MockServerClient" />
paket add MockServerClient --version 7.1.0
#r "nuget: MockServerClient, 7.1.0"
#:package MockServerClient@7.1.0
#addin nuget:?package=MockServerClient&version=7.1.0
#tool nuget:?package=MockServerClient&version=7.1.0
MockServerClient for .NET
A hand-written, idiomatic .NET client for MockServer's control-plane REST API.
Installation
The NuGet package is MockServerClient (the assembly and namespace remain MockServer.Client):
dotnet add package MockServerClient
Or via PackageReference in your .csproj:
<PackageReference Include="MockServerClient" Version="7.0.1" />
Supported Targets
- .NET Standard 2.0 (for broad compatibility: .NET Framework 4.6.1+, .NET Core 2.0+, Mono 5.4+)
- .NET 8.0 (for modern APIs and best performance)
Usage
using MockServer.Client;
using MockServer.Client.Models;
// Create client
using var client = new MockServerClient("localhost", 1080);
// Create an expectation with fluent API
client.When(
HttpRequest.Request()
.WithMethod("GET")
.WithPath("/hello")
.WithQueryStringParameter("name", "world")
).Respond(
HttpResponse.Response()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBody("{\"message\":\"hello world\"}")
);
// Verify the request was received
client.Verify(
HttpRequest.Request().WithPath("/hello"),
VerificationTimes.AtLeastTimes(1)
);
// Reset all expectations
client.Reset();
Forward Expectations
client.When(
HttpRequest.Request().WithPath("/proxy")
).Forward(
HttpForward.Forward()
.WithHost("backend.example.com")
.WithPort(443)
.WithScheme("HTTPS")
);
Verify Sequence
client.VerifySequence(
HttpRequest.Request().WithPath("/first"),
HttpRequest.Request().WithPath("/second")
);
Retrieve Recorded Requests
var requests = client.RetrieveRecordedRequests(
HttpRequest.Request().WithPath("/api")
);
Async API
All operations have async variants:
await client.VerifyAsync(
HttpRequest.Request().WithPath("/hello"),
VerificationTimes.AtLeastTimes(1)
);
Interactive Breakpoints
Register breakpoint matchers to pause forwarded/proxied traffic at REQUEST, RESPONSE, RESPONSE_STREAM, or INBOUND_STREAM phases. A callback WebSocket connection is opened automatically.
using MockServer.Client.Models;
using System.Text.Json.Nodes;
// REQUEST-only breakpoint
var id = client.AddRequestBreakpoint(
HttpRequest.Request().WithPath("/api/.*").Build(),
request => request // continue with original
);
// REQUEST + RESPONSE breakpoint
var id2 = client.AddRequestResponseBreakpoint(
HttpRequest.Request().WithPath("/api/.*").Build(),
request => request,
(request, response) => response
);
// Streaming breakpoint
var id3 = client.AddStreamBreakpoint(
HttpRequest.Request().WithPath("/stream/.*").Build(),
new[] { BreakpointPhase.ResponseStream },
frame => StreamFrameDecision.Continue(frame.CorrelationId!)
);
// Manage matchers
var list = client.ListBreakpointMatchers();
client.RemoveBreakpointMatcher(id);
client.ClearBreakpointMatchers();
Stream frame decisions: StreamFrameDecision.Continue, .Modify, .Drop, .Inject, .Close.
Start / Launch MockServer
The .NET client can download and launch a local MockServer instance directly -- no Java installation and no Docker required. The launcher downloads a self-contained platform bundle (mockserver-<version>-<os>-<arch>) from the GitHub Release, verifies its SHA-256, caches it per-user, and starts it.
Quick start
using MockServer.Client;
// Download (first run) and start MockServer on port 1080
using var launcher = MockServerBinaryLauncher.Start(port: 1080);
Console.WriteLine($"MockServer started, PID {launcher.Process?.Id}");
// ... use MockServer ...
launcher.Stop();
// or let the using statement dispose and stop it automatically
Async API
using var launcher = await MockServerBinaryLauncher.StartAsync(port: 1080);
Just ensure the binary is present
string launcherPath = await MockServerBinaryLauncher.EnsureBinaryAsync();
// or synchronously:
string launcherPath = MockServerBinaryLauncher.EnsureBinary();
Specify a version
using var launcher = MockServerBinaryLauncher.Start(port: 1080, version: "7.1.0");
API reference
| Method / Class | Description |
|---|---|
MockServerBinaryLauncher.EnsureBinaryAsync(version?, options?) |
Download, verify, cache, and return the launcher path. Defaults to DefaultVersion. |
MockServerBinaryLauncher.EnsureBinary(version?, options?) |
Synchronous wrapper for EnsureBinaryAsync. |
MockServerBinaryLauncher.StartAsync(port, version?, options?) |
Ensure the binary and start MockServer. Returns a MockServerBinaryLauncher instance. |
MockServerBinaryLauncher.Start(port, version?, options?) |
Synchronous wrapper for StartAsync. |
MockServerBinaryLauncher |
Implements IDisposable. Properties: Process. Methods: Stop(), Dispose(). |
MockServerBinaryLauncher.DefaultVersion |
The default MockServer version, derived from the NuGet package version at runtime. |
Supported platforms
| OS | Architecture |
|---|---|
| Linux | x86_64, aarch64 |
| macOS (darwin) | x86_64, aarch64 |
| Windows | x86_64, aarch64 |
Environment variables
| Variable | Purpose |
|---|---|
MOCKSERVER_BINARY_BASE_URL |
Mirror host for the release assets (corporate / air-gapped networks) |
MOCKSERVER_BINARY_CACHE |
Override the cache directory (default: ~/.cache/mockserver/binaries on Unix, %LOCALAPPDATA% on Windows) |
MOCKSERVER_SKIP_BINARY_DOWNLOAD |
Fail instead of downloading (use with a pre-seeded cache in CI) |
Version
By default the launcher downloads the MockServer version matching this NuGet package (derived from the <Version> property in the .csproj at build time). Pass an explicit version argument to override.
Building
cd mockserver-client-dotnet
dotnet build
dotnet test
Requirements
- .NET SDK 8.0+ (for building)
System.Net.WebSockets.ClientWebSocket(built-in, for breakpoint callback WebSocket)- No external runtime dependencies beyond
System.Text.Json(included via .NET or NuGet for netstandard2.0)
License
Apache 2.0 - see LICENSE
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.5)
-
net8.0
- No dependencies.
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 |
|---|---|---|
| 7.1.0 | 52 | 6/16/2026 |
| 7.0.0-alpha.1 | 37 | 6/11/2026 |