Reset single scenario using HTTP request #460

Closed
opened 2025-12-29 15:24:23 +01:00 by adam · 7 comments
Owner

Originally created by @iparry7979 on GitHub (Oct 19, 2022).

I am running WireMock as a standalone app.

Regarding resetting scenarios: I am able to reset all scenarios using an empty POST request such as: POST /__admin/scenarios/reset.

However, it fails when I try to reset a single scenario using an empty PUT request for example: PUT /__admin/scenarios/my_scenario/state

According to the documentation here this should work in the java version. Is this implemented in the C# version? If so am I doing something wrong to reset a single scenario?

Originally created by @iparry7979 on GitHub (Oct 19, 2022). I am running WireMock as a standalone app. Regarding resetting scenarios: I am able to reset all scenarios using an empty POST request such as: POST /__admin/scenarios/reset. However, it fails when I try to reset a single scenario using an empty PUT request for example: PUT /__admin/scenarios/my_scenario/state According to the documentation [here](https://wiremock.org/docs/stateful-behaviour/) this should work in the java version. Is this implemented in the C# version? If so am I doing something wrong to reset a single scenario?
adam added the question label 2025-12-29 15:24:23 +01:00
adam closed this issue 2025-12-29 15:24:23 +01:00
Author
Owner

@StefH commented on GitHub (Oct 19, 2022):

Hello @iparry7979,

This is not yet implemented in the current version, however you can try a preview version which supports:

  • DELETE to /__admin/scenarios/ABC
  • POST to /__admin/scenarios/ABC/reset

Where ABC is the name from the scenario.

Preview version = "1.5.8-ci-16566".
Info: https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Oct 19, 2022): Hello @iparry7979, This is not yet implemented in the current version, however you can try a preview version which supports: - DELETE to `/__admin/scenarios/ABC` - POST to `/__admin/scenarios/ABC/reset` Where `ABC` is the name from the scenario. Preview version = "1.5.8-ci-16566". Info: https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@StefH commented on GitHub (Oct 21, 2022):

https://github.com/WireMock-Net/WireMock.Net/pull/834

@StefH commented on GitHub (Oct 21, 2022): https://github.com/WireMock-Net/WireMock.Net/pull/834
Author
Owner

@StefH commented on GitHub (Oct 22, 2022):

@iparry7979 did you have to time to verify this logic in the preview NuGet ?

@StefH commented on GitHub (Oct 22, 2022): @iparry7979 did you have to time to verify this logic in the preview NuGet ?
Author
Owner

@StefH commented on GitHub (Oct 25, 2022):

@iparry7979 Did you have time to test this?

@StefH commented on GitHub (Oct 25, 2022): @iparry7979 Did you have time to test this?
Author
Owner

@iparry7979 commented on GitHub (Oct 25, 2022):

Hi @StefH I have done some testing with this preview version. It's not working quite as I expected. I have the following stubs:

server.Given(Request.Create().WithPath("/scenario").UsingGet()).InScenario("Scenario1").WillSetStateTo("State2") .RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "text/plain").WithBody("Initial state"));

server.Given(Request.Create().WithPath("/scenario").UsingGet()).InScenario("Scenario1").WhenStateIs("State2").WillSetStateTo("State3").RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "text/plain").WithBody("State 2"));

server.Given(Request.Create().WithPath("/scenario").UsingGet()).InScenario("Scenario1").WhenStateIs("State3") .RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "text/plain").WithBody("State 3"));

What I was expecting was that when I hit the /scenario path multiple times I would get the following responses:

Initial state
State 2
State 3
State 3
State 3
...

Since when the scenario is in state 3 there is no WillSetStateTo. What I actually got as responses was:

Initial state
State 2
State 3
Initial state
State 2
State 3
...

So the on the 3rd call it set the state back to the initial state despite having no instruction to reset the state. I also tested the POST to /__admin/scenarios/ABC/reset. Here were the results:

C:\Developer>curl http://localhost:7979/scenario
Initial state

C:\Developer>curl -X POST http://localhost:7979/__admin/scenarios/Scenario1/reset
State 2

C:\Developer>curl http://localhost:7979/scenario
State 3

So the POST to the admin url seemed to just do the same thing as a call to the /scenario path and updated the state to state3. Whereas I expected it should reset the scenario to it's initial state. I may be misunderstanding something about the way it is supposed to work though.

@iparry7979 commented on GitHub (Oct 25, 2022): Hi @StefH I have done some testing with this preview version. It's not working quite as I expected. I have the following stubs: `server.Given(Request.Create().WithPath("/scenario").UsingGet()).InScenario("Scenario1").WillSetStateTo("State2") .RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "text/plain").WithBody("Initial state"));` `server.Given(Request.Create().WithPath("/scenario").UsingGet()).InScenario("Scenario1").WhenStateIs("State2").WillSetStateTo("State3").RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "text/plain").WithBody("State 2"));` `server.Given(Request.Create().WithPath("/scenario").UsingGet()).InScenario("Scenario1").WhenStateIs("State3") .RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "text/plain").WithBody("State 3"));` What I was expecting was that when I hit the /scenario path multiple times I would get the following responses: Initial state State 2 State 3 State 3 State 3 ... Since when the scenario is in state 3 there is no WillSetStateTo. What I actually got as responses was: Initial state State 2 State 3 Initial state State 2 State 3 ... So the on the 3rd call it set the state back to the initial state despite having no instruction to reset the state. I also tested the POST to /__admin/scenarios/ABC/reset. Here were the results: `C:\Developer>curl http://localhost:7979/scenario` `Initial state` `C:\Developer>curl -X POST http://localhost:7979/__admin/scenarios/Scenario1/reset` `State 2` `C:\Developer>curl http://localhost:7979/scenario` `State 3` So the POST to the admin url seemed to just do the same thing as a call to the /scenario path and updated the state to state3. Whereas I expected it should reset the scenario to it's initial state. I may be misunderstanding something about the way it is supposed to work though.
Author
Owner

@iparry7979 commented on GitHub (Oct 25, 2022):

@StefH Please disregard the second part of my comment above. I had updated Wiremock.Net.Standalone but not WireMock.Net. When I updated the package the POST to /__admin/scenarios/Scenario1/reset worked as expected in version 1.5.8-ci-16566.

@iparry7979 commented on GitHub (Oct 25, 2022): @StefH Please disregard the second part of my comment above. I had updated Wiremock.Net.Standalone but not WireMock.Net. When I updated the package the POST to /__admin/scenarios/Scenario1/reset worked as expected in version 1.5.8-ci-16566.
Author
Owner

@StefH commented on GitHub (Oct 26, 2022):

@iparry7979 Thanks for testing. I'll merge PR to master en close this issue.

@StefH commented on GitHub (Oct 26, 2022): @iparry7979 Thanks for testing. I'll merge PR to master en close this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#460