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

Why does UsingMethod check _callscount? #815

Closed
robvangeloven opened this issue Sep 26, 2022 · 3 comments
Closed

Why does UsingMethod check _callscount? #815

robvangeloven opened this issue Sep 26, 2022 · 3 comments
Assignees
Labels

Comments

@robvangeloven
Copy link

robvangeloven commented Sep 26, 2022

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.

@StefH
Copy link
Collaborator

StefH commented 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 (#816)

@robvangeloven
Copy link
Author

robvangeloven commented 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();

@StefH StefH added bug and removed question labels Sep 26, 2022
@StefH StefH self-assigned this Sep 26, 2022
@StefH
Copy link
Collaborator

StefH commented Sep 26, 2022

#816

@StefH StefH closed this as completed Oct 15, 2022
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