FluentAssertions extensions do not filter headers correctly #578

Closed
opened 2025-12-29 08:30:31 +01:00 by adam · 2 comments
Owner

Originally created by @chrischu on GitHub (Mar 4, 2024).

Originally assigned to: @StefH on GitHub.

Describe the bug

When asserting headers via the FluentAssertions extensions, headers are not filtered correctly (headers from all captured requests are checked).

Expected behavior:

I expect the assertions to only consider the requests that match the previous filters (see example below).

Test to reproduce

[Test]
public async Task SendGetWithHeader ()
{
  using var server = WireMockServer.Start();
  using var httpClient = new HttpClient();

  // ACT
  await httpClient.GetAsync(server.Url!);

  var request = new HttpRequestMessage(HttpMethod.Post, server.Url!);
  request.Headers.Add("TestHeader", "Value");
  await httpClient.SendAsync(request);

  // ASSERT
  server.Should().HaveReceivedACall().UsingGet().And.WithHeader("TestHeader", "Value");
}

This test succeeds although it should fail, since only the POST request has the header, the GET request does not.

I'm using WireMock.Net & WireMock.Net.FluentAssertions 1.5.48.

Originally created by @chrischu on GitHub (Mar 4, 2024). Originally assigned to: @StefH on GitHub. ### Describe the bug When asserting headers via the FluentAssertions extensions, headers are not filtered correctly (headers from all captured requests are checked). ### Expected behavior: I expect the assertions to only consider the requests that match the previous filters (see example below). ### Test to reproduce ``` c# [Test] public async Task SendGetWithHeader () { using var server = WireMockServer.Start(); using var httpClient = new HttpClient(); // ACT await httpClient.GetAsync(server.Url!); var request = new HttpRequestMessage(HttpMethod.Post, server.Url!); request.Headers.Add("TestHeader", "Value"); await httpClient.SendAsync(request); // ASSERT server.Should().HaveReceivedACall().UsingGet().And.WithHeader("TestHeader", "Value"); } ``` This test succeeds although it should fail, since only the POST request has the header, the GET request does not. ### Other related info I'm using WireMock.Net & WireMock.Net.FluentAssertions 1.5.48.
adam added the bug label 2025-12-29 08:30:31 +01:00
adam closed this issue 2025-12-29 08:30:31 +01:00
Author
Owner

@StefH commented on GitHub (Mar 8, 2024):

@chrischu
I can confirm this bug and it's fixed in preview version 1.5.49-ci-18411

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

@StefH commented on GitHub (Mar 8, 2024): @chrischu I can confirm this bug and it's fixed in preview version 1.5.49-ci-18411 https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@chrischu commented on GitHub (Mar 8, 2024):

Thanks for the quick fix!

@chrischu commented on GitHub (Mar 8, 2024): Thanks for the quick fix!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#578