question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WithBody(Func) executes for all requests, ignore path matching

See original GitHub issue

Hello, Thank you for this great NuGet package! It is awesome!!

During using the package I was faced with following issue:

I start a single WireMockServer and then create two mappings one for /api/Customer/add and another for /api/Customer/update, also, I use .WithBody((body) => VerifyCrmRequestBody(TestCustomers.Customer1, body))) for both requests mapping.

When no matter what request send to wiremock WithBody executes for both mappings and ignore .WithPath(“/api/Customer/add”)

Is it correct behavior? How can I solve this issue and verify WithBody for only a specific URL path?

Package:

 <PackageReference Include="WireMock.Net" Version="1.5.6" />
    // RestEase http client

    [BasePath("/api/Customer")]
    public interface ICustomerCrmClient
    {
        [Post("add")]
        public Task Add([Body] CustomerCrmCreation customer);

        [Put("update")]
        public Task Update([Body] CustomerCrmCreation customer);
    }

    public void Test()
    {
        var wireMockServer = WireMockServer.Start();
        wireMockServer.Given(Request.Create()
                                   .UsingPost()
                                   .WithPath("/api/Customer/add")
                                   .WithBody((body) => VerifyCrmRequestBody(TestCustomers.Customer1, body)))
                        .RespondWith(WireMock.ResponseBuilders.Response.Create().WithStatusCode(HttpStatusCode.OK));

        wireMockServer.Given(Request.Create()
                                    .UsingPut()
                                    .WithPath("/api/Customer/update")
                                    .WithBody((body) => VerifyRequestBody(TestCustomers.Customer1, body)))
                       .RespondWith(WireMock.ResponseBuilders.Response.Create().WithStatusCode(HttpStatusCode.OK));
    }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
khdevnetcommented, Sep 16, 2022

yes, I used logging to verify that request was sent, great feature!! Problem solved for me @mattisking @StefH thank you guys, you saved tons of my time. have nice weekend!!

0reactions
mattiskingcommented, Sep 16, 2022

You can also assign a Priority for each mapping to allow you to prioritize one mapping over another when you match multiple times.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implement different response with WireMock when no ...
Implement different response with WireMock when no request(s) match - Stack Overflow.
Read more >
Creating Expectations
A request properties matcher matches requests using one or more of the following properties: method - property matcher; path - property matcher; path...
Read more >
Wiremock Stubbing, Stub Verification And Proxying With ...
First stubs are configured on a Wiremock instance. Now, when a request is sent to the Wiremock server, then the request matching logic...
Read more >
Introduction to MockServer
Requests can be matched using: path – URL path; query string – URL parameters; headers – request headers; cookies – client side cookies;...
Read more >
Build an HTTPS-intercepting JavaScript proxy in 30 ...
Create a new directory; Run npm install mockttp ... Above, we've created a script that matches all requests, and always returns a fixed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found