Skip to content

Commit

Permalink
Dynamic response handlebars templating (2) (#273)
Browse files Browse the repository at this point in the history
* Dynamic response files using Handlebars templating
(#270)

* * Response templating / transformation using Handlebars and extensions

* Add unit test for JsonPath and BodyAsFile mapping (#272)

* fix merge issue
  • Loading branch information
StefH committed May 4, 2019
1 parent 96e68ae commit 6e45255
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,32 @@ public async Task Response_ProvideResponse_Handlebars_WithBodyAsFile()
// Assert
Check.That(responseMessage.BodyData.BodyAsFile).Equals(@"c:\1\test.xml");
}

[Fact]
public async Task Response_ProvideResponse_Handlebars_WithBodyAsFile_JsonPath()
{
// Assign
string jsonString = "{ \"MyUniqueNumber\": \"1\" }";
var bodyData = new BodyData
{
BodyAsString = jsonString,
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
DetectedBodyType = BodyType.Json,
DetectedBodyTypeFromContentType = BodyType.Json,
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData);

string jsonPath = "\"$.MyUniqueNumber\"";
var response = Response.Create()
.WithTransformer()
.WithBodyFromFile(@"c:\\{{JsonPath.SelectToken request.body " + jsonPath + "}}\\test.json"); // why use a \\ here ?

// Act
var responseMessage = await response.ProvideResponseAsync(request);

// Assert
Check.That(responseMessage.BodyData.BodyAsFile).Equals(@"c:\1\test.json");
}
}
}

0 comments on commit 6e45255

Please sign in to comment.