Why does UsingMethod check _callscount? #452

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

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

Originally assigned to: @StefH on GitHub.

When making this call:

                ._wireMockFixture
                .Server
                .Should()
                .HaveReceived(1)
                .Calls()
                .AtUrl(mockUrl)
                .And
                .UsingPost();

My expectation is that this will work, but I get the error:
Expected _wireMockFixture.Server to have been called using method "POST", but didn't find it among the methods {"GET", "POST", "POST"}.

However, I'm trying to check that there was a singular call that matches the specifics of the assert. And there is, but the UsingPost also checks the _callsCount for number of "POST" used.

Originally created by @robvangeloven on GitHub (Sep 26, 2022). Originally assigned to: @StefH on GitHub. When making this call: ```csharp ._wireMockFixture .Server .Should() .HaveReceived(1) .Calls() .AtUrl(mockUrl) .And .UsingPost(); ``` My expectation is that this will work, but I get the error: Expected _wireMockFixture.Server to have been called using method "POST", but didn't find it among the methods {"GET", "POST", "POST"}. However, I'm trying to check that there was a singular call that matches the specifics of the assert. And there is, but the UsingPost also checks the _callsCount for number of "POST" used.
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
Can you provide a failing unit-test ?

Because I cannot reproduce it in existing unit tests.

And also not in new unit tests (https://github.com/WireMock-Net/WireMock.Net/pull/816)

@StefH commented on GitHub (Sep 26, 2022): @robvangeloven Can you provide a failing unit-test ? Because I cannot reproduce it in existing unit tests. And also not in new unit tests (https://github.com/WireMock-Net/WireMock.Net/pull/816)
Author
Owner

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

@StefH Sure!

using System.Net;

using FluentAssertions;

using WireMock.FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;

var server = WireMockServer.Start();

server
    .Given(Request.Create().WithPath("/a").UsingGet())
    .RespondWith(Response.Create().WithBodyAsJson("A response").WithStatusCode(HttpStatusCode.OK));

server
    .Given(Request.Create().WithPath("/b").UsingPost())
    .RespondWith(Response.Create().WithBodyAsJson("B response").WithStatusCode(HttpStatusCode.OK));

server
    .Given(Request.Create().WithPath("/c").UsingPost())
    .RespondWith(Response.Create().WithBodyAsJson("C response").WithStatusCode(HttpStatusCode.OK));


var httpClient = new HttpClient();

await httpClient.GetAsync($"{server.Url}/a");

await httpClient.PostAsync($"{server.Url}/b", new StringContent("B"));

await httpClient.PostAsync($"{server.Url}/c", new StringContent("C"));

server
    .Should()
    .HaveReceived(1)
    .Calls()
    .AtUrl($"{server.Url}/c")
    .And
    .UsingPost();

server.Stop();
@robvangeloven commented on GitHub (Sep 26, 2022): @StefH Sure! ```csharp using System.Net; using FluentAssertions; using WireMock.FluentAssertions; using WireMock.RequestBuilders; using WireMock.ResponseBuilders; using WireMock.Server; var server = WireMockServer.Start(); server .Given(Request.Create().WithPath("/a").UsingGet()) .RespondWith(Response.Create().WithBodyAsJson("A response").WithStatusCode(HttpStatusCode.OK)); server .Given(Request.Create().WithPath("/b").UsingPost()) .RespondWith(Response.Create().WithBodyAsJson("B response").WithStatusCode(HttpStatusCode.OK)); server .Given(Request.Create().WithPath("/c").UsingPost()) .RespondWith(Response.Create().WithBodyAsJson("C response").WithStatusCode(HttpStatusCode.OK)); var httpClient = new HttpClient(); await httpClient.GetAsync($"{server.Url}/a"); await httpClient.PostAsync($"{server.Url}/b", new StringContent("B")); await httpClient.PostAsync($"{server.Url}/c", new StringContent("C")); server .Should() .HaveReceived(1) .Calls() .AtUrl($"{server.Url}/c") .And .UsingPost(); server.Stop(); ```
Author
Owner

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

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

@StefH commented on GitHub (Sep 26, 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#452