mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-27 19:27:42 +02:00
Fix Null body in handlebar transformation (#442)
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.2.0</VersionPrefix>
|
<VersionPrefix>1.2.1</VersionPrefix>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Choose>
|
<Choose>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace WireMock.Transformers
|
|||||||
|
|
||||||
var template = new { request = requestMessage };
|
var template = new { request = requestMessage };
|
||||||
|
|
||||||
switch (original.BodyData.DetectedBodyType)
|
switch (original.BodyData?.DetectedBodyType)
|
||||||
{
|
{
|
||||||
case BodyType.Json:
|
case BodyType.Json:
|
||||||
TransformBodyAsJson(handlebarsContext.Handlebars, template, original, responseMessage);
|
TransformBodyAsJson(handlebarsContext.Handlebars, template, original, responseMessage);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
@@ -25,6 +26,23 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
|||||||
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
|
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
|
||||||
private const string ClientIp = "::1";
|
private const string ClientIp = "::1";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Response_ProvideResponse_Handlebars_WithNullBody_ShouldNotThrowException()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
|
||||||
|
var request = new RequestMessage(urlDetails, "GET", ClientIp);
|
||||||
|
|
||||||
|
var response = Response.Create()
|
||||||
|
.WithTransformer();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var responseMessage = await response.ProvideResponseAsync(request, _settings);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
responseMessage.BodyData.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Response_ProvideResponse_Handlebars_UrlPathVerb()
|
public async Task Response_ProvideResponse_Handlebars_UrlPathVerb()
|
||||||
{
|
{
|
||||||
@@ -47,12 +65,14 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
|||||||
Check.That(responseMessage.BodyData.BodyAsString).Equals("test http://localhost/foo /foo POSt");
|
Check.That(responseMessage.BodyData.BodyAsString).Equals("test http://localhost/foo /foo POSt");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public async Task Response_ProvideResponse_Handlebars_UrlPath()
|
[InlineData("Get")]
|
||||||
|
[InlineData("Post")]
|
||||||
|
public async Task Response_ProvideResponse_Handlebars_UrlPath(string httpMethod)
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
|
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
|
||||||
var request = new RequestMessage(urlDetails, "POST", ClientIp);
|
var request = new RequestMessage(urlDetails, httpMethod, ClientIp);
|
||||||
|
|
||||||
var response = Response.Create()
|
var response = Response.Create()
|
||||||
.WithBody("{{request.url}} {{request.absoluteurl}} {{request.path}} {{request.absolutepath}}")
|
.WithBody("{{request.url}} {{request.absoluteurl}} {{request.path}} {{request.absolutepath}}")
|
||||||
|
|||||||
Reference in New Issue
Block a user