mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Iterative Responses Based on Number of Requests Received #431
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 @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
@StefH commented on GitHub (Aug 3, 2022):
@3mv3
I think you are looking for Scenarios and States.
@3mv3 commented on GitHub (Aug 3, 2022):
@StefH Exactly what I needed! Thank you so much!
@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
@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):
@3mv3
Maybe in someone can make a UI with drag/drop support to build scenarios and states from existing mappings...