mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
While stubbing the request with same path, responses are not getting overwritten. #288
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @anjoiype on GitHub (Jul 29, 2020).
Originally assigned to: @StefH on GitHub.
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 on GitHub (Jul 29, 2020):
Hello @anjoiype
How to you set the new mapping? Via C# code or by posting to __admin endpoint?
@anjoiype commented on GitHub (Jul 29, 2020):
I set the new mapping via C# code.
_testContext.MockServer .Given(Request.Create() .WithPath($"/foo/bar")) .RespondWith(Response.Create() .WithStatusCode(200) .WithBodyFromFile(fooPath));Here
_testContextis injected through DI and it containsWireMockServer.Start()@StefH commented on GitHub (Jul 29, 2020):
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 on GitHub (Jul 29, 2020):
It works now. Thanks a lot for wonderful support.