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

Closed
opened 2025-12-29 15:25:53 +01:00 by adam · 2 comments
Owner

Originally created by @tlevesque-ueat on GitHub (Jun 22, 2023).

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");

Provide additional information if any.

Originally created by @tlevesque-ueat on GitHub (Jun 22, 2023). ### 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: ```csharp _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 ```csharp 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.
adam added the bug label 2025-12-29 15:25:53 +01:00
adam closed this issue 2025-12-29 15:25:53 +01:00
Author
Owner

@StefH commented on GitHub (Jun 22, 2023):

Thanks for this detailed issue.

A fix will be released in the next version.

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

@StefH commented on GitHub (Jun 22, 2023): Thanks for this detailed issue. A fix will be released in the next version. https://github.com/WireMock-Net/WireMock.Net/pull/959
Author
Owner

@tlevesque-ueat commented on GitHub (Jun 26, 2023):

Wow, that was fast! Thanks

@tlevesque-ueat commented on GitHub (Jun 26, 2023): Wow, that was fast! Thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#523