mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 15:10:17 +02:00
Include Handlebars.Net.Helpers project (#456)
* wip * h 100 * rename * csproj
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
<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="log4net" Version="2.0.8" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<!--<PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.4.0" />-->
|
<!--<PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.4.0" />-->
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using WireMock.Validation;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsFile
|
internal static class HandlebarsFile
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
|
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
using HandlebarsDotNet;
|
|
||||||
using WireMock.Handlers;
|
|
||||||
|
|
||||||
namespace WireMock.Transformers
|
|
||||||
{
|
|
||||||
internal static class HandlebarsHelpers
|
|
||||||
{
|
|
||||||
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
|
|
||||||
{
|
|
||||||
HandleBarsRegex.Register(handlebarsContext);
|
|
||||||
|
|
||||||
HandleBarsJsonPath.Register(handlebarsContext);
|
|
||||||
|
|
||||||
HandleBarsLinq.Register(handlebarsContext);
|
|
||||||
|
|
||||||
HandleBarsRandom.Register(handlebarsContext);
|
|
||||||
|
|
||||||
HandleBarsXeger.Register(handlebarsContext);
|
|
||||||
|
|
||||||
HandleBarsXPath.Register(handlebarsContext);
|
|
||||||
|
|
||||||
HandleBarsFile.Register(handlebarsContext, fileSystemHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ using WireMock.Validation;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsJsonPath
|
internal static class HandlebarsJsonPath
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext)
|
public static void Register(IHandlebars handlebarsContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using WireMock.Validation;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsLinq
|
internal static class HandlebarsLinq
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext)
|
public static void Register(IHandlebars handlebarsContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using WireMock.Validation;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsRandom
|
internal static class HandlebarsRandom
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext)
|
public static void Register(IHandlebars handlebarsContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using WireMock.Validation;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsRegex
|
internal static class HandlebarsRegex
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext)
|
public static void Register(IHandlebars handlebarsContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using Wmhelp.XPath2;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsXPath
|
internal static class HandlebarsXPath
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext)
|
public static void Register(IHandlebars handlebarsContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using WireMock.Validation;
|
|||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
{
|
{
|
||||||
internal static class HandleBarsXeger
|
internal static class HandlebarsXeger
|
||||||
{
|
{
|
||||||
public static void Register(IHandlebars handlebarsContext)
|
public static void Register(IHandlebars handlebarsContext)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace WireMock.Transformers
|
|||||||
{
|
{
|
||||||
var handlebars = Handlebars.Create(HandlebarsConfiguration);
|
var handlebars = Handlebars.Create(HandlebarsConfiguration);
|
||||||
|
|
||||||
HandlebarsHelpers.Register(handlebars, _fileSystemHandler);
|
WireMockHandlebarsHelpers.Register(handlebars, _fileSystemHandler);
|
||||||
|
|
||||||
_action?.Invoke(handlebars, _fileSystemHandler);
|
_action?.Invoke(handlebars, _fileSystemHandler);
|
||||||
|
|
||||||
|
|||||||
30
src/WireMock.Net/Transformers/WireMockHandlebarsHelpers.cs
Normal file
30
src/WireMock.Net/Transformers/WireMockHandlebarsHelpers.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.10" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.10" />
|
||||||
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
||||||
|
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(Configuration)' == 'Debug - Sonar'">
|
<ItemGroup Condition="'$(Configuration)' == 'Debug - Sonar'">
|
||||||
@@ -67,14 +68,6 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</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' ">
|
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
|
||||||
<PackageReference Include="XPath2.Extensions" Version="1.0.6.1" />
|
<PackageReference Include="XPath2.Extensions" Version="1.0.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user