Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Handlebars.Net.Helpers project #456

Merged
merged 4 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
<PackageReference Include="Handlebars.Net.Helpers" Version="0.0.3" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<!--<PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.4.0" />-->
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsFile
internal static class HandlebarsFile
{
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
{
Expand Down
25 changes: 0 additions & 25 deletions src/WireMock.Net/Transformers/HandleBarsHelpers.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsJsonPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsJsonPath
internal static class HandlebarsJsonPath
{
public static void Register(IHandlebars handlebarsContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsLinq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsLinq
internal static class HandlebarsLinq
{
public static void Register(IHandlebars handlebarsContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsRandom
internal static class HandlebarsRandom
{
public static void Register(IHandlebars handlebarsContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsRegex
internal static class HandlebarsRegex
{
public static void Register(IHandlebars handlebarsContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsXPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsXPath
internal static class HandlebarsXPath
{
public static void Register(IHandlebars handlebarsContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandleBarsXeger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace WireMock.Transformers
{
internal static class HandleBarsXeger
internal static class HandlebarsXeger
{
public static void Register(IHandlebars handlebarsContext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WireMock.Net/Transformers/HandlebarsContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public IHandlebarsContext Create()
{
var handlebars = Handlebars.Create(HandlebarsConfiguration);

HandlebarsHelpers.Register(handlebars, _fileSystemHandler);
WireMockHandlebarsHelpers.Register(handlebars, _fileSystemHandler);

_action?.Invoke(handlebars, _fileSystemHandler);

Expand Down
30 changes: 30 additions & 0 deletions src/WireMock.Net/Transformers/WireMockHandlebarsHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HandlebarsDotNet;
using HandlebarsDotNet.Helpers;
using WireMock.Handlers;

namespace WireMock.Transformers
{
internal static class WireMockHandlebarsHelpers
{
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
{
// Register https://github.com/StefH/Handlebars.Net.Helpers
HandlebarsHelpers.Register(handlebarsContext);

// Register WireMock.Net specific helpers
HandlebarsRegex.Register(handlebarsContext);

HandlebarsJsonPath.Register(handlebarsContext);

HandlebarsLinq.Register(handlebarsContext);

HandlebarsRandom.Register(handlebarsContext);

HandlebarsXeger.Register(handlebarsContext);

HandlebarsXPath.Register(handlebarsContext);

HandlebarsFile.Register(handlebarsContext, fileSystemHandler);
}
}
}
9 changes: 1 addition & 8 deletions src/WireMock.Net/WireMock.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.10" />
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug - Sonar'">
Expand All @@ -70,14 +71,6 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<PackageReference Include="Handlebars.Net" Version="[1.9.0]" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net451' ">
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
<PackageReference Include="XPath2.Extensions" Version="1.0.6.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
using Xunit;

namespace WireMock.Net.Tests.ResponseBuilders
{
public class ResponseWithHandlebarsHelpersTests
{
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
private const string ClientIp = "::1";

[Fact]
public async Task Response_ProvideResponseAsync_HandlebarsHelpers_String_Uppercase()
{
// Assign
var body = new BodyData { BodyAsString = "abc", DetectedBodyType = BodyType.String };

var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "POST", ClientIp, body);

var response = Response.Create()
.WithBody("{{String.Uppercase request.body}}")
.WithTransformer();

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

// assert
Check.That(responseMessage.BodyData.BodyAsString).Equals("ABC");
}
}
}