WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.41k stars 209 forks source link

While stubbing the request with same path, responses are not getting overwritten. #493

Closed anjoiype closed 4 years ago

anjoiype commented 4 years ago

I have a requirement that on calling same path, each time I have to get separate response. It is not related to stateful behavior. When I try to set the response 2nd time, its not overwriting the first and hence getting the old response. If I reset the mappings, it will reset the whole mappings which I don't need. How to overwrite the response for same request?

StefH commented 4 years ago

Hello @anjoiype How to you set the new mapping? Via C# code or by posting to __admin endpoint?

anjoiype commented 4 years ago

I set the new mapping via C# code. _testContext.MockServer .Given(Request.Create() .WithPath($"/foo/bar")) .RespondWith(Response.Create() .WithStatusCode(200) .WithBodyFromFile(fooPath));
Here _testContext is injected through DI and it contains WireMockServer.Start()

StefH commented 4 years ago

When using that code, a new mapping is added. So you end up with 2 mappings.

If you want to replace it, add a GUID when adding the first mapping.

And use the same GUID when adding the new one. See https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Net452.Classic/MainApp.cs#L169

anjoiype commented 4 years ago

It works now. Thanks a lot for wonderful support.