mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 22:33:35 +01:00
* Add TIOBE + include SonarAnalyzer.CSharp * . * cp * Copyright © WireMock.Net * more fixes * fix * xpath * if (Matchers == null || !Matchers.Any()) * if (Matchers != null) * ? * . * .
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using Newtonsoft.Json.Linq;
|
|
using NFluent;
|
|
using WireMock.Handlers;
|
|
using WireMock.Models;
|
|
using WireMock.ResponseBuilders;
|
|
using WireMock.Settings;
|
|
using Xunit;
|
|
|
|
namespace WireMock.Net.Tests.ResponseBuilders;
|
|
|
|
public class ResponseWithHandlebarsHumanizerTests
|
|
{
|
|
private const string ClientIp = "::1";
|
|
private readonly WireMockServerSettings _settings = new();
|
|
|
|
private readonly Mock<IMapping> _mappingMock;
|
|
|
|
public ResponseWithHandlebarsHumanizerTests()
|
|
{
|
|
_mappingMock = new Mock<IMapping>();
|
|
|
|
var filesystemHandlerMock = new Mock<IFileSystemHandler>(MockBehavior.Strict);
|
|
filesystemHandlerMock.Setup(fs => fs.ReadResponseBodyAsString(It.IsAny<string>())).Returns("abc");
|
|
|
|
_settings.FileSystemHandler = filesystemHandlerMock.Object;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Response_ProvideResponseAsync_Handlebars_Humanizer()
|
|
{
|
|
// Assign
|
|
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "GET", ClientIp);
|
|
|
|
var responseBuilder = Response.Create()
|
|
.WithBodyAsJson(new
|
|
{
|
|
Text = string.Format("{{{{[Humanizer.Humanize] \"{0}\" }}}}", "PascalCaseInputStringIsTurnedIntoSentence")
|
|
})
|
|
.WithTransformer();
|
|
|
|
// Act
|
|
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
|
|
|
// Assert
|
|
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
|
|
Check.That(j["Text"].Value<string>()).IsEqualTo("Pascal case input string is turned into sentence");
|
|
}
|
|
} |