Skip to main content

Mockly

Fluent HTTP mocking for .NET like it should have been done

Power in Simplicity

using var mock = new HttpMock();

// 1. Match with full URL shortcuts and wildcards
// 2. Filter by specific query parameters
// 3. Use custom JSON options for serialization
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };

mock.ForGet("https://api.github.com/repos/*/issues?state=open")
.WithQueryParam("page", "1")
.Using(options)
.RespondsWithJsonContent(new[] {
new { Id = 1, Title = "Found a bug" },
new { Id = 2, Title = "Feature request" }
});

// 4. Match Bearer tokens and other headers
// 5. Match request body using JSON equivalence
// 6. Capture requests for later verification
var creations = new RequestCollection();

mock.ForPost()
.WithPath("/api/users")
.WithBearerToken("secret-token")
.WithBody(new { Name = "John", Role = "Admin" })
.CollectingRequestsIn(creations)
.RespondsWithStatus(HttpStatusCode.Created);

// 7. Built-in support for Problem Details (RFC 7807)
mock.ForGet("/api/users/999")
.RespondsWithProblemDetails(HttpStatusCode.NotFound, "User not found");

// Get the pre-configured HttpClient and start testing!
var client = mock.GetClient();

// 8. Assert your expectations with FluentAssertions
mock.Should().HaveAllRequestsCalled();
creations.Should().ContainRequestFor("/api/users")
.Which.HasHeader("X-Trace-Id");
🎯

Fluent API

Chain method calls to build complex HTTP mocking scenarios with ease. Intuitive and readable API that makes your test code self-documenting.

Wildcard Matching

Use wildcards in URLs to match patterns. Perfect for dynamic paths, query strings, and flexible request matching.

🔍

Request Capture

Automatically capture all requests with full metadata including headers, body, and timestamp for detailed test assertions.

Powerful Assertions

Built-in FluentAssertions extensions for verifying HTTP behavior with expressive and readable test assertions.

Zero Configuration

Works out of the box with sensible defaults. Start mocking HTTP requests in seconds without complex setup.

🛡️

Fail-Fast Testing

Throws clear exceptions for unexpected requests by default, helping you catch configuration issues early in testing.