Add Random Regex (using Fare) (#236)

* Xeger

* update example

* 1.0.7

* Fix tests for Handlebars_Xeger

* ReplaceNodeValue

* 1.0.5

* readme
This commit is contained in:
Stef Heyenrath
2018-12-06 14:29:12 +01:00
committed by GitHub
parent cd200a10a4
commit 4be1483a5f
10 changed files with 166 additions and 28 deletions

View File

@@ -0,0 +1,39 @@
using System;
using Fare;
using HandlebarsDotNet;
using WireMock.Validation;
namespace WireMock.Transformers
{
internal static class HandleBarsXeger
{
public static void Register(IHandlebars handlebarsContext)
{
handlebarsContext.RegisterHelper("Xeger", (writer, context, arguments) =>
{
string value = ParseArgumentAndGenerate(arguments);
writer.Write(value);
});
handlebarsContext.RegisterHelper("Xeger", (writer, options, context, arguments) =>
{
string value = ParseArgumentAndGenerate(arguments);
options.Template(writer, value);
});
}
private static string ParseArgumentAndGenerate(object[] arguments)
{
Check.Condition(arguments, args => args.Length == 1, nameof(arguments));
Check.NotNull(arguments[0], "arguments[0]");
switch (arguments[0])
{
case string pattern:
return new Xeger(pattern).Generate();
}
throw new NotSupportedException($"The value '{arguments[0]}' with type '{arguments[0]?.GetType()}' cannot be used in Handlebars Xeger.");
}
}
}