WithBody(Func) executes for all requests, ignore path matching
See original GitHub issueHello, 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:
- Created a year ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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!!
You can also assign a Priority for each mapping to allow you to prioritize one mapping over another when you match multiple times.