Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

NFluent extensions for TestableHttpClient

License

Notifications You must be signed in to change notification settings

testablehttpclient/TestableHttpClient.NFluent

Repository files navigation

TestableHttpClient.NFluent

GitHub GitHub Workflow Status Project status Nuget

In integration tests, asserting HttpResponseMessages can be a real challenge, especially since error messages are sometimes not very clear. NFluent is known for giving clear error messages. TestableHttpClient.NFluent is designed to make it easier to check HttpResponseMessages and TestableHttpClients and give clear error messages.

For example when the following check fails:

Check.That(response).HasResponseHeader("Server");

it will return the following message:

The checked response's headers does not contain the expected header.
The checked response's headers:
    {"Connection"} (1 item)
The expected header:
    ["Server"]

Status

The TestableHttpClient.NFluent has been deprecated and is no longer being maintained. The main reason for this is that I no longer use NFluent. If someone wants to continue developing this library, please feel free to contact me.

How to install

TestableHttpClient.NFluent is released as a NuGet packages and can be installed via the NuGet manager in VisualStudio or by running the following command on the command line:

dotnet add package TestableHttpClient.NFluent

How to use

Asserting HttpResponseMessages

var client = new HttpClient();

var result = await httpClient.GetAsync("https://httpbin.org/status/200");

Check.That(result).HasStatusCode(HttpStatusCode.OK).And.HasContentHeader("Content-Type", "*/json*");

Asserting TestableHttpMessageHandler

var handler = new TestableHttpMessageHandler();
var client = new HttpClient(handler);

_ = await httpClient.GetAsync("https://httpbin.org/status/200");

Check.That(handler).HasMadeRequestsTo("https://httpbin.org*").WithHttpMethod(HttpMethod.Get);

Authors

See also the list of contributors who participated in this project.

License

This project is released under the MIT license, see LICENSE.md for more information.