mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 09:52:05 +01:00
Fix ResponseMessageTransformer
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NFluent;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
@@ -12,6 +14,29 @@ namespace WireMock.Net.Tests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_Handlebars_WithBodyAsJson()
|
||||
{
|
||||
// given
|
||||
string jsonString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||
var bodyData = new BodyData
|
||||
{
|
||||
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
|
||||
Encoding = Encoding.UTF8
|
||||
};
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, bodyData);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithBodyAsJson(new { x = "test {{request.url}}" })
|
||||
.WithTransformer();
|
||||
|
||||
// act
|
||||
var responseMessage = await response.ProvideResponseAsync(request);
|
||||
|
||||
// then
|
||||
Check.That(JsonConvert.SerializeObject(responseMessage.BodyAsJson)).Equals("{\"x\":\"test http://localhost/foo\"}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_Handlebars_UrlPathVerb()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user