Fluentassertions
FluentAssertions / AwesomeAssertions
Section titled “FluentAssertions / AwesomeAssertions”With the NuGet Package WireMock.Net.FluentAssertions / WireMock.Net.AwesomeAssertions, it’s possible to verify if certain calls are made.
Example
Section titled “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");}
LogEntries
Section titled “LogEntries”In addition to the Fluent Assertions interface, you can also get information about the calls being made to the WireMock.Net server.
Example
Section titled “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();