WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.39k stars 207 forks source link

[FluentAssertions] Should().HaveReceivedACall().WithHeader() only checks the first header with the matching key. #958

Closed tlevesque-ueat closed 1 year ago

tlevesque-ueat commented 1 year ago

Describe the bug

I have a scenario where I send 2 different requests to wiremock. One has the header Authorization: Bearer invalidToken The other has the header Authorization: Bearer validToken I'm trying to assert that I received a request with each of these headers:

_server.Should().HaveReceivedACall().WithHeader("Authorization", "Bearer invalidToken");
_server.Should().HaveReceivedACall().WithHeader("Authorization", "Bearer validToken");

However, the second assertion fails, because WithHeader() only checks the first Authorization header of all received requests.

Expected behavior:

Both these assertions should succeed. WithHeader should check the headers of all requests, not just the first.

Test to reproduce

using var server  = WireMockServer.Start();
using var client = server.CreateClient();
await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
{
    Headers =
    {
        Authorization = new AuthenticationHeaderValue("Bearer", "invalidToken")
    }
});
await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
{
    Headers =
    {
        Authorization = new AuthenticationHeaderValue("Bearer", "validToken")
    }
});

server.Should().HaveReceivedACall().WithHeader("Authorization", "Bearer invalidToken");
server.Should().HaveReceivedACall().WithHeader("Authorization", "Bearer validToken");

Other related info

Provide additional information if any.

StefH commented 1 year ago

Thanks for this detailed issue.

A fix will be released in the next version.

https://github.com/WireMock-Net/WireMock.Net/pull/959

tlevesque-ueat commented 1 year ago

Wow, that was fast! Thanks