mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Using Random Handlebar mixed with {{ response templating }} #520
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 @pouyaSobhanipour on GitHub (Jun 12, 2023).
Originally assigned to: @StefH on GitHub.
Hello
i am using Random HandleBar in .Net to receieve a randome response from a list of predefied values using wiremock.
String List: "{{Random Type=\"StringList\" Values=[\"a\", \"b\", \"c\"]}}"in my case a, b or c are different json responces. as following :
a => {'result':'ERROR','description':'Value Not Found','ReqCode':'123'}
b => {'result':'ERROR','description':'Value set to Null','ReqCode':'456'}
c => {'result':'ERROR','description':'More than one item','ReqCode':'789'}
what i need to have in my project , is to understand which response ( a , b or c ) is associated with what request ( but i don't want the ReqCode to be fixed and pre-defiend).
we already know that one way to pass a dynamic value from request into response would be using "Response Templating - {{ }}" . but in this case , i could not find a way to pass this dynamic value using Random responce handlebar as the following :
"a\ => "{'result':'ERROR','description':'Value Not Found','ReqCode':'{{ my random Code }}'}
"b\ => "{'result':'ERROR','description':'Value set to Null','ReqCode':'{{my random Code }}'}
"c\ => "{'result':'ERROR','description':'More than one item','ReqCode':'{{my random Code }}'}
using this what i receive in response is the string itself ({{my random Code }}) rather than the value i passed in request body.
Is there any way to do this in wiremock ?
Thanks
@StefH commented on GitHub (Jun 17, 2023):
So depending on a random value from a string list, you want to return a different message and a random code?
@pouyaSobhanipour commented on GitHub (Jun 19, 2023):
Hello .
I need to pass a value into the Random string list.
as an example
so my request body would be (using a Post request) :
and the response would be a random string, chosed from the Random List filed with the passed data.
so the response body comming from wiremock server would be:
{'result':'ERROR','description':'Value set to Null','ReqCode':'1234'}How am i able to implement this ?
Thanks
@StefH commented on GitHub (Jun 23, 2023):
See https://github.com/WireMock-Net/WireMock.Net/issues/956