Skip to content

Fluentassertions

With the NuGet Package WireMock.Net.FluentAssertions / WireMock.Net.AwesomeAssertions, it’s possible to verify if certain calls are made.

The example below checks if a specific call to an url is actually made by the HttpClient.

[Fact]
public async Task AtUrl_WhenACallWasMadeToUrl_Should_BeOK()
{
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
_server.Should()
.HaveReceivedACall()
.AtUrl($"http://localhost:{_portUsed}/anyurl");
}

snippet

In addition to the Fluent Assertions interface, you can also get information about the calls being made to the WireMock.Net server.

Use the code below in a unit-test to check if the HttpClient actually did send these specific headers.

var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers)
.ToDictionary(x => x.Key, x => x.Value)["Accept"]
.Select(x => $"\"{x}\"")
.ToList();

snippet