-
-
Notifications
You must be signed in to change notification settings - Fork 212
FluentAssertions
Stef Heyenrath edited this page May 1, 2022
·
3 revisions
With the NuGet Package WireMock.Net.FluentAssertions, 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");
}
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();
- Home
- What is WireMock.Net
- WireMock.Org
- References
- Settings
- Admin REST API
- Proxying
- Stubbing
- Webhook
- Request Matching
- Response Templating
- Unit Testing
- Using WireMock
- Advanced
- Errors