Iterative Responses Based on Number of Requests Received #431

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

Originally created by @3mv3 on GitHub (Aug 3, 2022).

Hello!

I am in the process of mocking our existing integration tests using a proxy. It works great, but I was wondering if there is a way to return a different response depending on the number of same requests that have been received? For example, our test gets a list of data to process, processes some of it, then calls the same service again to re-get the list, which will now be missing what was processed although the call signature would be the same, ie:

GET https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001' (returns 2 lines)
POST https://U-B709GK3-MV.com/latest/shipmentLines/confirm (processes 1 line)
GET https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001' (returns 1 line)

I am using the dotnet tool, and these are my current settings:
dotnet-wiremock --ReadStaticMappings true --ProxyURL "https://U-B709GK3-MV.com" --SaveMapping true --SaveMappingToFile true --SaveMappingForStatusCodePattern "2xx" --ExcludedHeaders "Accept" "Host" "Connection" "User-Agent" "Accept-Encoding" "Authorization" "X-SessionId" "Postman-Token"

Is this possible?

Best regards,
Matt

Originally created by @3mv3 on GitHub (Aug 3, 2022). Hello! I am in the process of mocking our existing integration tests using a proxy. It works great, but I was wondering if there is a way to return a different response depending on the number of same requests that have been received? For example, our test gets a list of data to process, processes some of it, then calls the same service again to re-get the list, which will now be missing what was processed although the call signature would be the same, ie: GET https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001' (returns 2 lines) POST https://U-B709GK3-MV.com/latest/shipmentLines/confirm (processes 1 line) GET https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001' (returns 1 line) I am using the dotnet tool, and these are my current settings: dotnet-wiremock --ReadStaticMappings true --ProxyURL "https://U-B709GK3-MV.com" --SaveMapping true --SaveMappingToFile true --SaveMappingForStatusCodePattern "2xx" --ExcludedHeaders "Accept" "Host" "Connection" "User-Agent" "Accept-Encoding" "Authorization" "X-SessionId" "Postman-Token" Is this possible? Best regards, Matt
adam added the question label 2025-12-29 15:23:39 +01:00
adam closed this issue 2025-12-29 15:23:40 +01:00
Author
Owner

@StefH commented on GitHub (Aug 3, 2022):

@3mv3
I think you are looking for Scenarios and States.

@StefH commented on GitHub (Aug 3, 2022): @3mv3 I think you are looking for [Scenarios and States](https://github.com/WireMock-Net/WireMock.Net/wiki/Scenarios-and-States).
Author
Owner

@3mv3 commented on GitHub (Aug 3, 2022):

@StefH Exactly what I needed! Thank you so much!

@3mv3 commented on GitHub (Aug 3, 2022): @StefH Exactly what I needed! Thank you so much!
Author
Owner

@3mv3 commented on GitHub (Aug 3, 2022):

One last question on this topic, is there a way to automatically record Scenarios / States during proxy recording? Or is it a case of manually updating the files once they have been recorded? Going back to my original set of calls:

GET https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001' (returns 2 lines) - Records a new mock, with Scenario =shipmentLines, SetStateTo = 0
POST https://u-b709gk3-mv.com/latest/shipmentLines/confirm (processes 1 line)
GET https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001' (returns 1 line) - Records a new mock with Scenario =shipmentLines, WhenStateIs = 0, SetStateTo = 1

@3mv3 commented on GitHub (Aug 3, 2022): One last question on this topic, is there a way to automatically record Scenarios / States during proxy recording? Or is it a case of manually updating the files once they have been recorded? Going back to my original set of calls: GET [https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001](https://u-b709gk3-mv.com/latest/shipmentLines?q=org=%27001)' (returns 2 lines) - Records a new mock, with Scenario =shipmentLines, SetStateTo = 0 POST https://u-b709gk3-mv.com/latest/shipmentLines/confirm (processes 1 line) GET [https://U-B709GK3-MV.com/latest/shipmentLines?q=org='001](https://u-b709gk3-mv.com/latest/shipmentLines?q=org=%27001)' (returns 1 line) - Records a new mock with Scenario =shipmentLines, WhenStateIs = 0, SetStateTo = 1
Author
Owner

@StefH commented on GitHub (Aug 3, 2022):

No, this is not possible. You just need to capture all all requests first, and then manually change these into scenario and states.

@StefH commented on GitHub (Aug 3, 2022): No, this is not possible. You just need to capture all all requests first, and then manually change these into scenario and states.
Author
Owner

@StefH commented on GitHub (Aug 3, 2022):

@3mv3

Maybe in someone can make a UI with drag/drop support to build scenarios and states from existing mappings...

@StefH commented on GitHub (Aug 3, 2022): @3mv3 Maybe in someone can make a UI with drag/drop support to build scenarios and states from existing mappings...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#431