Skip to content

FluentAssertions

Stef Heyenrath edited this page May 1, 2022 · 3 revisions

FluentAssertions

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

Example

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

LogEntries

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

Example

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

Clone this wiki locally