MockServer.Testcontainers
7.1.0
dotnet add package MockServer.Testcontainers --version 7.1.0
NuGet\Install-Package MockServer.Testcontainers -Version 7.1.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="MockServer.Testcontainers" Version="7.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MockServer.Testcontainers" Version="7.1.0" />
<PackageReference Include="MockServer.Testcontainers" />
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 MockServer.Testcontainers --version 7.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MockServer.Testcontainers, 7.1.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 MockServer.Testcontainers@7.1.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=MockServer.Testcontainers&version=7.1.0
#tool nuget:?package=MockServer.Testcontainers&version=7.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MockServer.Testcontainers
A Testcontainers module for MockServer that starts a mockserver/mockserver Docker container, waits for readiness, and provides connection helpers.
Package id:
MockServer.Testcontainers. The namespace staysTestcontainers.MockServer(NuGet'sTestcontainers.*ID prefix is reserved), so the install id and theusingdiffer by design.
Installation
dotnet add package MockServer.Testcontainers
Usage
using Testcontainers.MockServer;
// Create and start a MockServer container
await using var container = new MockServerBuilder()
.WithLogLevel("INFO")
.Build();
await container.StartAsync();
// Get the connection URL
var url = container.GetUrl(); // http://localhost:xxxxx
var host = container.GetConnectionString(); // localhost:xxxxx
// Use MockServer via its REST API
using var httpClient = new HttpClient();
// Create an expectation
var expectation = """
{
"httpRequest": { "method": "GET", "path": "/hello" },
"httpResponse": { "statusCode": 200, "body": "world" }
}
""";
await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Put, $"{url}/mockserver/expectation")
{
Content = new StringContent(expectation, System.Text.Encoding.UTF8, "application/json")
});
// Issue a request that matches the expectation
var response = await httpClient.GetStringAsync($"{url}/hello");
// response == "world"
Builder Configuration
| Method | Description |
|---|---|
WithLogLevel(string) |
Set the MockServer log level (INFO, DEBUG, WARN, ERROR, TRACE) |
WithMockServerProperty(string, string) |
Set any MockServer configuration property as an env var |
WithImage(string) |
Override the Docker image (default: mockserver/mockserver:mockserver-7.1.0) |
WithPortBinding(int, int) |
Bind a specific host port to the container port |
Container Helpers
| Method | Returns |
|---|---|
GetUrl() |
HTTP endpoint: http://host:port |
GetSecureUrl() |
HTTPS endpoint: https://host:port |
GetConnectionString() |
host:port |
GetMappedPort() |
The host port mapped to container port 1080 |
Building
cd mockserver-testcontainers/dotnet
dotnet build
Testing
# Unit tests (no Docker required)
dotnet test --filter "Category!=Integration"
# All tests (Docker required)
dotnet test
Requirements
- .NET 8.0 SDK
- Docker (for integration tests and actual usage)
| Product | Versions 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Testcontainers (>= 4.12.0)
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 | 266 | 6/16/2026 |