Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset single scenario using HTTP request #833

Closed
iparry7979 opened this issue Oct 18, 2022 · 7 comments
Closed

Reset single scenario using HTTP request #833

iparry7979 opened this issue Oct 18, 2022 · 7 comments
Labels

Comments

@iparry7979
Copy link

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?

@StefH
Copy link
Collaborator

StefH commented 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
Copy link
Collaborator

StefH commented Oct 21, 2022

#834

@StefH
Copy link
Collaborator

StefH commented Oct 22, 2022

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

@StefH
Copy link
Collaborator

StefH commented Oct 25, 2022

@iparry7979 Did you have time to test this?

@iparry7979
Copy link
Author

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
Copy link
Author

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

@StefH
Copy link
Collaborator

StefH commented Oct 26, 2022

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

@StefH StefH closed this as completed Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants