Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tlevesque-ueat opened this issue Jun 22, 2023 · 2 comments
Labels

Comments

@tlevesque-ueat
Copy link
Contributor

tlevesque-ueat commented 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");

Other related info

Provide additional information if any.

@StefH
Copy link
Collaborator

StefH commented Jun 22, 2023

Thanks for this detailed issue.

A fix will be released in the next version.

#959

@StefH StefH closed this as completed Jun 22, 2023
@tlevesque-ueat
Copy link
Contributor Author

Wow, that was fast! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants