mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-22 08:48:46 +02:00
Update Handlebars Transformer logic (ReplaceNodeOptions) (#1036)
* Update Handlebars Transformer logic (ReplaceNodeOptions) * okeee * EvaluateAndKeep = Evaluate * fix? * linux * _ * tt * xxx * fx * x * fix test
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using CultureAwareTesting.xUnit;
|
||||
using FluentAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Util;
|
||||
@@ -7,6 +9,179 @@ namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class StringUtilsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("", "")]
|
||||
[InlineData("x", "x")]
|
||||
public void TryConvertToString_ShouldWorkCorrectly(string input, string expectedValue)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(false);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<bool>().And.Be(expectedValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("true", true, true)]
|
||||
[InlineData("false", false, true)]
|
||||
[InlineData("not a bool", false, false)] // Invalid case
|
||||
public void TryConvertToBool_ShouldWorkCorrectly(string input, bool expectedValue, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<bool>().And.Be(expectedValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("123", 123, true)]
|
||||
[InlineData("-456", -456, true)]
|
||||
[InlineData("not an int", 0, false)] // Invalid case
|
||||
public void TryConvertToInt_ShouldWorkCorrectly(string input, int expectedValue, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<int>().And.Be(expectedValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("12345678901", 12345678901L, true)]
|
||||
[InlineData("-9876543210", -9876543210L, true)]
|
||||
[InlineData("not a long", 0L, false)] // Invalid case
|
||||
public void TryConvertToLong_ShouldWorkCorrectly(string input, long expectedValue, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<long>().And.Be(expectedValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[CulturedTheory("en-US")]
|
||||
[InlineData("123.1", 123.1, true)]
|
||||
[InlineData("-456.1", -456.1, true)]
|
||||
[InlineData("not a double", 0.0, false)] // Invalid case
|
||||
public void TryConvertToDouble_ShouldWorkCorrectly(string input, double expectedValue, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
((double) convertedValue).Should().BeApproximately(expectedValue, 0.01);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("3F2504E0-4F89-11D3-9A0C-0305E82C3301", true)]
|
||||
[InlineData("00000000-0000-0000-0000-000000000000", true)]
|
||||
[InlineData("3f2504e0-4f89-11d3-9a0c-0305e82c3301", true)] // Lowercase Guid
|
||||
[InlineData("not a guid", false)] // Invalid case
|
||||
public void TryConvertToGuid_ShouldWorkCorrectly(string input, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<Guid>();
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2023-04-01", true)]
|
||||
[InlineData("01/01/2000", true)]
|
||||
[InlineData("not a date", false)] // Invalid case
|
||||
public void TryConvertToDateTime_ShouldWorkCorrectly(string input, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<DateTime>().And.Subject.As<DateTime>().Date.Should().Be(DateTime.Parse(input).Date);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1.00:00:00", true)] // 1 day
|
||||
[InlineData("00:30:00", true)] // 30 minutes
|
||||
[InlineData("not a timespan", false)] // Invalid case
|
||||
public void TryConvertToTimeSpan_ShouldWorkCorrectly(string input, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<TimeSpan>().And.Subject.As<TimeSpan>().Should().Be(TimeSpan.Parse(input));
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("http://example.com", true)]
|
||||
[InlineData("https://example.com/path?query=string#fragment", true)]
|
||||
[InlineData("ftp://example.com", true)]
|
||||
[InlineData("file://example.com", false)]
|
||||
[InlineData("not a uri", false)] // Invalid case
|
||||
public void TryConvertToUri_ShouldWorkCorrectly(string input, bool expectedConversion)
|
||||
{
|
||||
var (isConverted, convertedValue) = StringUtils.TryConvertToKnownType(input);
|
||||
|
||||
isConverted.Should().Be(expectedConversion);
|
||||
if (isConverted)
|
||||
{
|
||||
convertedValue.Should().BeOfType<Uri>().And.Subject.As<Uri>().AbsoluteUri.Should().Be(new Uri(input).AbsoluteUri);
|
||||
}
|
||||
else
|
||||
{
|
||||
convertedValue.Should().Be(input);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("And", MatchOperator.And)]
|
||||
[InlineData("Or", MatchOperator.Or)]
|
||||
|
||||
Reference in New Issue
Block a user