Closed denstorti closed 5 years ago
This scenario is not yet supported, I'll take a look and modify the code.
@denstorti Can you try MyGet version WireMock.Net.1.0.15-ci-11270 ?
Note that you need to set "UseTransformer": true
in the mapping.
@StefH, I could test it using the MyUniqueNumber as query string and also as JSON Path
Example using JSON Path
Input data (save as data.json):
{
"MyUniqueNumber": "4444"
}
Mapping:
{
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/postbodyasfile",
"IgnoreCase": false
}
]
},
"Methods": [
"post"
]
},
"Response": {
"StatusCode": 200,
"Headers": { "Content-Type": "application/json" },
"BodyAsFile": "c:/MockResponses/{{JsonPath.SelectToken request.body \"$.MyUniqueNumber\"}}/serv1.json",
"UseTransformer": true
}
}
curl test:
curl -d @data.json http://localhost:9091/postbodyasfile
Thank you!
OK.
I will release a new NuGet today.
Note that instead of JsonPath, you can also use JmesPath as a matcher. http://jmespath.org/ https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#jmes-path-jmespathmatcher
Hi,
I have a question about the current capabilities of templating.
I'd like to retrieve responses from files using WireMock.Net, and for that I am using static mappings with "BodyAsFile" attribute.
Example:
But I'd like to vary the response directory based on the request attributes, pretty much as Handlebars templates do.
Example (MyUniqueNumber would be the name of each folder):
In this example the variable is in the Path, but it could be appended to the file name as well.
I did test it and it seems the library tries to load the file from disk when loaded and not per request, so it cannot find the invalid path "c:\temp-wiremock\_admin\mappings\_{{request.query.MyUniqueNumber}}\MyXmlResponse.xml".
Is this scenario currently supported (maybe in a different way)?