Skip to content

Latest commit

 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Mockly

FluentAssertions extensions for Mockly

Coveralls branch GitHub Repo stars open issues Static Badge

Documentation

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:

Packages

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

Quick start

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.v8

Example:

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.

Building

./build.ps1

Contributing

Contributions are welcome! Please read CONTRIBUTING.md and open an issue or PR.

Versioning

This repository uses Semantic Versioning. See the releases.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages