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

Closed
opened 2025-12-29 15:19:45 +01:00 by adam · 4 comments
Owner

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?

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?
adam added the question label 2025-12-29 15:19:45 +01:00
adam closed this issue 2025-12-29 15:19:45 +01:00
Author
Owner

@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?

@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?
Author
Owner

@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 _testContext is injected through DI and it contains WireMockServer.Start()

@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 `_testContext` is injected through DI and it contains `WireMockServer.Start()`
Author
Owner

@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

@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
Author
Owner

@anjoiype commented on GitHub (Jul 29, 2020):

It works now. Thanks a lot for wonderful support.

@anjoiype commented on GitHub (Jul 29, 2020): It works now. Thanks a lot for wonderful support.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#288