WithHeader cannot handle multiple requests with the same header key values #453

Closed
opened 2025-12-29 08:28:23 +01:00 by adam · 14 comments
Owner

Originally created by @robvangeloven on GitHub (Sep 23, 2022).

Originally assigned to: @StefH on GitHub.

When using the assertion "WithHeader" it will fail if there are multiple requests with the same header value (e.g. "Accept"):

Server.Should().HaveReceivedACall().WithHeader("Authorization", $"Bearer xxxxxxx");

This is because there is a ToDictionary in the WithHeader function that doesn't take into account that multiple calls might have been made before the assert fires.

Originally created by @robvangeloven on GitHub (Sep 23, 2022). Originally assigned to: @StefH on GitHub. When using the assertion "WithHeader" it will fail if there are multiple requests with the same header value (e.g. "Accept"): ```csharp Server.Should().HaveReceivedACall().WithHeader("Authorization", $"Bearer xxxxxxx"); ``` This is because there is a ToDictionary in the WithHeader function that doesn't take into account that multiple calls might have been made before the assert fires.
adam added the bug label 2025-12-29 08:28:23 +01:00
adam closed this issue 2025-12-29 08:28:23 +01:00
Author
Owner

@StefH commented on GitHub (Sep 26, 2022):

@robvangeloven

I think I've fixed both issues (this & _callscount).

Can you please test preview version 1.5.6-ci-16474?

(https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

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

@StefH commented on GitHub (Sep 26, 2022): @robvangeloven I think I've fixed both issues (this & _callscount). Can you please test preview version `1.5.6-ci-16474`? (https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions) https://github.com/WireMock-Net/WireMock.Net/pull/816
Author
Owner

@StefH commented on GitHub (Oct 3, 2022):

@robvangeloven

Did you have time to validate?

@StefH commented on GitHub (Oct 3, 2022): @robvangeloven Did you have time to validate?
Author
Owner

@robvangeloven commented on GitHub (Oct 5, 2022):

@StefH Sorry, only now have time to test. The package version you mention is (no longer) available. Which version should I take for testing?

@robvangeloven commented on GitHub (Oct 5, 2022): @StefH Sorry, only now have time to test. The package version you mention is (no longer) available. Which version should I take for testing?
Author
Owner

@StefH commented on GitHub (Oct 5, 2022):

can you please try 16510?

@StefH commented on GitHub (Oct 5, 2022): can you please try `16510`?
Author
Owner

@robvangeloven commented on GitHub (Oct 5, 2022):

Tried it and failed, decompilation seems to show that the code isn't merged into that branch yet. Is that possible?

@robvangeloven commented on GitHub (Oct 5, 2022): Tried it and failed, decompilation seems to show that the code isn't merged into that branch yet. Is that possible?
Author
Owner

@StefH commented on GitHub (Oct 5, 2022):

Sorry, wrong branch.

This id: 16511 should be it.

@StefH commented on GitHub (Oct 5, 2022): Sorry, wrong branch. This id: 16511 should be it.
Author
Owner

@robvangeloven commented on GitHub (Oct 6, 2022):

Tried it! However it now tries to match the first request made to WireMock whereas the request I'm trying to match (via the AtUrl call) is the last request

@robvangeloven commented on GitHub (Oct 6, 2022): Tried it! However it now tries to match the first request made to WireMock whereas the request I'm trying to match (via the AtUrl call) is the last request
Author
Owner

@StefH commented on GitHub (Oct 7, 2022):

@robvangeloven
Thanks for testing.

Can you please take a look at this unit test file?
https://github.com/WireMock-Net/WireMock.Net/pull/816/files#diff-e73254164873009a752dfd094e87fa8aae2d0c6c0c0b7ebe3b6d2f2b23b287c8

See line 463.

@StefH commented on GitHub (Oct 7, 2022): @robvangeloven Thanks for testing. Can you please take a look at this unit test file? https://github.com/WireMock-Net/WireMock.Net/pull/816/files#diff-e73254164873009a752dfd094e87fa8aae2d0c6c0c0b7ebe3b6d2f2b23b287c8 See line 463.
Author
Owner

@StefH commented on GitHub (Oct 12, 2022):

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

@StefH commented on GitHub (Oct 12, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/816
Author
Owner

@robvangeloven commented on GitHub (Oct 13, 2022):

@robvangeloven Thanks for testing.

Can you please take a look at this unit test file? https://github.com/WireMock-Net/WireMock.Net/pull/816/files#diff-e73254164873009a752dfd094e87fa8aae2d0c6c0c0b7ebe3b6d2f2b23b287c8

See line 463.

I've checked the unit test, but that one doesn't actually check any headers?

@robvangeloven commented on GitHub (Oct 13, 2022): > @robvangeloven Thanks for testing. > > Can you please take a look at this unit test file? https://github.com/WireMock-Net/WireMock.Net/pull/816/files#diff-e73254164873009a752dfd094e87fa8aae2d0c6c0c0b7ebe3b6d2f2b23b287c8 > > See line 463. I've checked the unit test, but that one doesn't actually check any headers?
Author
Owner

@StefH commented on GitHub (Oct 13, 2022):

Correct.

I did combine both your issues into 1 PR.

And I think both issues are solved.

In case you still have an issue, please provide a unit test.

@StefH commented on GitHub (Oct 13, 2022): Correct. I did combine both your issues into 1 PR. And I think both issues are solved. In case you still have an issue, please provide a unit test.
Author
Owner

@robvangeloven commented on GitHub (Oct 14, 2022):

Yes, retested everything and both issues are fixed!

@robvangeloven commented on GitHub (Oct 14, 2022): Yes, retested everything and both issues are fixed!
Author
Owner

@StefH commented on GitHub (Oct 15, 2022):

Thanks for retesting. A new NuGet version will be released this weekend.

@StefH commented on GitHub (Oct 15, 2022): Thanks for retesting. A new NuGet version will be released this weekend.
Author
Owner

@StefH commented on GitHub (Oct 15, 2022):

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

@StefH commented on GitHub (Oct 15, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/816
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#453