mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How do I mock an endpoint to return an error given a specific parameter, otherwise return success? #441
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 @rosemaryehlers on GitHub (Aug 19, 2022).
I am mocking an endpoint /mark-item, which takes a numeric id. when id=666, I want the endpoint to return 500, otherwise all other requests to that endpoint should return 200.
This is what my static mapping file currently looks like:
When I remove the success stub, a request to http://localhost:49223/mark-item?id=66 returns 404 and a request to http://localhost:49223/mark-item?id=666 returns 500. But when I add in the success stub, both requests return 200. I have tried flipping the priorities, but that also makes no difference.
What is the correct way to do this? Thank you!
@StefH commented on GitHub (Aug 19, 2022):
I think you should switch the priority.
->
The priority. (A low value means higher priority.)Can you try that?
@rosemaryehlers commented on GitHub (Aug 22, 2022):
I've tried the priority values flipped, and it does not appear to affect anything.
Further testing shows that the WildcardMatcher for * for the id param actually fails requests with 404 no mapping, so I removed that clause entirely. New file is as follows:
Hitting the following urls in my web browser give the following:
http://localhost:49159/mark-item?id=666 -> Return 200 (Want it to return 500)
http://localhost:49159/mark-item?id=4 -> Return 200 (Correct)
@rosemaryehlers commented on GitHub (Aug 22, 2022):
Oh god I'm an idiot. The guids are matching, so the last configuration is overriding the first one. Sorry about that!
@StefH commented on GitHub (Aug 22, 2022):
Ah. I also missed duplicate GUID.
Maybe WireMock.Net should throw exception when duplicate GUiD is detected ..