Mockly documentation (including assertion usage) lives on https://mockly.org.
This repository contains only the FluentAssertions assertion packages for Mockly. For the core HTTP mocking library, see:
- Website: https://mockly.org
- Core repo: https://github.com/dennisdoomen/mockly
- Core NuGet package: https://www.nuget.org/packages/Mockly
Choose the package that matches your FluentAssertions major version:
| Package | FluentAssertions | NuGet |
|---|---|---|
FluentAssertions.Mockly.v7 |
7.x | https://www.nuget.org/packages/FluentAssertions.Mockly.v7 |
FluentAssertions.Mockly.v8 |
8.x | https://www.nuget.org/packages/FluentAssertions.Mockly.v8 |
Install Mockly and the assertion package you need:
dotnet add package Mockly
# Pick one:
dotnet add package FluentAssertions.Mockly.v7
dotnet add package FluentAssertions.Mockly.v8Example:
using System.Net;
using FluentAssertions;
using Mockly;
var mock = new HttpMock();
mock.ForGet()
.WithPath("/api/users/123")
.RespondsWithStatus(HttpStatusCode.OK);
var client = mock.GetClient();
var response = await client.GetAsync("/api/users/123");
response.StatusCode.Should().Be(HttpStatusCode.OK);
mock.Should().HaveAllRequestsCalled();You can also assert that matching captured requests did not include sensitive data:
requests.Should().ContainRequestFor("/api/users")
.WithoutHeader("X-Internal-Token")
.WithoutQueryParam("debug")
.WithoutBodyProperty("password");
requests.Should().NotContainRequest();The Without... assertions apply to every captured request matched by ContainRequestFor. One clean request does not hide
another request that still contains the rejected header, query parameter or body property.
Header names are matched case-insensitively, like HTTP headers. Query parameter names are URL-decoded and matched
case-sensitively. Repeated and valueless query parameters still count as present. WithoutBodyProperty checks top-level
properties of a JSON object body only. The property name is case-sensitive, and a property with a null value still counts
as present. Missing, empty, malformed or non-object JSON bodies fail the assertion because the property cannot be inspected.
./build.ps1Contributions are welcome! Please read CONTRIBUTING.md and open an issue or PR.
This repository uses Semantic Versioning. See the releases.
This project is licensed under the MIT License - see the LICENSE file for details.
