mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-06-08 16:02:48 +02:00
Generate C# code from Mapping (#842)
* 1 * . * v * . * . * - * b * res b * Fix UT * . * Verify * v * ... * . * . * dir * m
This commit is contained in:
@@ -255,3 +255,5 @@ paket-files/
|
|||||||
/test/WireMock.Net.Tests/coverage.opencover.xml
|
/test/WireMock.Net.Tests/coverage.opencover.xml
|
||||||
/test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml
|
/test/WireMock.Net.Tests/coverage.netcoreapp3.1.opencover.xml
|
||||||
/test/WireMock.Net.Tests/coverage.net5.0.opencover.xml
|
/test/WireMock.Net.Tests/coverage.net5.0.opencover.xml
|
||||||
|
|
||||||
|
*.received.*
|
||||||
+4
-4
@@ -42,11 +42,11 @@
|
|||||||
<Reference Include="Handlebars, Version=2.1.2.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.1.2.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.1.2\lib\net452\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.1.2\lib\net452\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars.Net.Helpers, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="Handlebars.Net.Helpers, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.3.10\lib\net452\Handlebars.Net.Helpers.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.3.12\lib\net452\Handlebars.Net.Helpers.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.3.12\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="AnyOf" version="0.3.0" targetFramework="net452" />
|
<package id="AnyOf" version="0.3.0" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net" version="2.1.2" targetFramework="net452" />
|
<package id="Handlebars.Net" version="2.1.2" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.3.10" targetFramework="net452" />
|
<package id="Handlebars.Net.Helpers" version="2.3.12" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.3.10" targetFramework="net452" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.3.12" targetFramework="net452" />
|
||||||
<package id="log4net" version="2.0.15" targetFramework="net452" />
|
<package id="log4net" version="2.0.15" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net452" />
|
||||||
|
|||||||
+4
-4
@@ -41,11 +41,11 @@
|
|||||||
<Reference Include="Handlebars, Version=2.1.2.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.1.2.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.1.2\lib\net46\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.1.2\lib\net46\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars.Net.Helpers, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="Handlebars.Net.Helpers, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.3.10\lib\net452\Handlebars.Net.Helpers.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.3.12\lib\net46\Handlebars.Net.Helpers.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.3.12\lib\net46\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="AnyOf" version="0.3.0" targetFramework="net461" />
|
<package id="AnyOf" version="0.3.0" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net" version="2.1.2" targetFramework="net461" />
|
<package id="Handlebars.Net" version="2.1.2" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.3.10" targetFramework="net461" />
|
<package id="Handlebars.Net.Helpers" version="2.3.12" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.3.10" targetFramework="net461" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.3.12" targetFramework="net461" />
|
||||||
<package id="log4net" version="2.0.15" targetFramework="net461" />
|
<package id="log4net" version="2.0.15" targetFramework="net461" />
|
||||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net461" />
|
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net461" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
|
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
|
||||||
|
|||||||
+16
-16
@@ -49,29 +49,29 @@
|
|||||||
<Reference Include="Handlebars, Version=2.1.2.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.1.2.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.1.2\lib\net46\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.1.2\lib\net46\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars.Net.Helpers, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="Handlebars.Net.Helpers, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.3.10\lib\net452\Handlebars.Net.Helpers.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.3.12\lib\net46\Handlebars.Net.Helpers.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.3.12\lib\net46\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.DynamicLinq, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.DynamicLinq, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.DynamicLinq.2.3.10\lib\net452\HandlebarsDotNet.Helpers.DynamicLinq.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.DynamicLinq.2.3.12\lib\net46\HandlebarsDotNet.Helpers.DynamicLinq.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Humanizer, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Humanizer, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Humanizer.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Humanizer.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Humanizer.2.3.12\lib\net46\HandlebarsDotNet.Helpers.Humanizer.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Json, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Json, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Json.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Json.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Json.2.3.12\lib\net46\HandlebarsDotNet.Helpers.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Random, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Random, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Random.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Random.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Random.2.3.12\lib\net46\HandlebarsDotNet.Helpers.Random.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Xeger, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Xeger, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Xeger.2.3.10\lib\net452\HandlebarsDotNet.Helpers.Xeger.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Xeger.2.3.12\lib\net46\HandlebarsDotNet.Helpers.Xeger.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.XPath, Version=2.3.10.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.XPath, Version=2.3.12.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.XPath.2.3.10\lib\net452\HandlebarsDotNet.Helpers.XPath.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.XPath.2.3.12\lib\net46\HandlebarsDotNet.Helpers.XPath.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Humanizer, Version=2.14.0.0, Culture=neutral, PublicKeyToken=979442b78dfc278e, processorArchitecture=MSIL">
|
<Reference Include="Humanizer, Version=2.14.0.0, Culture=neutral, PublicKeyToken=979442b78dfc278e, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Humanizer.Core.2.14.1\lib\netstandard2.0\Humanizer.dll</HintPath>
|
<HintPath>..\..\packages\Humanizer.Core.2.14.1\lib\netstandard2.0\Humanizer.dll</HintPath>
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
<package id="AnyOf" version="0.3.0" targetFramework="net472" />
|
<package id="AnyOf" version="0.3.0" targetFramework="net472" />
|
||||||
<package id="Fare" version="2.2.1" targetFramework="net472" />
|
<package id="Fare" version="2.2.1" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net" version="2.1.2" targetFramework="net472" />
|
<package id="Handlebars.Net" version="2.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.DynamicLinq" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.DynamicLinq" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Humanizer" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Humanizer" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Json" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Json" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Random" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Random" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Xeger" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Xeger" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.XPath" version="2.3.10" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.XPath" version="2.3.12" targetFramework="net472" />
|
||||||
<package id="Humanizer" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer" version="2.14.1" targetFramework="net472" />
|
||||||
<package id="Humanizer.Core" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer.Core" version="2.14.1" targetFramework="net472" />
|
||||||
<package id="Humanizer.Core.af" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer.Core.af" version="2.14.1" targetFramework="net472" />
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace WireMock.Types;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public enum MappingConverterType
|
||||||
|
{
|
||||||
|
Server,
|
||||||
|
|
||||||
|
Builder
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace WireMock.Types;
|
namespace WireMock.Types;
|
||||||
|
|
||||||
@@ -63,7 +64,8 @@ public class WireMockList<T> : List<T>
|
|||||||
return this[0]?.ToString();
|
return this[0]?.ToString();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return base.ToString();
|
var strings = this.Select(x => x as string ?? x?.ToString());
|
||||||
|
return string.Join(", ", strings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace WireMock.Extensions;
|
||||||
|
|
||||||
|
internal static class EnumExtensions
|
||||||
|
{
|
||||||
|
public static string GetFullyQualifiedEnumValue<T>(this T enumValue)
|
||||||
|
where T : struct, IConvertible
|
||||||
|
{
|
||||||
|
var type = typeof(T);
|
||||||
|
|
||||||
|
if (!type.GetTypeInfo().IsEnum)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("T must be an enum");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{type.Namespace}.{type.Name}.{enumValue}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
@@ -8,6 +7,7 @@ using WireMock.Owin;
|
|||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock;
|
namespace WireMock;
|
||||||
|
|
||||||
@@ -18,9 +18,10 @@ public class MappingBuilder : IMappingBuilder
|
|||||||
{
|
{
|
||||||
private readonly WireMockServerSettings _settings;
|
private readonly WireMockServerSettings _settings;
|
||||||
private readonly IWireMockMiddlewareOptions _options;
|
private readonly IWireMockMiddlewareOptions _options;
|
||||||
|
|
||||||
private readonly MappingConverter _mappingConverter;
|
private readonly MappingConverter _mappingConverter;
|
||||||
private readonly MappingToFileSaver _mappingToFileSaver;
|
private readonly MappingToFileSaver _mappingToFileSaver;
|
||||||
|
private readonly IGuidUtils _guidUtils;
|
||||||
|
private readonly IDateTimeUtils _dateTimeUtils;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a MappingBuilder
|
/// Create a MappingBuilder
|
||||||
@@ -34,25 +35,32 @@ public class MappingBuilder : IMappingBuilder
|
|||||||
var matcherMapper = new MatcherMapper(_settings);
|
var matcherMapper = new MatcherMapper(_settings);
|
||||||
_mappingConverter = new MappingConverter(matcherMapper);
|
_mappingConverter = new MappingConverter(matcherMapper);
|
||||||
_mappingToFileSaver = new MappingToFileSaver(_settings, _mappingConverter);
|
_mappingToFileSaver = new MappingToFileSaver(_settings, _mappingConverter);
|
||||||
|
|
||||||
|
_guidUtils = new GuidUtils();
|
||||||
|
_dateTimeUtils = new DateTimeUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal MappingBuilder(
|
internal MappingBuilder(
|
||||||
WireMockServerSettings settings,
|
WireMockServerSettings settings,
|
||||||
IWireMockMiddlewareOptions options,
|
IWireMockMiddlewareOptions options,
|
||||||
MappingConverter mappingConverter,
|
MappingConverter mappingConverter,
|
||||||
MappingToFileSaver mappingToFileSaver
|
MappingToFileSaver mappingToFileSaver,
|
||||||
|
IGuidUtils guidUtils,
|
||||||
|
IDateTimeUtils dateTimeUtils
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_settings = Guard.NotNull(settings);
|
_settings = Guard.NotNull(settings);
|
||||||
_options = Guard.NotNull(options);
|
_options = Guard.NotNull(options);
|
||||||
_mappingConverter = Guard.NotNull(mappingConverter);
|
_mappingConverter = Guard.NotNull(mappingConverter);
|
||||||
_mappingToFileSaver = Guard.NotNull(mappingToFileSaver);
|
_mappingToFileSaver = Guard.NotNull(mappingToFileSaver);
|
||||||
|
_guidUtils = Guard.NotNull(guidUtils);
|
||||||
|
_dateTimeUtils = Guard.NotNull(dateTimeUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRespondWithAProvider Given(IRequestMatcher requestMatcher, bool saveToFile = false)
|
public IRespondWithAProvider Given(IRequestMatcher requestMatcher, bool saveToFile = false)
|
||||||
{
|
{
|
||||||
return new RespondWithAProvider(RegisterMapping, Guard.NotNull(requestMatcher), _settings, saveToFile);
|
return new RespondWithAProvider(RegisterMapping, Guard.NotNull(requestMatcher), _settings, _guidUtils, _dateTimeUtils, saveToFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -95,7 +103,7 @@ public class MappingBuilder : IMappingBuilder
|
|||||||
// Check a mapping exists with the same Guid. If so, update the datetime and replace it.
|
// Check a mapping exists with the same Guid. If so, update the datetime and replace it.
|
||||||
if (_options.Mappings.ContainsKey(mapping.Guid))
|
if (_options.Mappings.ContainsKey(mapping.Guid))
|
||||||
{
|
{
|
||||||
mapping.UpdatedAt = DateTime.UtcNow;
|
mapping.UpdatedAt = _dateTimeUtils.UtcNow;
|
||||||
_options.Mappings[mapping.Guid] = mapping;
|
_options.Mappings[mapping.Guid] = mapping;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,85 +1,83 @@
|
|||||||
using JetBrains.Annotations;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders
|
namespace WireMock.RequestBuilders;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CookieRequestBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface ICookiesRequestBuilder : IParamsRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The CookieRequestBuilder interface.
|
/// WithCookie: matching based on name, pattern and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ICookiesRequestBuilder : IParamsRequestBuilder
|
/// <param name="name">The name.</param>
|
||||||
{
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <summary>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// WithCookie: matching based on name, pattern and matchBehaviour.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </summary>
|
IRequestBuilder WithCookie(string name, string pattern, MatchBehaviour matchBehaviour);
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="pattern">The pattern.</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithCookie([NotNull] string name, string pattern, MatchBehaviour matchBehaviour);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on name, pattern, ignoreCase and matchBehaviour.
|
/// WithCookie: matching based on name, pattern, ignoreCase and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on name, patterns and matchBehaviour.
|
/// WithCookie: matching based on name, patterns and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, string[] patterns, MatchBehaviour matchBehaviour);
|
IRequestBuilder WithCookie(string name, string[] patterns, MatchBehaviour matchBehaviour);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on name, patterns, ignoreCase and matchBehaviour.
|
/// WithCookie: matching based on name, patterns, ignoreCase and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithCookie(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on name and IStringMatcher[].
|
/// WithCookie: matching based on name and IStringMatcher[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithCookie(string name, params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on name, ignoreCase and IStringMatcher[].
|
/// WithCookie: matching based on name, ignoreCase and IStringMatcher[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the cookie-keys.</param>
|
/// <param name="ignoreCase">Ignore the case from the cookie-keys.</param>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, bool ignoreCase, [NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithCookie(string name, bool ignoreCase, params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on name, ignoreCase, matchBehaviour and IStringMatcher[].
|
/// WithCookie: matching based on name, ignoreCase, matchBehaviour and IStringMatcher[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the cookie-keys.</param>
|
/// <param name="ignoreCase">Ignore the case from the cookie-keys.</param>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, bool ignoreCase, MatchBehaviour matchBehaviour, [NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithCookie(string name, bool ignoreCase, MatchBehaviour matchBehaviour, params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithCookie: matching based on functions.
|
/// WithCookie: matching based on functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="funcs">The cookies funcs.</param>
|
/// <param name="funcs">The cookies funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] params Func<IDictionary<string, string>, bool>[] funcs);
|
IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
|
using WireMock.Constants;
|
||||||
|
using WireMock.Extensions;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
@@ -16,6 +19,8 @@ namespace WireMock.Serialization;
|
|||||||
|
|
||||||
internal class MappingConverter
|
internal class MappingConverter
|
||||||
{
|
{
|
||||||
|
private static readonly string AcceptOnMatch = MatchBehaviour.AcceptOnMatch.GetFullyQualifiedEnumValue();
|
||||||
|
|
||||||
private readonly MatcherMapper _mapper;
|
private readonly MatcherMapper _mapper;
|
||||||
|
|
||||||
public MappingConverter(MatcherMapper mapper)
|
public MappingConverter(MatcherMapper mapper)
|
||||||
@@ -23,6 +28,133 @@ internal class MappingConverter
|
|||||||
_mapper = Guard.NotNull(mapper);
|
_mapper = Guard.NotNull(mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ToCSharpCode(IMapping mapping, MappingConverterSettings? settings = null)
|
||||||
|
{
|
||||||
|
settings ??= new MappingConverterSettings();
|
||||||
|
|
||||||
|
var request = (Request)mapping.RequestMatcher;
|
||||||
|
var response = (Response)mapping.Provider;
|
||||||
|
|
||||||
|
var clientIPMatcher = request.GetRequestMessageMatcher<RequestMessageClientIPMatcher>();
|
||||||
|
var pathMatcher = request.GetRequestMessageMatcher<RequestMessagePathMatcher>();
|
||||||
|
var urlMatcher = request.GetRequestMessageMatcher<RequestMessageUrlMatcher>();
|
||||||
|
var headerMatchers = request.GetRequestMessageMatchers<RequestMessageHeaderMatcher>();
|
||||||
|
var cookieMatchers = request.GetRequestMessageMatchers<RequestMessageCookieMatcher>();
|
||||||
|
var paramsMatchers = request.GetRequestMessageMatchers<RequestMessageParamMatcher>();
|
||||||
|
var methodMatcher = request.GetRequestMessageMatcher<RequestMessageMethodMatcher>();
|
||||||
|
var bodyMatcher = request.GetRequestMessageMatcher<RequestMessageBodyMatcher>();
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (settings.ConverterType == MappingConverterType.Server)
|
||||||
|
{
|
||||||
|
if (settings.AddStart)
|
||||||
|
{
|
||||||
|
sb.AppendLine("var server = WireMockServer.Start();");
|
||||||
|
}
|
||||||
|
sb.AppendLine("server");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (settings.AddStart)
|
||||||
|
{
|
||||||
|
sb.AppendLine("var builder = new MappingBuilder();");
|
||||||
|
}
|
||||||
|
sb.AppendLine("builder");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request
|
||||||
|
sb.AppendLine(" .Given(Request.Create()");
|
||||||
|
sb.AppendLine($" .UsingMethod({To1Or2Or3Arguments(methodMatcher?.MatchBehaviour, methodMatcher?.MatchOperator, methodMatcher?.Methods, HttpRequestMethod.GET)})");
|
||||||
|
|
||||||
|
if (pathMatcher is { Matchers: { } })
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithPath({To1Or2Arguments(pathMatcher.MatchOperator, pathMatcher.Matchers)})");
|
||||||
|
}
|
||||||
|
else if (urlMatcher is { Matchers: { } })
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithUrl({To1Or2Arguments(urlMatcher.MatchOperator, urlMatcher.Matchers)})");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var paramsMatcher in paramsMatchers)
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithParam({To1Or2Or3Arguments(paramsMatcher.Key, paramsMatcher.MatchBehaviour, paramsMatcher.Matchers!)})");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientIPMatcher is { Matchers: { } })
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithClientIP({ToValueArguments(GetStringArray(clientIPMatcher.Matchers))})");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var headerMatcher in headerMatchers.Where(h => h.Matchers is { }))
|
||||||
|
{
|
||||||
|
var headerBuilder = new StringBuilder($"\"{headerMatcher.Name}\", {ToValueArguments(GetStringArray(headerMatcher.Matchers!))}, true");
|
||||||
|
if (headerMatcher.MatchOperator != MatchOperator.Or)
|
||||||
|
{
|
||||||
|
headerBuilder.Append($"{AcceptOnMatch}, {headerMatcher.MatchOperator.GetFullyQualifiedEnumValue()}");
|
||||||
|
}
|
||||||
|
sb.AppendLine($" .WithHeader({headerBuilder})");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var cookieMatcher in cookieMatchers.Where(h => h.Matchers is { }))
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithCookie(\"{cookieMatcher.Name}\", {ToValueArguments(GetStringArray(cookieMatcher.Matchers!))}, true)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bodyMatcher is { Matchers: { } })
|
||||||
|
{
|
||||||
|
var wildcardMatcher = bodyMatcher.Matchers.OfType<WildcardMatcher>().FirstOrDefault();
|
||||||
|
if (wildcardMatcher is { } && wildcardMatcher.GetPatterns().Any())
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithBody({GetString(wildcardMatcher)})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine(@" )");
|
||||||
|
|
||||||
|
// Guid
|
||||||
|
sb.AppendLine($" .WithGuid(\"{mapping.Guid}\")");
|
||||||
|
|
||||||
|
// Response
|
||||||
|
sb.AppendLine(" .RespondWith(Response.Create()");
|
||||||
|
|
||||||
|
if (response.ResponseMessage.Headers is { })
|
||||||
|
{
|
||||||
|
foreach (var header in response.ResponseMessage.Headers)
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithHeader(\"{header.Key})\", {ToValueArguments(header.Value.ToArray())})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.ResponseMessage.BodyData is { })
|
||||||
|
{
|
||||||
|
switch (response.ResponseMessage.BodyData.DetectedBodyType)
|
||||||
|
{
|
||||||
|
case BodyType.String:
|
||||||
|
sb.AppendLine($" .WithBody(\"{response.ResponseMessage.BodyData.BodyAsString}\")");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.Delay is { })
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithDelay({response.Delay.Value.TotalMilliseconds})");
|
||||||
|
}
|
||||||
|
else if (response.MinimumDelayMilliseconds > 0 && response.MaximumDelayMilliseconds > 0)
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WithRandomDelay({response.MinimumDelayMilliseconds}, {response.MaximumDelayMilliseconds})");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.UseTransformer)
|
||||||
|
{
|
||||||
|
var transformerArgs = response.TransformerType != TransformerType.Handlebars ? response.TransformerType.GetFullyQualifiedEnumValue() : string.Empty;
|
||||||
|
sb.AppendLine($" .WithTransformer({transformerArgs})");
|
||||||
|
}
|
||||||
|
sb.AppendLine(@" );");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public MappingModel ToMappingModel(IMapping mapping)
|
public MappingModel ToMappingModel(IMapping mapping)
|
||||||
{
|
{
|
||||||
var request = (Request)mapping.RequestMatcher;
|
var request = (Request)mapping.RequestMatcher;
|
||||||
@@ -237,6 +369,64 @@ internal class MappingConverter
|
|||||||
return mappingModel;
|
return mappingModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetString(IStringMatcher stringMatcher)
|
||||||
|
{
|
||||||
|
return stringMatcher.GetPatterns().Select(p => $"\"{p.GetPattern()}\"").First();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string[] GetStringArray(IReadOnlyList<IStringMatcher> stringMatchers)
|
||||||
|
{
|
||||||
|
return stringMatchers.SelectMany(m => m.GetPatterns()).Select(p => p.GetPattern()).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string To1Or2Or3Arguments(string key, MatchBehaviour? matchBehaviour, IReadOnlyList<IStringMatcher> matchers)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder($"\"{key}\", ");
|
||||||
|
|
||||||
|
if (matchBehaviour.HasValue && matchBehaviour != MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
sb.AppendFormat("{0}, ", matchBehaviour.Value.GetFullyQualifiedEnumValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendFormat("{0}", ToValueArguments(GetStringArray(matchers), string.Empty));
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string To1Or2Or3Arguments(MatchBehaviour? matchBehaviour, MatchOperator? matchOperator, string[]? values, string defaultValue)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (matchBehaviour.HasValue && matchBehaviour != MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
sb.AppendFormat("{0}, ", matchBehaviour.Value.GetFullyQualifiedEnumValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return To1Or2Arguments(matchOperator, values, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string To1Or2Arguments(MatchOperator? matchOperator, IReadOnlyList<IStringMatcher> matchers)
|
||||||
|
{
|
||||||
|
return To1Or2Arguments(matchOperator, GetStringArray(matchers), string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string To1Or2Arguments(MatchOperator? matchOperator, string[]? values, string defaultValue)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (matchOperator.HasValue && matchOperator != MatchOperator.Or)
|
||||||
|
{
|
||||||
|
sb.AppendFormat("{0}, ", matchOperator.Value.GetFullyQualifiedEnumValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.Append(ToValueArguments(values, defaultValue)).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ToValueArguments(string[]? values, string defaultValue = "")
|
||||||
|
{
|
||||||
|
return values is { } ? string.Join(", ", values.Select(v => $"\"{v}\"")) : $"\"{defaultValue}\"";
|
||||||
|
}
|
||||||
|
|
||||||
private static WebProxyModel? MapWebProxy(WebProxySettings? settings)
|
private static WebProxyModel? MapWebProxy(WebProxySettings? settings)
|
||||||
{
|
{
|
||||||
return settings != null ? new WebProxyModel
|
return settings != null ? new WebProxyModel
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using WireMock.Types;
|
||||||
|
|
||||||
|
namespace WireMock.Serialization;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// MappingConverterSettings
|
||||||
|
/// </summary>
|
||||||
|
public class MappingConverterSettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Use 'Server' or 'Builder'.
|
||||||
|
///
|
||||||
|
/// Default is Server
|
||||||
|
/// </summary>
|
||||||
|
public MappingConverterType ConverterType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add "var server = WireMockServer.Start();"
|
||||||
|
/// or
|
||||||
|
/// Add "var builder = new MappingBuilder();"
|
||||||
|
///
|
||||||
|
/// Default it's false.
|
||||||
|
/// </summary>
|
||||||
|
public bool AddStart { get; set; }
|
||||||
|
}
|
||||||
@@ -28,9 +28,8 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
|||||||
private readonly RegistrationCallback _registrationCallback;
|
private readonly RegistrationCallback _registrationCallback;
|
||||||
private readonly IRequestMatcher _requestMatcher;
|
private readonly IRequestMatcher _requestMatcher;
|
||||||
private readonly WireMockServerSettings _settings;
|
private readonly WireMockServerSettings _settings;
|
||||||
|
private readonly IDateTimeUtils _dateTimeUtils;
|
||||||
private readonly bool _saveToFile;
|
private readonly bool _saveToFile;
|
||||||
private readonly IGuidUtils _guidUtils = new GuidUtils();
|
|
||||||
private readonly IDateTimeUtils _dateTimeUtils = new DateTimeUtils();
|
|
||||||
|
|
||||||
private bool _useWebhookFireAndForget;
|
private bool _useWebhookFireAndForget;
|
||||||
|
|
||||||
@@ -46,20 +45,25 @@ internal class RespondWithAProvider : IRespondWithAProvider
|
|||||||
/// <param name="registrationCallback">The registration callback.</param>
|
/// <param name="registrationCallback">The registration callback.</param>
|
||||||
/// <param name="requestMatcher">The request matcher.</param>
|
/// <param name="requestMatcher">The request matcher.</param>
|
||||||
/// <param name="settings">The WireMockServerSettings.</param>
|
/// <param name="settings">The WireMockServerSettings.</param>
|
||||||
|
/// <param name="guidUtils">GuidUtils to make unit testing possible.</param>
|
||||||
|
/// <param name="dateTimeUtils">DateTimeUtils to make unit testing possible.</param>
|
||||||
/// <param name="saveToFile">Optional boolean to indicate if this mapping should be saved as static mapping file.</param>
|
/// <param name="saveToFile">Optional boolean to indicate if this mapping should be saved as static mapping file.</param>
|
||||||
public RespondWithAProvider(
|
public RespondWithAProvider(
|
||||||
RegistrationCallback registrationCallback,
|
RegistrationCallback registrationCallback,
|
||||||
IRequestMatcher requestMatcher,
|
IRequestMatcher requestMatcher,
|
||||||
WireMockServerSettings settings,
|
WireMockServerSettings settings,
|
||||||
|
IGuidUtils guidUtils,
|
||||||
|
IDateTimeUtils dateTimeUtils,
|
||||||
bool saveToFile = false
|
bool saveToFile = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_registrationCallback = Guard.NotNull(registrationCallback);
|
_registrationCallback = Guard.NotNull(registrationCallback);
|
||||||
_requestMatcher = Guard.NotNull(requestMatcher);
|
_requestMatcher = Guard.NotNull(requestMatcher);
|
||||||
_settings = Guard.NotNull(settings);
|
_settings = Guard.NotNull(settings);
|
||||||
_saveToFile = Guard.NotNull(saveToFile);
|
_dateTimeUtils = Guard.NotNull(dateTimeUtils);
|
||||||
|
_saveToFile = saveToFile;
|
||||||
|
|
||||||
Guid = _guidUtils.NewGuid();
|
Guid = guidUtils.NewGuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ using WireMock.ResponseProviders;
|
|||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.Server;
|
namespace WireMock.Server;
|
||||||
|
|
||||||
@@ -39,6 +40,8 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
private readonly MatcherMapper _matcherMapper;
|
private readonly MatcherMapper _matcherMapper;
|
||||||
private readonly MappingToFileSaver _mappingToFileSaver;
|
private readonly MappingToFileSaver _mappingToFileSaver;
|
||||||
private readonly MappingBuilder _mappingBuilder;
|
private readonly MappingBuilder _mappingBuilder;
|
||||||
|
private readonly IGuidUtils _guidUtils = new GuidUtils();
|
||||||
|
private readonly IDateTimeUtils _dateTimeUtils = new DateTimeUtils();
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServer.IsStarted" />
|
/// <inheritdoc cref="IWireMockServer.IsStarted" />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
@@ -315,7 +318,14 @@ public partial class WireMockServer : IWireMockServer
|
|||||||
_matcherMapper = new MatcherMapper(_settings);
|
_matcherMapper = new MatcherMapper(_settings);
|
||||||
_mappingConverter = new MappingConverter(_matcherMapper);
|
_mappingConverter = new MappingConverter(_matcherMapper);
|
||||||
_mappingToFileSaver = new MappingToFileSaver(_settings, _mappingConverter);
|
_mappingToFileSaver = new MappingToFileSaver(_settings, _mappingConverter);
|
||||||
_mappingBuilder = new MappingBuilder(settings, _options, _mappingConverter, _mappingToFileSaver);
|
_mappingBuilder = new MappingBuilder(
|
||||||
|
settings,
|
||||||
|
_options,
|
||||||
|
_mappingConverter,
|
||||||
|
_mappingToFileSaver,
|
||||||
|
_guidUtils,
|
||||||
|
_dateTimeUtils
|
||||||
|
);
|
||||||
|
|
||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
_options.AdditionalServiceRegistration = _settings.AdditionalServiceRegistration;
|
_options.AdditionalServiceRegistration = _settings.AdditionalServiceRegistration;
|
||||||
|
|||||||
@@ -177,13 +177,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Handlebars.Net.Helpers" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers" Version="2.3.12" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.3.12" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.Humanizer" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers.Humanizer" Version="2.3.12" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.Json" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers.Json" Version="2.3.12" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.3.12" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.3.12" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.3.11" />
|
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.3.12" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<!--<DelaySign>true</DelaySign>-->
|
<!--<DelaySign>true</DelaySign>-->
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
|
||||||
|
"root": true,
|
||||||
|
|
||||||
|
"dependentFileProviders": {
|
||||||
|
"add": {
|
||||||
|
"addedExtension": {},
|
||||||
|
"pathSegment": {},
|
||||||
|
"fileSuffixToExtension": {
|
||||||
|
"add": {
|
||||||
|
".verified.txt": [
|
||||||
|
".cs"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,40 +5,39 @@ using FluentAssertions;
|
|||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Http
|
namespace WireMock.Net.Tests.Http;
|
||||||
|
|
||||||
|
public class ByteArrayContentHelperTests
|
||||||
{
|
{
|
||||||
public class ByteArrayContentHelperTests
|
[Fact]
|
||||||
|
public async Task ByteArrayContentHelperTests_Create_WithNullContentType()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Arrange
|
||||||
public async Task ByteArrayContentHelperTests_Create_WithNullContentType()
|
var content = Encoding.UTF8.GetBytes("test");
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var content = Encoding.UTF8.GetBytes("test");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = ByteArrayContentHelper.Create(content, null);
|
var result = ByteArrayContentHelper.Create(content, null);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Headers.ContentType.Should().BeNull();
|
result.Headers.ContentType.Should().BeNull();
|
||||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("application/octet-stream", "application/octet-stream")]
|
|
||||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
|
||||||
[InlineData("multipart/form-data; boundary=------------------------x", "multipart/form-data; boundary=------------------------x")]
|
|
||||||
public async Task ByteArrayContentHelperTests_Create(string test, string expected)
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var content = Encoding.UTF8.GetBytes("test");
|
|
||||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = ByteArrayContentHelper.Create(content, contentType);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
|
||||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("application/octet-stream", "application/octet-stream")]
|
||||||
|
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||||
|
[InlineData("multipart/form-data; boundary=------------------------x", "multipart/form-data; boundary=------------------------x")]
|
||||||
|
public async Task ByteArrayContentHelperTests_Create(string test, string expected)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var content = Encoding.UTF8.GetBytes("test");
|
||||||
|
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = ByteArrayContentHelper.Create(content, contentType);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||||
|
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,164 +1,163 @@
|
|||||||
using NFluent;
|
using NFluent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Http
|
namespace WireMock.Net.Tests.Http;
|
||||||
|
|
||||||
|
public class HttpRequestMessageHelperTests
|
||||||
{
|
{
|
||||||
public class HttpRequestMessageHelperTests
|
private const string ClientIp = "::1";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void HttpRequestMessageHelper_Create()
|
||||||
{
|
{
|
||||||
private const string ClientIp = "::1";
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "x", new[] { "value-1" } } };
|
||||||
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, headers);
|
||||||
|
|
||||||
[Fact]
|
// Act
|
||||||
public void HttpRequestMessageHelper_Create()
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(message.Headers.GetValues("x")).ContainsExactly("value-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task HttpRequestMessageHelper_Create_Bytes()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsBytes = Encoding.UTF8.GetBytes("hi"),
|
||||||
var headers = new Dictionary<string, string[]> { { "x", new[] { "value-1" } } };
|
DetectedBodyType = BodyType.Bytes
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, headers);
|
};
|
||||||
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(message.Headers.GetValues("x")).ContainsExactly("value-1");
|
Check.That(await message.Content.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HttpRequestMessageHelper_Create_Bytes()
|
public async Task HttpRequestMessageHelper_Create_Json()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsJson = new { x = 42 },
|
||||||
var body = new BodyData
|
DetectedBodyType = BodyType.Json
|
||||||
{
|
};
|
||||||
BodyAsBytes = Encoding.UTF8.GetBytes("hi"),
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||||
DetectedBodyType = BodyType.Bytes
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(await message.Content.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HttpRequestMessageHelper_Create_Json()
|
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json" } } };
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsJson = new { x = 42 },
|
||||||
var body = new BodyData
|
DetectedBodyType = BodyType.Json
|
||||||
{
|
};
|
||||||
BodyAsJson = new { x = 42 },
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
||||||
DetectedBodyType = BodyType.Json
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||||
}
|
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson()
|
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson_UTF8()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json; charset=utf-8" } } };
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsJson = new { x = 42 },
|
||||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json" } } };
|
DetectedBodyType = BodyType.Json
|
||||||
var body = new BodyData
|
};
|
||||||
{
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
||||||
BodyAsJson = new { x = 42 },
|
|
||||||
DetectedBodyType = BodyType.Json
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json");
|
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson_UTF8()
|
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsString = "<xml>hello</xml>",
|
||||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json; charset=utf-8" } } };
|
DetectedBodyType = BodyType.String
|
||||||
var body = new BodyData
|
};
|
||||||
{
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||||
BodyAsJson = new { x = 42 },
|
|
||||||
DetectedBodyType = BodyType.Json
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml");
|
||||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml()
|
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_UTF8()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=UTF-8" } } };
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsString = "<xml>hello</xml>",
|
||||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
|
DetectedBodyType = BodyType.String
|
||||||
var body = new BodyData
|
};
|
||||||
{
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||||
BodyAsString = "<xml>hello</xml>",
|
|
||||||
DetectedBodyType = BodyType.String
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml");
|
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_UTF8()
|
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_ASCII()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=Ascii" } } };
|
||||||
|
var body = new BodyData
|
||||||
{
|
{
|
||||||
// Assign
|
BodyAsString = "<xml>hello</xml>",
|
||||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=UTF-8" } } };
|
DetectedBodyType = BodyType.String
|
||||||
var body = new BodyData
|
};
|
||||||
{
|
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
||||||
BodyAsString = "<xml>hello</xml>",
|
|
||||||
DetectedBodyType = BodyType.String
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=UTF-8");
|
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=Ascii");
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_ASCII()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=Ascii" } } };
|
|
||||||
var body = new BodyData
|
|
||||||
{
|
|
||||||
BodyAsString = "<xml>hello</xml>",
|
|
||||||
DetectedBodyType = BodyType.String
|
|
||||||
};
|
|
||||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=Ascii");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,39 +1,38 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Http
|
namespace WireMock.Net.Tests.Http;
|
||||||
|
|
||||||
|
public class StringContentHelperTests
|
||||||
{
|
{
|
||||||
public class StringContentHelperTests
|
[Fact]
|
||||||
|
public void StringContentHelper_Create_WithNullContentType()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void StringContentHelper_Create_WithNullContentType()
|
var result = StringContentHelper.Create("test", null);
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var result = StringContentHelper.Create("test", null);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Headers.ContentType.Should().BeNull();
|
result.Headers.ContentType.Should().BeNull();
|
||||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("application/json", "application/json")]
|
|
||||||
[InlineData("application/soap+xml", "application/soap+xml")]
|
|
||||||
[InlineData("application/soap+xml;charset=UTF-8", "application/soap+xml; charset=UTF-8")]
|
|
||||||
[InlineData("application/soap+xml;charset=UTF-8;action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"", "application/soap+xml; charset=UTF-8; action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"")]
|
|
||||||
public void StringContentHelper_Create(string test, string expected)
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var contentType = MediaTypeHeaderValue.Parse(test);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = StringContentHelper.Create("test", contentType);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
|
||||||
result.ReadAsStringAsync().Result.Should().Be("test");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("application/json", "application/json")]
|
||||||
|
[InlineData("application/soap+xml", "application/soap+xml")]
|
||||||
|
[InlineData("application/soap+xml;charset=UTF-8", "application/soap+xml; charset=UTF-8")]
|
||||||
|
[InlineData("application/soap+xml;charset=UTF-8;action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"", "application/soap+xml; charset=UTF-8; action=\"http://myCompany.Customer.Contract/ICustomerService/GetSomeConfiguration\"")]
|
||||||
|
public void StringContentHelper_Create(string test, string expected)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var contentType = MediaTypeHeaderValue.Parse(test);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = StringContentHelper.Create("test", contentType);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||||
|
result.ReadAsStringAsync().Result.Should().Be("test");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
Guid: 41372914-1838-4c67-916b-b9aacdd096ce,
|
||||||
|
UpdatedAt: 2023-01-14 15:16:17,
|
||||||
|
Request: {
|
||||||
|
Path: {
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: WildcardMatcher,
|
||||||
|
Pattern: /foo,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Methods: [
|
||||||
|
GET
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Response: {
|
||||||
|
BodyDestination: SameAsSource,
|
||||||
|
Body: { msg: "Hello world!"}
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
Guid: 41372914-1838-4c67-916b-b9aacdd096ce,
|
||||||
|
UpdatedAt: 2023-01-14T15:16:17,
|
||||||
|
Request: {
|
||||||
|
Path: {
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: WildcardMatcher,
|
||||||
|
Pattern: /foo,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Methods: [
|
||||||
|
GET
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Response: {
|
||||||
|
BodyDestination: SameAsSource,
|
||||||
|
Body: { msg: "Hello world!"}
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
using FluentAssertions;
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using VerifyTests;
|
||||||
|
using VerifyXunit;
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
@@ -7,13 +12,17 @@ using WireMock.RequestBuilders;
|
|||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests;
|
namespace WireMock.Net.Tests;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
public class MappingBuilderTests
|
public class MappingBuilderTests
|
||||||
{
|
{
|
||||||
private static readonly string MappingGuid = "41372914-1838-4c67-916b-b9aacdd096ce";
|
private static readonly Guid NewGuid = new("98fae52e-76df-47d9-876f-2ee32e931d9b");
|
||||||
|
private const string MappingGuid = "41372914-1838-4c67-916b-b9aacdd096ce";
|
||||||
|
private static readonly DateTime UtcNow = new(2023, 1, 14, 15, 16, 17);
|
||||||
|
|
||||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock;
|
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock;
|
||||||
|
|
||||||
@@ -23,6 +32,12 @@ public class MappingBuilderTests
|
|||||||
{
|
{
|
||||||
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||||
|
|
||||||
|
var guidUtilsMock = new Mock<IGuidUtils>();
|
||||||
|
guidUtilsMock.Setup(g => g.NewGuid()).Returns(NewGuid);
|
||||||
|
|
||||||
|
var dateTimeUtilsMock = new Mock<IDateTimeUtils>();
|
||||||
|
dateTimeUtilsMock.SetupGet(d => d.UtcNow).Returns(UtcNow);
|
||||||
|
|
||||||
var settings = new WireMockServerSettings
|
var settings = new WireMockServerSettings
|
||||||
{
|
{
|
||||||
FileSystemHandler = _fileSystemHandlerMock.Object,
|
FileSystemHandler = _fileSystemHandlerMock.Object,
|
||||||
@@ -33,7 +48,14 @@ public class MappingBuilderTests
|
|||||||
var mappingConverter = new MappingConverter(matcherMapper);
|
var mappingConverter = new MappingConverter(matcherMapper);
|
||||||
var mappingToFileSaver = new MappingToFileSaver(settings, mappingConverter);
|
var mappingToFileSaver = new MappingToFileSaver(settings, mappingConverter);
|
||||||
|
|
||||||
_sut = new MappingBuilder(settings, options, mappingConverter, mappingToFileSaver);
|
_sut = new MappingBuilder(
|
||||||
|
settings,
|
||||||
|
options,
|
||||||
|
mappingConverter,
|
||||||
|
mappingToFileSaver,
|
||||||
|
guidUtilsMock.Object,
|
||||||
|
dateTimeUtilsMock.Object
|
||||||
|
);
|
||||||
|
|
||||||
_sut.Given(Request.Create()
|
_sut.Given(Request.Create()
|
||||||
.WithPath("/foo")
|
.WithPath("/foo")
|
||||||
@@ -45,24 +67,31 @@ public class MappingBuilderTests
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ModuleInitializer]
|
||||||
|
public static void ModuleInitializer()
|
||||||
|
{
|
||||||
|
VerifierSettings.DontScrubGuids();
|
||||||
|
VerifierSettings.DontScrubDateTimes();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetMappings()
|
public Task GetMappings()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var mappings = _sut.GetMappings();
|
var mappings = _sut.GetMappings();
|
||||||
|
|
||||||
// Assert
|
// Verify
|
||||||
mappings.Should().HaveCount(1);
|
return Verifier.Verify(mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToJson()
|
public Task ToJson()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var json = _sut.ToJson();
|
var json = _sut.ToJson();
|
||||||
|
|
||||||
// Assert
|
// Verify
|
||||||
json.Should().NotBeEmpty();
|
return Verifier.VerifyJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -133,4 +162,5 @@ public class MappingBuilderTests
|
|||||||
_fileSystemHandlerMock.Verify(fs => fs.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
_fileSystemHandlerMock.Verify(fs => fs.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||||
_fileSystemHandlerMock.VerifyNoOtherCalls();
|
_fileSystemHandlerMock.VerifyNoOtherCalls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -2,91 +2,90 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class CSharpCodeMatcherTests
|
||||||
{
|
{
|
||||||
public class CSharpCodeMatcherTests
|
[Fact]
|
||||||
|
public void CSharpCodeMatcher_For_String_SinglePattern_IsMatch_Positive()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void CSharpCodeMatcher_For_String_SinglePattern_IsMatch_Positive()
|
string input = "x";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CSharpCodeMatcher_For_String_IsMatch_Negative()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string input = "y";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CSharpCodeMatcher_For_String_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string input = "x";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new CSharpCodeMatcher(MatchBehaviour.RejectOnMatch, MatchOperator.Or, "return it == \"x\";");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CSharpCodeMatcher_For_Object_IsMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var input = new
|
||||||
{
|
{
|
||||||
// Assign
|
Id = 9,
|
||||||
string input = "x";
|
Name = "Test"
|
||||||
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
var matcher = new CSharpCodeMatcher("return it.Id > 1 && it.Name == \"Test\";");
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
Assert.Equal(1.0, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CSharpCodeMatcher_For_String_IsMatch_Negative()
|
public void CSharpCodeMatcher_GetName()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
string input = "y";
|
var matcher = new CSharpCodeMatcher("x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new CSharpCodeMatcher("return it == \"x\";");
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
Check.That(name).Equals("CSharpCodeMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CSharpCodeMatcher_For_String_IsMatch_RejectOnMatch()
|
public void CSharpCodeMatcher_GetPatterns()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
string input = "x";
|
var matcher = new CSharpCodeMatcher("x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new CSharpCodeMatcher(MatchBehaviour.RejectOnMatch, MatchOperator.Or, "return it == \"x\";");
|
var patterns = matcher.GetPatterns();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
Check.That(patterns).ContainsExactly("x");
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CSharpCodeMatcher_For_Object_IsMatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var input = new
|
|
||||||
{
|
|
||||||
Id = 9,
|
|
||||||
Name = "Test"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var matcher = new CSharpCodeMatcher("return it.Id > 1 && it.Name == \"Test\";");
|
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CSharpCodeMatcher_GetName()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new CSharpCodeMatcher("x");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
string name = matcher.Name;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(name).Equals("CSharpCodeMatcher");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CSharpCodeMatcher_GetPatterns()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new CSharpCodeMatcher("x");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var patterns = matcher.GetPatterns();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(patterns).ContainsExactly("x");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,59 +1,57 @@
|
|||||||
using AnyOfTypes;
|
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class ContentTypeMatcherTests
|
||||||
{
|
{
|
||||||
public class ContentTypeMatcherTests
|
[Theory]
|
||||||
|
[InlineData("application/json")]
|
||||||
|
[InlineData("application/json; charset=ascii")]
|
||||||
|
[InlineData("application/json; charset=utf-8")]
|
||||||
|
[InlineData("application/json; charset=UTF-8")]
|
||||||
|
public void ContentTypeMatcher_IsMatchWithIgnoreCaseFalse_Positive(string contentType)
|
||||||
{
|
{
|
||||||
[Theory]
|
var matcher = new ContentTypeMatcher("application/json");
|
||||||
[InlineData("application/json")]
|
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
||||||
[InlineData("application/json; charset=ascii")]
|
}
|
||||||
[InlineData("application/json; charset=utf-8")]
|
|
||||||
[InlineData("application/json; charset=UTF-8")]
|
|
||||||
public void ContentTypeMatcher_IsMatchWithIgnoreCaseFalse_Positive(string contentType)
|
|
||||||
{
|
|
||||||
var matcher = new ContentTypeMatcher("application/json");
|
|
||||||
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("application/json")]
|
[InlineData("application/json")]
|
||||||
[InlineData("application/JSON")]
|
[InlineData("application/JSON")]
|
||||||
[InlineData("application/json; CharSet=ascii")]
|
[InlineData("application/json; CharSet=ascii")]
|
||||||
[InlineData("application/json; charset=utf-8")]
|
[InlineData("application/json; charset=utf-8")]
|
||||||
[InlineData("application/json; charset=UTF-8")]
|
[InlineData("application/json; charset=UTF-8")]
|
||||||
public void ContentTypeMatcher_IsMatchWithIgnoreCaseTrue_Positive(string contentType)
|
public void ContentTypeMatcher_IsMatchWithIgnoreCaseTrue_Positive(string contentType)
|
||||||
{
|
{
|
||||||
var matcher = new ContentTypeMatcher("application/json", true);
|
var matcher = new ContentTypeMatcher("application/json", true);
|
||||||
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
Check.That(matcher.IsMatch(contentType)).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ContentTypeMatcher_GetName()
|
public void ContentTypeMatcher_GetName()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new ContentTypeMatcher("x");
|
var matcher = new ContentTypeMatcher("x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.Name;
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("ContentTypeMatcher");
|
Check.That(name).Equals("ContentTypeMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ContentTypeMatcher_GetPatterns()
|
public void ContentTypeMatcher_GetPatterns()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new ContentTypeMatcher("x");
|
var matcher = new ContentTypeMatcher("x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var patterns = matcher.GetPatterns();
|
var patterns = matcher.GetPatterns();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(patterns).ContainsExactly("x");
|
Check.That(patterns).ContainsExactly("x");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,65 +1,64 @@
|
|||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class ExactObjectMatcherTests
|
||||||
{
|
{
|
||||||
public class ExactObjectMatcherTests
|
[Fact]
|
||||||
|
public void ExactObjectMatcher_GetName()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void ExactObjectMatcher_GetName()
|
object obj = 1;
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
object obj = 1;
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new ExactObjectMatcher(obj);
|
var matcher = new ExactObjectMatcher(obj);
|
||||||
string name = matcher.Name;
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("ExactObjectMatcher");
|
Check.That(name).Equals("ExactObjectMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ExactObjectMatcher_IsMatch_ByteArray()
|
public void ExactObjectMatcher_IsMatch_ByteArray()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
object checkValue = new byte[] { 1, 2 };
|
object checkValue = new byte[] { 1, 2 };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new ExactObjectMatcher(new byte[] { 1, 2 });
|
var matcher = new ExactObjectMatcher(new byte[] { 1, 2 });
|
||||||
double result = matcher.IsMatch(checkValue);
|
double result = matcher.IsMatch(checkValue);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(1.0);
|
Check.That(result).IsEqualTo(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
|
public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
object obj = new { x = 500, s = "s" };
|
object obj = new { x = 500, s = "s" };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new ExactObjectMatcher(obj);
|
var matcher = new ExactObjectMatcher(obj);
|
||||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(1.0);
|
Check.That(result).IsEqualTo(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ExactObjectMatcher_IsMatch_RejectOnMatch()
|
public void ExactObjectMatcher_IsMatch_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
object obj = new { x = 500, s = "s" };
|
object obj = new { x = 500, s = "s" };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
|
var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
|
||||||
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
double result = matcher.IsMatch(new { x = 500, s = "s" });
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(0.0);
|
Check.That(result).IsEqualTo(0.0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,164 +3,163 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class JmesPathMatcherTests
|
||||||
{
|
{
|
||||||
public class JmesPathMatcherTests
|
[Fact]
|
||||||
|
public void JmesPathMatcher_GetName()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void JmesPathMatcher_GetName()
|
var matcher = new JmesPathMatcher("X");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
string name = matcher.Name;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(name).Equals("JmesPathMatcher");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_GetPatterns()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JmesPathMatcher("X");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var patterns = matcher.GetPatterns();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(patterns).ContainsExactly("X");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_ByteArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var bytes = new byte[0];
|
||||||
|
var matcher = new JmesPathMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(bytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_NullString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string? s = null;
|
||||||
|
var matcher = new JmesPathMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(s);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_NullObject()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
object? o = null;
|
||||||
|
var matcher = new JmesPathMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(o);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_String_Exception_Mismatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JmesPathMatcher("xxx");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch("");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_Object_Exception_Mismatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JmesPathMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch("x");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_AnonymousObject()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JmesPathMatcher("things.name == 'RequiredThing'");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(new { things = new { name = "RequiredThing" } });
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JmesPathMatcher_IsMatch_JObject()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string[] patterns = { "things.x == 'RequiredThing'" };
|
||||||
|
var matcher = new JmesPathMatcher(patterns);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var sub = new JObject
|
||||||
{
|
{
|
||||||
// Assign
|
{ "x", new JValue("RequiredThing") }
|
||||||
var matcher = new JmesPathMatcher("X");
|
};
|
||||||
|
var jobject = new JObject
|
||||||
// Act
|
|
||||||
string name = matcher.Name;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(name).Equals("JmesPathMatcher");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_GetPatterns()
|
|
||||||
{
|
{
|
||||||
// Assign
|
{ "Id", new JValue(1) },
|
||||||
var matcher = new JmesPathMatcher("X");
|
{ "things", sub }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jobject);
|
||||||
|
|
||||||
// Act
|
// Assert
|
||||||
var patterns = matcher.GetPatterns();
|
Check.That(match).IsEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Assert
|
[Fact]
|
||||||
Check.That(patterns).ContainsExactly("X");
|
public void JmesPathMatcher_IsMatch_JObject_Parsed()
|
||||||
}
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JmesPathMatcher("things.x == 'RequiredThing'");
|
||||||
|
|
||||||
[Fact]
|
// Act
|
||||||
public void JmesPathMatcher_IsMatch_ByteArray()
|
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var bytes = new byte[0];
|
|
||||||
var matcher = new JmesPathMatcher("");
|
|
||||||
|
|
||||||
// Act
|
// Assert
|
||||||
double match = matcher.IsMatch(bytes);
|
Check.That(match).IsEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Assert
|
[Fact]
|
||||||
Check.That(match).IsEqualTo(0);
|
public void JmesPathMatcher_IsMatch_RejectOnMatch()
|
||||||
}
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JmesPathMatcher(MatchBehaviour.RejectOnMatch, false, MatchOperator.Or, "things.x == 'RequiredThing'");
|
||||||
|
|
||||||
[Fact]
|
// Act
|
||||||
public void JmesPathMatcher_IsMatch_NullString()
|
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
string? s = null;
|
|
||||||
var matcher = new JmesPathMatcher("");
|
|
||||||
|
|
||||||
// Act
|
// Assert
|
||||||
double match = matcher.IsMatch(s);
|
Check.That(match).IsEqualTo(0.0);
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_NullObject()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
object? o = null;
|
|
||||||
var matcher = new JmesPathMatcher("");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(o);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_String_Exception_Mismatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JmesPathMatcher("xxx");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch("");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_Object_Exception_Mismatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JmesPathMatcher("");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch("x");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_AnonymousObject()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JmesPathMatcher("things.name == 'RequiredThing'");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(new { things = new { name = "RequiredThing" } });
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_JObject()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
string[] patterns = { "things.x == 'RequiredThing'" };
|
|
||||||
var matcher = new JmesPathMatcher(patterns);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var sub = new JObject
|
|
||||||
{
|
|
||||||
{ "x", new JValue("RequiredThing") }
|
|
||||||
};
|
|
||||||
var jobject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "things", sub }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jobject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_JObject_Parsed()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JmesPathMatcher("things.x == 'RequiredThing'");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JmesPathMatcher_IsMatch_RejectOnMatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JmesPathMatcher(MatchBehaviour.RejectOnMatch, false, MatchOperator.Or, "things.x == 'RequiredThing'");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,416 +7,415 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class JsonPartialMatcherTests
|
||||||
{
|
{
|
||||||
public class JsonPartialMatcherTests
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_GetName()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void JsonPartialMatcher_GetName()
|
var matcher = new JsonPartialMatcher("{}");
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("{}");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.Name;
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("JsonPartialMatcher");
|
Check.That(name).Equals("JsonPartialMatcher");
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_GetValue()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("{}");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
object value = matcher.Value;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(value).Equals("{}");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_WithInvalidStringValue_Should_ThrowException()
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
// ReSharper disable once ObjectCreationAsStatement
|
|
||||||
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
action.Should().Throw<JsonException>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_WithInvalidObjectValue_Should_ThrowException()
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
// ReSharper disable once ObjectCreationAsStatement
|
|
||||||
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, new MemoryStream());
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
action.Should().Throw<JsonException>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(new MemoryStream());
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("", false, true);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
Action action = () => matcher.IsMatch(new MemoryStream());
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
action.Should().Throw<JsonException>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_ByteArray()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var bytes = new byte[0];
|
|
||||||
var matcher = new JsonPartialMatcher("");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(bytes);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_NullString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
string? s = null;
|
|
||||||
var matcher = new JsonPartialMatcher("");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(s);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_NullObject()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
object? o = null;
|
|
||||||
var matcher = new JsonPartialMatcher("");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(o);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(match).IsEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JArray()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new[] { "x", "y" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jArray = new JArray
|
|
||||||
{
|
|
||||||
"x",
|
|
||||||
"y"
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jArray);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JObject()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithRegexTrue()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" }, false, false, true);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithRegexFalse()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(0.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObject()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new { id = 1, Name = "test" }, true);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "NaMe", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JObjectParsed()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectParsed()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "TESt" }, true);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JArrayAsString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("[ \"x\", \"y\" ]");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jArray = new JArray
|
|
||||||
{
|
|
||||||
"x",
|
|
||||||
"y"
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jArray);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JObjectAsString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectAsString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"test\" }", true);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JObjectAsString_RejectOnMatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "Id", new JValue(1) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(0.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void JsonPartialMatcher_IsMatch_JObjectWithDateTimeOffsetAsString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher("{ \"preferredAt\" : \"2019-11-21T10:32:53.2210009+00:00\" }");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var jObject = new JObject
|
|
||||||
{
|
|
||||||
{ "preferredAt", new JValue("2019-11-21T10:32:53.2210009+00:00") }
|
|
||||||
};
|
|
||||||
double match = matcher.IsMatch(jObject);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("{\"test\":\"abc\"}", "{\"test\":\"abc\",\"other\":\"xyz\"}")]
|
|
||||||
[InlineData("\"test\"", "\"test\"")]
|
|
||||||
[InlineData("123", "123")]
|
|
||||||
[InlineData("[\"test\"]", "[\"test\"]")]
|
|
||||||
[InlineData("[\"test\"]", "[\"test\", \"other\"]")]
|
|
||||||
[InlineData("[123]", "[123]")]
|
|
||||||
[InlineData("[123]", "[123, 456]")]
|
|
||||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\",\"other\":123}")]
|
|
||||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\"}")]
|
|
||||||
[InlineData("{\"test\":{\"nested\":\"value\"}}", "{\"test\":{\"nested\":\"value\"}}")]
|
|
||||||
public void JsonPartialMatcher_IsMatch_StringInputValidMatch(string value, string input)
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(value);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("\"test\"", null)]
|
|
||||||
[InlineData("\"test1\"", "\"test2\"")]
|
|
||||||
[InlineData("123", "1234")]
|
|
||||||
[InlineData("[\"test\"]", "[\"test1\"]")]
|
|
||||||
[InlineData("[\"test\"]", "[\"test1\", \"test2\"]")]
|
|
||||||
[InlineData("[123]", "[1234]")]
|
|
||||||
[InlineData("{}", "\"test\"")]
|
|
||||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value2\"}")]
|
|
||||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
|
||||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
|
||||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
|
||||||
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(value);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(0.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":123}}")]
|
|
||||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[123, 456]}}")]
|
|
||||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value\"}}")]
|
|
||||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value\"}")]
|
|
||||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value\"}}]")]
|
|
||||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value\"}]")]
|
|
||||||
public void JsonPartialMatcher_IsMatch_ValueAsJPathValidMatch(string value, string input)
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(value);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":456}}")]
|
|
||||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[1, 2]}}")]
|
|
||||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
|
||||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value1\"}")]
|
|
||||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
|
||||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value1\"}]")]
|
|
||||||
public void JsonPartialMatcher_IsMatch_ValueAsJPathInvalidMatch(string value, string input)
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new JsonPartialMatcher(value);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(0.0, match);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_GetValue()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("{}");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
object value = matcher.Value;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(value).Equals("{}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_WithInvalidStringValue_Should_ThrowException()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
// ReSharper disable once ObjectCreationAsStatement
|
||||||
|
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_WithInvalidObjectValue_Should_ThrowException()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
// ReSharper disable once ObjectCreationAsStatement
|
||||||
|
Action action = () => new JsonPartialMatcher(MatchBehaviour.AcceptOnMatch, new MemoryStream());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(new MemoryStream());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("", false, true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Action action = () => matcher.IsMatch(new MemoryStream());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_ByteArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var bytes = new byte[0];
|
||||||
|
var matcher = new JsonPartialMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(bytes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_NullString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string? s = null;
|
||||||
|
var matcher = new JsonPartialMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(s);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_NullObject()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
object? o = null;
|
||||||
|
var matcher = new JsonPartialMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(o);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new[] { "x", "y" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jArray = new JArray
|
||||||
|
{
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jArray);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JObject()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithRegexTrue()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" }, false, false, true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithRegexFalse()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(0.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObject()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new { id = 1, Name = "test" }, true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "NaMe", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JObjectParsed()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "Test" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectParsed()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(new { Id = 1, Name = "TESt" }, true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JArrayAsString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("[ \"x\", \"y\" ]");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jArray = new JArray
|
||||||
|
{
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jArray);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JObjectAsString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_WithIgnoreCaseTrue_JObjectAsString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("{ \"Id\" : 1, \"Name\" : \"test\" }", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JObjectAsString_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "Id", new JValue(1) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(0.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPartialMatcher_IsMatch_JObjectWithDateTimeOffsetAsString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher("{ \"preferredAt\" : \"2019-11-21T10:32:53.2210009+00:00\" }");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var jObject = new JObject
|
||||||
|
{
|
||||||
|
{ "preferredAt", new JValue("2019-11-21T10:32:53.2210009+00:00") }
|
||||||
|
};
|
||||||
|
double match = matcher.IsMatch(jObject);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("{\"test\":\"abc\"}", "{\"test\":\"abc\",\"other\":\"xyz\"}")]
|
||||||
|
[InlineData("\"test\"", "\"test\"")]
|
||||||
|
[InlineData("123", "123")]
|
||||||
|
[InlineData("[\"test\"]", "[\"test\"]")]
|
||||||
|
[InlineData("[\"test\"]", "[\"test\", \"other\"]")]
|
||||||
|
[InlineData("[123]", "[123]")]
|
||||||
|
[InlineData("[123]", "[123, 456]")]
|
||||||
|
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\",\"other\":123}")]
|
||||||
|
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\"}")]
|
||||||
|
[InlineData("{\"test\":{\"nested\":\"value\"}}", "{\"test\":{\"nested\":\"value\"}}")]
|
||||||
|
public void JsonPartialMatcher_IsMatch_StringInputValidMatch(string value, string input)
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("\"test\"", null)]
|
||||||
|
[InlineData("\"test1\"", "\"test2\"")]
|
||||||
|
[InlineData("123", "1234")]
|
||||||
|
[InlineData("[\"test\"]", "[\"test1\"]")]
|
||||||
|
[InlineData("[\"test\"]", "[\"test1\", \"test2\"]")]
|
||||||
|
[InlineData("[123]", "[1234]")]
|
||||||
|
[InlineData("{}", "\"test\"")]
|
||||||
|
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value2\"}")]
|
||||||
|
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||||
|
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||||
|
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||||
|
public void JsonPartialMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(0.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":123}}")]
|
||||||
|
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[123, 456]}}")]
|
||||||
|
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value\"}}")]
|
||||||
|
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value\"}")]
|
||||||
|
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value\"}}]")]
|
||||||
|
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value\"}]")]
|
||||||
|
public void JsonPartialMatcher_IsMatch_ValueAsJPathValidMatch(string value, string input)
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(1.0, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":456}}")]
|
||||||
|
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[1, 2]}}")]
|
||||||
|
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||||
|
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value1\"}")]
|
||||||
|
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||||
|
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value1\"}]")]
|
||||||
|
public void JsonPartialMatcher_IsMatch_ValueAsJPathInvalidMatch(string value, string input)
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPartialMatcher(value);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(0.0, match);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,110 +3,109 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class LinqMatcherTests
|
||||||
{
|
{
|
||||||
public class LinqMatcherTests
|
[Fact]
|
||||||
|
public void LinqMatcher_For_String_SinglePattern_IsMatch_Positive()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void LinqMatcher_For_String_SinglePattern_IsMatch_Positive()
|
string input = "2018-08-31 13:59:59";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LinqMatcher_For_String_IsMatch_Negative()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string input = "2018-08-31 13:59:59";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2019-01-01 00:00:00\"");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LinqMatcher_For_String_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string input = "2018-08-31 13:59:59";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new LinqMatcher(MatchBehaviour.RejectOnMatch, "DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LinqMatcher_For_Object_IsMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var input = new
|
||||||
{
|
{
|
||||||
// Assign
|
Id = 9,
|
||||||
string input = "2018-08-31 13:59:59";
|
Name = "Test"
|
||||||
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
var matcher = new LinqMatcher("Id > 1 AND Name == \"Test\"");
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.IsMatch(input)).IsEqualTo(1.0d);
|
Assert.Equal(1.0, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LinqMatcher_For_String_IsMatch_Negative()
|
public void LinqMatcher_For_JObject_IsMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var input = new JObject
|
||||||
{
|
{
|
||||||
// Assign
|
{ "IntegerId", new JValue(9) },
|
||||||
string input = "2018-08-31 13:59:59";
|
{ "LongId", new JValue(long.MaxValue) },
|
||||||
|
{ "Name", new JValue("Test") }
|
||||||
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new LinqMatcher("DateTime.Parse(it) > \"2019-01-01 00:00:00\"");
|
var matcher = new LinqMatcher("IntegerId > 1 AND LongId > 1 && Name == \"Test\"");
|
||||||
|
double match = matcher.IsMatch(input);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
Assert.Equal(1.0, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LinqMatcher_For_String_IsMatch_RejectOnMatch()
|
public void LinqMatcher_GetName()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
string input = "2018-08-31 13:59:59";
|
var matcher = new LinqMatcher("x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new LinqMatcher(MatchBehaviour.RejectOnMatch, "DateTime.Parse(it) > \"2018-08-01 13:50:00\"");
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.IsMatch(input)).IsEqualTo(0.0d);
|
Check.That(name).Equals("LinqMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LinqMatcher_For_Object_IsMatch()
|
public void LinqMatcher_GetPatterns()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var input = new
|
var matcher = new LinqMatcher("x");
|
||||||
{
|
|
||||||
Id = 9,
|
|
||||||
Name = "Test"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new LinqMatcher("Id > 1 AND Name == \"Test\"");
|
var patterns = matcher.GetPatterns();
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(1.0, match);
|
Check.That(patterns).ContainsExactly("x");
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void LinqMatcher_For_JObject_IsMatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var input = new JObject
|
|
||||||
{
|
|
||||||
{ "IntegerId", new JValue(9) },
|
|
||||||
{ "LongId", new JValue(long.MaxValue) },
|
|
||||||
{ "Name", new JValue("Test") }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var matcher = new LinqMatcher("IntegerId > 1 AND LongId > 1 && Name == \"Test\"");
|
|
||||||
double match = matcher.IsMatch(input);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(1.0, match);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void LinqMatcher_GetName()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new LinqMatcher("x");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
string name = matcher.Name;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(name).Equals("LinqMatcher");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void LinqMatcher_GetPatterns()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new LinqMatcher("x");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var patterns = matcher.GetPatterns();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(patterns).ContainsExactly("x");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
{
|
|
||||||
public class MatchBehaviourHelperTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void MatchBehaviourHelper_Convert_AcceptOnMatch()
|
|
||||||
{
|
|
||||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0);
|
|
||||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5);
|
|
||||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
public class MatchBehaviourHelperTests
|
||||||
public void MatchBehaviourHelper_Convert_RejectOnMatch()
|
{
|
||||||
{
|
[Fact]
|
||||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0)).IsEqualTo(1.0);
|
public void MatchBehaviourHelper_Convert_AcceptOnMatch()
|
||||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5)).IsEqualTo(0.0);
|
{
|
||||||
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0)).IsEqualTo(0.0);
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0);
|
||||||
}
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Fact]
|
||||||
|
public void MatchBehaviourHelper_Convert_RejectOnMatch()
|
||||||
|
{
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0)).IsEqualTo(1.0);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5)).IsEqualTo(0.0);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0)).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,82 +3,81 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class NotNullOrEmptyMatcherTests
|
||||||
{
|
{
|
||||||
public class NotNullOrEmptyMatcherTests
|
[Fact]
|
||||||
|
public void NotNullOrEmptyMatcher_GetName()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void NotNullOrEmptyMatcher_GetName()
|
var matcher = new NotNullOrEmptyMatcher();
|
||||||
{
|
string name = matcher.Name;
|
||||||
// Act
|
|
||||||
var matcher = new NotNullOrEmptyMatcher();
|
|
||||||
string name = matcher.Name;
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("NotNullOrEmptyMatcher");
|
Check.That(name).Equals("NotNullOrEmptyMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(null, 0.0)]
|
[InlineData(null, 0.0)]
|
||||||
[InlineData(new byte[0], 0.0)]
|
[InlineData(new byte[0], 0.0)]
|
||||||
[InlineData(new byte[] { 48 }, 1.0)]
|
[InlineData(new byte[] { 48 }, 1.0)]
|
||||||
public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[] data, double expected)
|
public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[] data, double expected)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var matcher = new NotNullOrEmptyMatcher();
|
var matcher = new NotNullOrEmptyMatcher();
|
||||||
double result = matcher.IsMatch(data);
|
double result = matcher.IsMatch(data);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(null, 0.0)]
|
[InlineData(null, 0.0)]
|
||||||
[InlineData("", 0.0)]
|
[InlineData("", 0.0)]
|
||||||
[InlineData("x", 1.0)]
|
[InlineData("x", 1.0)]
|
||||||
public void NotNullOrEmptyMatcher_IsMatch_String(string @string, double expected)
|
public void NotNullOrEmptyMatcher_IsMatch_String(string @string, double expected)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var matcher = new NotNullOrEmptyMatcher();
|
var matcher = new NotNullOrEmptyMatcher();
|
||||||
double result = matcher.IsMatch(@string);
|
double result = matcher.IsMatch(@string);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(null, 0.0)]
|
[InlineData(null, 0.0)]
|
||||||
[InlineData("", 0.0)]
|
[InlineData("", 0.0)]
|
||||||
[InlineData("x", 1.0)]
|
[InlineData("x", 1.0)]
|
||||||
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string @string, double expected)
|
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string @string, double expected)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var matcher = new NotNullOrEmptyMatcher();
|
var matcher = new NotNullOrEmptyMatcher();
|
||||||
double result = matcher.IsMatch((object)@string);
|
double result = matcher.IsMatch((object)@string);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(expected);
|
result.Should().Be(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NotNullOrEmptyMatcher_IsMatch_Json()
|
public void NotNullOrEmptyMatcher_IsMatch_Json()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var matcher = new NotNullOrEmptyMatcher();
|
var matcher = new NotNullOrEmptyMatcher();
|
||||||
double result = matcher.IsMatch(new { x = "x" });
|
double result = matcher.IsMatch(new { x = "x" });
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(1.0);
|
result.Should().Be(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray()
|
public void NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var patterns = new NotNullOrEmptyMatcher().GetPatterns();
|
var patterns = new NotNullOrEmptyMatcher().GetPatterns();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
patterns.Should().BeEmpty();
|
patterns.Should().BeEmpty();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,124 +4,123 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class RegexMatcherTests
|
||||||
{
|
{
|
||||||
public class RegexMatcherTests
|
[Fact]
|
||||||
|
public void RegexMatcher_GetName()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void RegexMatcher_GetName()
|
var matcher = new RegexMatcher("");
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new RegexMatcher("");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.Name;
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("RegexMatcher");
|
Check.That(name).Equals("RegexMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_GetPatterns()
|
public void RegexMatcher_GetPatterns()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher("X");
|
var matcher = new RegexMatcher("X");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var patterns = matcher.GetPatterns();
|
var patterns = matcher.GetPatterns();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(patterns).ContainsExactly("X");
|
Check.That(patterns).ContainsExactly("X");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_GetIgnoreCase()
|
public void RegexMatcher_GetIgnoreCase()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
bool case1 = new RegexMatcher("X").IgnoreCase;
|
bool case1 = new RegexMatcher("X").IgnoreCase;
|
||||||
bool case2 = new RegexMatcher("X", true).IgnoreCase;
|
bool case2 = new RegexMatcher("X", true).IgnoreCase;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(case1).IsFalse();
|
Check.That(case1).IsFalse();
|
||||||
Check.That(case2).IsTrue();
|
Check.That(case2).IsTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch()
|
public void RegexMatcher_IsMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher("H.*o");
|
var matcher = new RegexMatcher("H.*o");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("Hello world!");
|
double result = matcher.IsMatch("Hello world!");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(1.0d);
|
Check.That(result).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch_NullInput()
|
public void RegexMatcher_IsMatch_NullInput()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher("H.*o");
|
var matcher = new RegexMatcher("H.*o");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch(null);
|
double result = matcher.IsMatch(null);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(0.0d);
|
Check.That(result).IsEqualTo(0.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch_RegexExtended_Guid()
|
public void RegexMatcher_IsMatch_RegexExtended_Guid()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher(@"\GUIDB", true);
|
var matcher = new RegexMatcher(@"\GUIDB", true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(1.0);
|
result.Should().Be(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch_Regex_Guid()
|
public void RegexMatcher_IsMatch_Regex_Guid()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher(@"\GUIDB", true, false, false);
|
var matcher = new RegexMatcher(@"\GUIDB", true, false, false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be(0);
|
result.Should().Be(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch_IgnoreCase()
|
public void RegexMatcher_IsMatch_IgnoreCase()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher("H.*o", true);
|
var matcher = new RegexMatcher("H.*o", true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("hello");
|
double result = matcher.IsMatch("hello");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(1.0d);
|
Check.That(result).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch_RejectOnMatch()
|
public void RegexMatcher_IsMatch_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");
|
var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("hello");
|
double result = matcher.IsMatch("hello");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(0.0);
|
Check.That(result).IsEqualTo(0.0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,54 +1,53 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class RequestMatchResultTests
|
||||||
{
|
{
|
||||||
public class RequestMatchResultTests
|
[Fact]
|
||||||
|
public void CompareTo_WithDifferentAverageScore_ReturnsBestMatch()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Arrange
|
||||||
public void CompareTo_WithDifferentAverageScore_ReturnsBestMatch()
|
var result1 = new RequestMatchResult();
|
||||||
{
|
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||||
// Arrange
|
result1.AddScore(typeof(WildcardMatcher), 0.9);
|
||||||
var result1 = new RequestMatchResult();
|
|
||||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
|
||||||
result1.AddScore(typeof(WildcardMatcher), 0.9);
|
|
||||||
|
|
||||||
var result2 = new RequestMatchResult();
|
var result2 = new RequestMatchResult();
|
||||||
result2.AddScore(typeof(LinqMatcher), 1);
|
result2.AddScore(typeof(LinqMatcher), 1);
|
||||||
result2.AddScore(typeof(LinqMatcher), 1);
|
result2.AddScore(typeof(LinqMatcher), 1);
|
||||||
|
|
||||||
var results = new[] { result1, result2 };
|
var results = new[] { result1, result2 };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var best = results.OrderBy(x => x).First();
|
var best = results.OrderBy(x => x).First();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
best.Should().Be(result2);
|
best.Should().Be(result2);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CompareTo_WithSameAverageScoreButMoreMatchers_ReturnsMatchWithMoreMatchers()
|
public void CompareTo_WithSameAverageScoreButMoreMatchers_ReturnsMatchWithMoreMatchers()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var result1 = new RequestMatchResult();
|
var result1 = new RequestMatchResult();
|
||||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||||
result1.AddScore(typeof(WildcardMatcher), 1);
|
result1.AddScore(typeof(WildcardMatcher), 1);
|
||||||
|
|
||||||
var result2 = new RequestMatchResult();
|
var result2 = new RequestMatchResult();
|
||||||
result2.AddScore(typeof(LinqMatcher), 1);
|
result2.AddScore(typeof(LinqMatcher), 1);
|
||||||
result2.AddScore(typeof(LinqMatcher), 1);
|
result2.AddScore(typeof(LinqMatcher), 1);
|
||||||
result2.AddScore(typeof(LinqMatcher), 1);
|
result2.AddScore(typeof(LinqMatcher), 1);
|
||||||
|
|
||||||
var results = new[] { result1, result2 };
|
var results = new[] { result1, result2 };
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var best = results.OrderBy(x => x).First();
|
var best = results.OrderBy(x => x).First();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
best.Should().Be(result2);
|
best.Should().Be(result2);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,86 +2,85 @@ using NFluent;
|
|||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class SimMetricsMatcherTests
|
||||||
{
|
{
|
||||||
public class SimMetricsMatcherTests
|
[Fact]
|
||||||
|
public void SimMetricsMatcher_GetName()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void SimMetricsMatcher_GetName()
|
var matcher = new SimMetricsMatcher("X");
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new SimMetricsMatcher("X");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.Name;
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SimMetricsMatcher_GetPatterns()
|
public void SimMetricsMatcher_GetPatterns()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new SimMetricsMatcher("X");
|
var matcher = new SimMetricsMatcher("X");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var patterns = matcher.GetPatterns();
|
var patterns = matcher.GetPatterns();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(patterns).ContainsExactly("X");
|
Check.That(patterns).ContainsExactly("X");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SimMetricsMatcher_IsMatch_1()
|
public void SimMetricsMatcher_IsMatch_1()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("The car drives in the street.");
|
double result = matcher.IsMatch("The car drives in the street.");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
Check.That(result).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SimMetricsMatcher_IsMatch_2()
|
public void SimMetricsMatcher_IsMatch_2()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
var matcher = new SimMetricsMatcher("The cat walks in the street.");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("Hello");
|
double result = matcher.IsMatch("Hello");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SimMetricsMatcher_IsMatch_AcceptOnMatch()
|
public void SimMetricsMatcher_IsMatch_AcceptOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new SimMetricsMatcher("test");
|
var matcher = new SimMetricsMatcher("test");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("test");
|
double result = matcher.IsMatch("test");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(1.0);
|
Check.That(result).IsEqualTo(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SimMetricsMatcher_IsMatch_RejectOnMatch()
|
public void SimMetricsMatcher_IsMatch_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new SimMetricsMatcher(MatchBehaviour.RejectOnMatch, "test");
|
var matcher = new SimMetricsMatcher(MatchBehaviour.RejectOnMatch, "test");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("test");
|
double result = matcher.IsMatch("test");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(0.0);
|
Check.That(result).IsEqualTo(0.0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,135 +5,134 @@ using WireMock.Matchers;
|
|||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
|
public class WildcardMatcherTest
|
||||||
{
|
{
|
||||||
public class WildcardMatcherTest
|
[Fact]
|
||||||
|
public void WildcardMatcher_IsMatch_With_StringPattern()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Arrange
|
||||||
public void WildcardMatcher_IsMatch_With_StringPattern()
|
var pattern = new StringPattern
|
||||||
{
|
{
|
||||||
// Arrange
|
Pattern = "*",
|
||||||
var pattern = new StringPattern
|
PatternAsFile = "pf"
|
||||||
{
|
};
|
||||||
Pattern = "*",
|
|
||||||
PatternAsFile = "pf"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new WildcardMatcher(pattern);
|
var matcher = new WildcardMatcher(pattern);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
matcher.IsMatch("a").Should().Be(1.0d);
|
matcher.IsMatch("a").Should().Be(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WildcardMatcher_IsMatch_With_StringPatterns()
|
public void WildcardMatcher_IsMatch_With_StringPatterns()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
AnyOf<string, StringPattern> pattern1 = new StringPattern
|
||||||
{
|
{
|
||||||
// Arrange
|
Pattern = "a"
|
||||||
AnyOf<string, StringPattern> pattern1 = new StringPattern
|
};
|
||||||
{
|
AnyOf<string, StringPattern> pattern2 = new StringPattern
|
||||||
Pattern = "a"
|
|
||||||
};
|
|
||||||
AnyOf<string, StringPattern> pattern2 = new StringPattern
|
|
||||||
{
|
|
||||||
Pattern = "b"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var matcher = new WildcardMatcher(new [] { pattern1, pattern2 });
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
matcher.IsMatch("a").Should().Be(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WildcardMatcher_IsMatch_Positive()
|
|
||||||
{
|
{
|
||||||
var tests = new[]
|
Pattern = "b"
|
||||||
{
|
};
|
||||||
new { p = "*", i = "" },
|
|
||||||
new { p = "?", i = " "},
|
|
||||||
new { p = "*", i = "a "},
|
|
||||||
new { p = "*", i = "ab" },
|
|
||||||
new { p = "?", i = "a" },
|
|
||||||
new { p = "*?", i = "abc" },
|
|
||||||
new { p = "?*", i = "abc" },
|
|
||||||
new { p = "abc", i = "abc" },
|
|
||||||
new { p = "abc*", i = "abc" },
|
|
||||||
new { p = "abc*", i = "abcd" },
|
|
||||||
new { p = "*abc*", i = "abc" },
|
|
||||||
new { p = "*a*bc*", i = "abc" },
|
|
||||||
new { p = "*a*b?", i = "aXXXbc" }
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var test in tests)
|
// Act
|
||||||
{
|
var matcher = new WildcardMatcher(new [] { pattern1, pattern2 });
|
||||||
var matcher = new WildcardMatcher(test.p);
|
|
||||||
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
// Assert
|
||||||
public void WildcardMatcher_IsMatch_Negative()
|
matcher.IsMatch("a").Should().Be(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WildcardMatcher_IsMatch_Positive()
|
||||||
|
{
|
||||||
|
var tests = new[]
|
||||||
{
|
{
|
||||||
var tests = new[]
|
new { p = "*", i = "" },
|
||||||
{
|
new { p = "?", i = " "},
|
||||||
new { p = "*a", i = "" },
|
new { p = "*", i = "a "},
|
||||||
new { p = "a*", i = "" },
|
new { p = "*", i = "ab" },
|
||||||
new { p = "?", i = "" },
|
new { p = "?", i = "a" },
|
||||||
new { p = "*b*", i = "a" },
|
new { p = "*?", i = "abc" },
|
||||||
new { p = "b*a", i = "ab" },
|
new { p = "?*", i = "abc" },
|
||||||
new { p = "??", i = "a" },
|
new { p = "abc", i = "abc" },
|
||||||
new { p = "*?", i = "" },
|
new { p = "abc*", i = "abc" },
|
||||||
new { p = "??*", i = "a" },
|
new { p = "abc*", i = "abcd" },
|
||||||
new { p = "*abc", i = "abX" },
|
new { p = "*abc*", i = "abc" },
|
||||||
new { p = "*abc*", i = "Xbc" },
|
new { p = "*a*bc*", i = "abc" },
|
||||||
new { p = "*a*bc*", i = "ac" }
|
new { p = "*a*b?", i = "aXXXbc" }
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var test in tests)
|
foreach (var test in tests)
|
||||||
{
|
|
||||||
var matcher = new WildcardMatcher(test.p);
|
|
||||||
Check.That(matcher.IsMatch(test.i)).IsEqualTo(0.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WildcardMatcher_GetName()
|
|
||||||
{
|
{
|
||||||
// Assign
|
var matcher = new WildcardMatcher(test.p);
|
||||||
var matcher = new WildcardMatcher("x");
|
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
||||||
|
|
||||||
// Act
|
|
||||||
string name = matcher.Name;
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(name).Equals("WildcardMatcher");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WildcardMatcher_GetPatterns()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new WildcardMatcher("x");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var patterns = matcher.GetPatterns();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
double result = matcher.IsMatch("m");
|
|
||||||
|
|
||||||
Check.That(result).IsEqualTo(0.0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WildcardMatcher_IsMatch_Negative()
|
||||||
|
{
|
||||||
|
var tests = new[]
|
||||||
|
{
|
||||||
|
new { p = "*a", i = "" },
|
||||||
|
new { p = "a*", i = "" },
|
||||||
|
new { p = "?", i = "" },
|
||||||
|
new { p = "*b*", i = "a" },
|
||||||
|
new { p = "b*a", i = "ab" },
|
||||||
|
new { p = "??", i = "a" },
|
||||||
|
new { p = "*?", i = "" },
|
||||||
|
new { p = "??*", i = "a" },
|
||||||
|
new { p = "*abc", i = "abX" },
|
||||||
|
new { p = "*abc*", i = "Xbc" },
|
||||||
|
new { p = "*a*bc*", i = "ac" }
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var test in tests)
|
||||||
|
{
|
||||||
|
var matcher = new WildcardMatcher(test.p);
|
||||||
|
Check.That(matcher.IsMatch(test.i)).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WildcardMatcher_GetName()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new WildcardMatcher("x");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
string name = matcher.Name;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(name).Equals("WildcardMatcher");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WildcardMatcher_GetPatterns()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new WildcardMatcher("x");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var patterns = matcher.GetPatterns();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("m");
|
||||||
|
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,98 +3,97 @@ using NFluent;
|
|||||||
using WireMock.RegularExpressions;
|
using WireMock.RegularExpressions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RegularExpressions
|
namespace WireMock.Net.Tests.RegularExpressions;
|
||||||
|
|
||||||
|
public class RegexExtendedTests
|
||||||
{
|
{
|
||||||
public class RegexExtendedTests
|
/// <summary>
|
||||||
|
/// Input guid used for testing
|
||||||
|
/// </summary>
|
||||||
|
public Guid InputGuid => Guid.NewGuid();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexExtended_GuidB_Pattern()
|
||||||
{
|
{
|
||||||
/// <summary>
|
var guidbUpper = @".*\GUIDB.*";
|
||||||
/// Input guid used for testing
|
var guidbLower = @".*\guidb.*";
|
||||||
/// </summary>
|
|
||||||
public Guid InputGuid => Guid.NewGuid();
|
|
||||||
|
|
||||||
[Fact]
|
var inputLower = InputGuid.ToString("B");
|
||||||
public void RegexExtended_GuidB_Pattern()
|
var inputUpper = InputGuid.ToString("B").ToUpper();
|
||||||
{
|
var regexLower = new RegexExtended(guidbLower);
|
||||||
var guidbUpper = @".*\GUIDB.*";
|
var regexUpper = new RegexExtended(guidbUpper);
|
||||||
var guidbLower = @".*\guidb.*";
|
|
||||||
|
|
||||||
var inputLower = InputGuid.ToString("B");
|
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||||
var inputUpper = InputGuid.ToString("B").ToUpper();
|
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||||
var regexLower = new RegexExtended(guidbLower);
|
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||||
var regexUpper = new RegexExtended(guidbUpper);
|
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||||
|
|
||||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
|
||||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
|
||||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
|
||||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RegexExtended_GuidD_Pattern()
|
|
||||||
{
|
|
||||||
var guiddUpper = @".*\GUIDD.*";
|
|
||||||
var guiddLower = @".*\guidd.*";
|
|
||||||
|
|
||||||
var inputLower = InputGuid.ToString("D");
|
|
||||||
var inputUpper = InputGuid.ToString("D").ToUpper();
|
|
||||||
var regexLower = new RegexExtended(guiddLower);
|
|
||||||
var regexUpper = new RegexExtended(guiddUpper);
|
|
||||||
|
|
||||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
|
||||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
|
||||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
|
||||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RegexExtended_GuidN_Pattern()
|
|
||||||
{
|
|
||||||
var guidnUpper = @".*\GUIDN.*";
|
|
||||||
var guidnLower = @".*\guidn.*";
|
|
||||||
|
|
||||||
var inputLower = InputGuid.ToString("N");
|
|
||||||
var inputUpper = InputGuid.ToString("N").ToUpper();
|
|
||||||
var regexLower = new RegexExtended(guidnLower);
|
|
||||||
var regexUpper = new RegexExtended(guidnUpper);
|
|
||||||
|
|
||||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
|
||||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
|
||||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
|
||||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RegexExtended_GuidP_Pattern()
|
|
||||||
{
|
|
||||||
var guidpUpper = @".*\GUIDP.*";
|
|
||||||
var guidpLower = @".*\guidp.*";
|
|
||||||
|
|
||||||
var inputLower = InputGuid.ToString("P");
|
|
||||||
var inputUpper = InputGuid.ToString("P").ToUpper();
|
|
||||||
var regexLower = new RegexExtended(guidpLower);
|
|
||||||
var regexUpper = new RegexExtended(guidpUpper);
|
|
||||||
|
|
||||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
|
||||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
|
||||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
|
||||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RegexExtended_GuidX_Pattern()
|
|
||||||
{
|
|
||||||
var guidxUpper = @".*\GUIDX.*";
|
|
||||||
var guidxLower = @".*\guidx.*";
|
|
||||||
|
|
||||||
var inputLower = InputGuid.ToString("X");
|
|
||||||
var inputUpper = InputGuid.ToString("X").ToUpper().Replace("X", "x");
|
|
||||||
var regexLower = new RegexExtended(guidxLower);
|
|
||||||
var regexUpper = new RegexExtended(guidxUpper);
|
|
||||||
|
|
||||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
|
||||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
|
||||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
|
||||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexExtended_GuidD_Pattern()
|
||||||
|
{
|
||||||
|
var guiddUpper = @".*\GUIDD.*";
|
||||||
|
var guiddLower = @".*\guidd.*";
|
||||||
|
|
||||||
|
var inputLower = InputGuid.ToString("D");
|
||||||
|
var inputUpper = InputGuid.ToString("D").ToUpper();
|
||||||
|
var regexLower = new RegexExtended(guiddLower);
|
||||||
|
var regexUpper = new RegexExtended(guiddUpper);
|
||||||
|
|
||||||
|
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||||
|
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||||
|
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||||
|
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexExtended_GuidN_Pattern()
|
||||||
|
{
|
||||||
|
var guidnUpper = @".*\GUIDN.*";
|
||||||
|
var guidnLower = @".*\guidn.*";
|
||||||
|
|
||||||
|
var inputLower = InputGuid.ToString("N");
|
||||||
|
var inputUpper = InputGuid.ToString("N").ToUpper();
|
||||||
|
var regexLower = new RegexExtended(guidnLower);
|
||||||
|
var regexUpper = new RegexExtended(guidnUpper);
|
||||||
|
|
||||||
|
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||||
|
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||||
|
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||||
|
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexExtended_GuidP_Pattern()
|
||||||
|
{
|
||||||
|
var guidpUpper = @".*\GUIDP.*";
|
||||||
|
var guidpLower = @".*\guidp.*";
|
||||||
|
|
||||||
|
var inputLower = InputGuid.ToString("P");
|
||||||
|
var inputUpper = InputGuid.ToString("P").ToUpper();
|
||||||
|
var regexLower = new RegexExtended(guidpLower);
|
||||||
|
var regexUpper = new RegexExtended(guidpUpper);
|
||||||
|
|
||||||
|
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||||
|
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||||
|
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||||
|
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexExtended_GuidX_Pattern()
|
||||||
|
{
|
||||||
|
var guidxUpper = @".*\GUIDX.*";
|
||||||
|
var guidxLower = @".*\guidx.*";
|
||||||
|
|
||||||
|
var inputLower = InputGuid.ToString("X");
|
||||||
|
var inputUpper = InputGuid.ToString("X").ToUpper().Replace("X", "x");
|
||||||
|
var regexLower = new RegexExtended(guidxLower);
|
||||||
|
var regexUpper = new RegexExtended(guidxUpper);
|
||||||
|
|
||||||
|
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||||
|
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||||
|
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||||
|
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,78 +1,77 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestBuilders
|
namespace WireMock.Net.Tests.RequestBuilders;
|
||||||
|
|
||||||
|
public class RequestBuilderUsingMethodTests
|
||||||
{
|
{
|
||||||
public class RequestBuilderUsingMethodTests
|
[Fact]
|
||||||
|
public void RequestBuilder_UsingConnect()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void RequestBuilder_UsingConnect()
|
var requestBuilder = (Request)Request.Create().UsingConnect();
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().UsingConnect();
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("CONNECT");
|
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("CONNECT");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_UsingOptions()
|
public void RequestBuilder_UsingOptions()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().UsingOptions();
|
var requestBuilder = (Request)Request.Create().UsingOptions();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("OPTIONS");
|
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("OPTIONS");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_UsingPatch()
|
public void RequestBuilder_UsingPatch()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().UsingPatch();
|
var requestBuilder = (Request)Request.Create().UsingPatch();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_UsingTrace()
|
public void RequestBuilder_UsingTrace()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().UsingTrace();
|
var requestBuilder = (Request)Request.Create().UsingTrace();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("TRACE");
|
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("TRACE");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestBuilder = (Request)Request.Create().UsingGet();
|
var requestBuilder = (Request)Request.Create().UsingGet();
|
||||||
|
|
||||||
// Assert 1
|
// Assert 1
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageMethodMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageMethodMatcher));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
requestBuilder.UsingAnyMethod();
|
requestBuilder.UsingAnyMethod();
|
||||||
|
|
||||||
// Assert 2
|
// Assert 2
|
||||||
matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(0);
|
Check.That(matchers.Count).IsEqualTo(0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
@@ -6,39 +6,38 @@ using WireMock.Matchers.Request;
|
|||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestBuilders
|
namespace WireMock.Net.Tests.RequestBuilders;
|
||||||
|
|
||||||
|
public class RequestBuilderWithBodyTests
|
||||||
{
|
{
|
||||||
public class RequestBuilderWithBodyTests
|
[Fact]
|
||||||
|
public void RequestBuilder_WithBody_IMatcher()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void RequestBuilder_WithBody_IMatcher()
|
var matcher = new WildcardMatcher("x");
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var matcher = new WildcardMatcher("x");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithBody(matcher);
|
var requestBuilder = (Request)Request.Create().WithBody(matcher);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
matchers.Should().HaveCount(1);
|
matchers.Should().HaveCount(1);
|
||||||
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(matcher);
|
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithBody_IMatchers()
|
public void RequestBuilder_WithBody_IMatchers()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher1 = new WildcardMatcher("x");
|
var matcher1 = new WildcardMatcher("x");
|
||||||
var matcher2 = new WildcardMatcher("y");
|
var matcher2 = new WildcardMatcher("y");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithBody(new[] { matcher1, matcher2 }.Cast<IMatcher>().ToArray());
|
var requestBuilder = (Request)Request.Create().WithBody(new[] { matcher1, matcher2 }.Cast<IMatcher>().ToArray());
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
matchers.Should().HaveCount(1);
|
matchers.Should().HaveCount(1);
|
||||||
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(new[] { matcher1, matcher2 });
|
((RequestMessageBodyMatcher)matchers[0]).Matchers.Should().Contain(new[] { matcher1, matcher2 });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,48 +1,47 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestBuilders
|
namespace WireMock.Net.Tests.RequestBuilders;
|
||||||
|
|
||||||
|
public class RequestBuilderWithCookieTests
|
||||||
{
|
{
|
||||||
public class RequestBuilderWithCookieTests
|
[Fact]
|
||||||
|
public void RequestBuilder_WithCookie_String_String_Bool_MatchBehaviour()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void RequestBuilder_WithCookie_String_String_Bool_MatchBehaviour()
|
var requestBuilder = (Request)Request.Create().WithCookie("c", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().WithCookie("c", "t", true, MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithCookie_String_IStringMatcher()
|
public void RequestBuilder_WithCookie_String_IStringMatcher()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithCookie("c", new ExactMatcher("v"));
|
var requestBuilder = (Request)Request.Create().WithCookie("c", new ExactMatcher("v"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithCookie_FuncIDictionary()
|
public void RequestBuilder_WithCookie_FuncIDictionary()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithCookie((IDictionary<string, string> x) => true);
|
var requestBuilder = (Request)Request.Create().WithCookie((IDictionary<string, string> x) => true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageCookieMatcher));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,84 +1,83 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestBuilders
|
namespace WireMock.Net.Tests.RequestBuilders;
|
||||||
|
|
||||||
|
public class RequestBuilderWithHeaderTests
|
||||||
{
|
{
|
||||||
public class RequestBuilderWithHeaderTests
|
[Fact]
|
||||||
|
public void RequestBuilder_WithHeader_String_String_MatchBehaviour()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void RequestBuilder_WithHeader_String_String_MatchBehaviour()
|
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", MatchBehaviour.AcceptOnMatch);
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithHeader_String_String_Bool_MatchBehaviour()
|
public void RequestBuilder_WithHeader_String_String_Bool_MatchBehaviour()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", true, MatchBehaviour.AcceptOnMatch);
|
var requestBuilder = (Request)Request.Create().WithHeader("h", "t", true, MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithHeader_String_Strings_MatchBehaviour()
|
public void RequestBuilder_WithHeader_String_Strings_MatchBehaviour()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, MatchBehaviour.AcceptOnMatch);
|
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithHeader_String_Strings_Bool_MatchBehaviour()
|
public void RequestBuilder_WithHeader_String_Strings_Bool_MatchBehaviour()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, true, MatchBehaviour.AcceptOnMatch);
|
var requestBuilder = (Request)Request.Create().WithHeader("h", new[] { "t1", "t2" }, true, MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithHeader_String_IStringMatcher()
|
public void RequestBuilder_WithHeader_String_IStringMatcher()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithHeader("h", new ExactMatcher("v"));
|
var requestBuilder = (Request)Request.Create().WithHeader("h", new ExactMatcher("v"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithHeader_FuncIDictionary()
|
public void RequestBuilder_WithHeader_FuncIDictionary()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithHeader(x => true);
|
var requestBuilder = (Request)Request.Create().WithHeader(x => true);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageHeaderMatcher));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,60 +1,59 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestBuilders
|
namespace WireMock.Net.Tests.RequestBuilders;
|
||||||
|
|
||||||
|
public class RequestBuilderWithParamTests
|
||||||
{
|
{
|
||||||
public class RequestBuilderWithParamTests
|
[Fact]
|
||||||
|
public void RequestBuilder_WithParam_String_MatchBehaviour()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void RequestBuilder_WithParam_String_MatchBehaviour()
|
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch);
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithParam_String_Strings()
|
public void RequestBuilder_WithParam_String_Strings()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithParam("p", new[] { "v1", "v2" });
|
var requestBuilder = (Request)Request.Create().WithParam("p", new[] { "v1", "v2" });
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithParam_String_IStringMatcher()
|
public void RequestBuilder_WithParam_String_IStringMatcher()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithParam("p", new RegexMatcher("[012]"));
|
var requestBuilder = (Request)Request.Create().WithParam("p", new RegexMatcher("[012]"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithParam_String_MatchBehaviour_IExactMatcher()
|
public void RequestBuilder_WithParam_String_MatchBehaviour_IExactMatcher()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch, new ExactMatcher("v"));
|
var requestBuilder = (Request)Request.Create().WithParam("p", MatchBehaviour.AcceptOnMatch, new ExactMatcher("v"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageParamMatcher));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,56 +5,55 @@ using WireMock.Matchers.Request;
|
|||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestBuilders
|
namespace WireMock.Net.Tests.RequestBuilders;
|
||||||
|
|
||||||
|
public class RequestBuilderWithUrlTests
|
||||||
{
|
{
|
||||||
public class RequestBuilderWithUrlTests
|
[Fact]
|
||||||
|
public void RequestBuilder_WithUrl_Strings()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Act
|
||||||
public void RequestBuilder_WithUrl_Strings()
|
var requestBuilder = (Request)Request.Create().WithUrl("http://a", "http://b");
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().WithUrl("http://a", "http://b");
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithUrl_MatchBehaviour_Strings()
|
public void RequestBuilder_WithUrl_MatchBehaviour_Strings()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithUrl(MatchOperator.Or, "http://a", "http://b");
|
var requestBuilder = (Request)Request.Create().WithUrl(MatchOperator.Or, "http://a", "http://b");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithUrl_Funcs()
|
public void RequestBuilder_WithUrl_Funcs()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request) Request.Create().WithUrl(url => true, url => false);
|
var requestBuilder = (Request) Request.Create().WithUrl(url => true, url => false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithUrl_IStringMatchers()
|
public void RequestBuilder_WithUrl_IStringMatchers()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request) Request.Create().WithUrl(new ExactMatcher("http://a"), new ExactMatcher("http://b"));
|
var requestBuilder = (Request) Request.Create().WithUrl(new ExactMatcher("http://a"), new ExactMatcher("http://b"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
Check.That(matchers[0]).IsInstanceOfType(typeof(RequestMessageUrlMatcher));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
@@ -6,78 +6,77 @@ using WireMock.Matchers.Request;
|
|||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestMatchers
|
namespace WireMock.Net.Tests.RequestMatchers;
|
||||||
|
|
||||||
|
public class RequestMessageCompositeMatcherTests
|
||||||
{
|
{
|
||||||
public class RequestMessageCompositeMatcherTests
|
private class Helper : RequestMessageCompositeMatcher
|
||||||
{
|
{
|
||||||
private class Helper : RequestMessageCompositeMatcher
|
public Helper(IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And) : base(requestMatchers, type)
|
||||||
{
|
{
|
||||||
public Helper(IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And) : base(requestMatchers, type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageCompositeMatcher_GetMatchingScore_EmptyArray()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new Helper(Enumerable.Empty<IRequestMatcher>());
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(0.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_And()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
|
||||||
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
|
||||||
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
|
||||||
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
|
||||||
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(0.9d);
|
|
||||||
|
|
||||||
// Verify
|
|
||||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
|
||||||
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_Or()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
|
||||||
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
|
||||||
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
|
||||||
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
|
||||||
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object }, CompositeMatcherType.Or);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
|
||||||
|
|
||||||
// Verify
|
|
||||||
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
|
||||||
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCompositeMatcher_GetMatchingScore_EmptyArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new Helper(Enumerable.Empty<IRequestMatcher>());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_And()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
||||||
|
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
||||||
|
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
||||||
|
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
||||||
|
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.9d);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||||
|
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCompositeMatcher_GetMatchingScore_CompositeMatcherType_Or()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMatcher1Mock = new Mock<IRequestMatcher>();
|
||||||
|
requestMatcher1Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(1.0d);
|
||||||
|
var requestMatcher2Mock = new Mock<IRequestMatcher>();
|
||||||
|
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
|
||||||
|
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object }, CompositeMatcherType.Or);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
requestMatcher1Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||||
|
requestMatcher2Mock.Verify(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>()), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,154 +1,153 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestMatchers
|
namespace WireMock.Net.Tests.RequestMatchers;
|
||||||
|
|
||||||
|
public class RequestMessageCookieMatcherTests
|
||||||
{
|
{
|
||||||
public class RequestMessageCookieMatcherTests
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||||
{
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", false, "x");
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", false, "x");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(0.0d);
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
|
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", false, "x");
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", false, "x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch()
|
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", false, "x");
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", false, "x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch()
|
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", false, "x");
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", false, "x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(0.0d);
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_IStringMatcher_Match()
|
public void RequestMessageCookieMatcher_GetMatchingScore_IStringMatcher_Match()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", false, new ExactMatcher("x"));
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", false, new ExactMatcher("x"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_WithMissingCookie_When_RejectOnMatch_Is_True_Should_Match()
|
public void RequestMessageCookieMatcher_WithMissingCookie_When_RejectOnMatch_Is_True_Should_Match()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "uhuh", false, new ExactMatcher("x"));
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "uhuh", false, new ExactMatcher("x"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_Func_Match()
|
public void RequestMessageCookieMatcher_GetMatchingScore_Func_Match()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
var cookies = new Dictionary<string, string> { { "cook", "x" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(x => x.ContainsKey("cook"));
|
var matcher = new RequestMessageCookieMatcher(x => x.ContainsKey("cook"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieValue()
|
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieValue()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", "test", true);
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "cook", "test", true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieName()
|
public void RequestMessageCookieMatcher_GetMatchingScore_CaseIgnoreForCookieName()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
var cookies = new Dictionary<string, string> { { "cook", "teST" } };
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "CooK", "test", true);
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "CooK", "test", true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,193 +7,192 @@ using WireMock.Owin;
|
|||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.RequestMatchers
|
namespace WireMock.Net.Tests.RequestMatchers;
|
||||||
|
|
||||||
|
public class RequestMessageParamMatcherTests
|
||||||
{
|
{
|
||||||
public class RequestMessageParamMatcherTests
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_IgnoreCaseKeyWithValuesPresentInUrl_And_With1StringValues_Returns1_0()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_IgnoreCaseKeyWithValuesPresentInUrl_And_With1StringValues_Returns1_0()
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "KeY", true, new[] { "test1" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith1ValuePresentInUrl_And_With2Strings_Or_Returns0_5()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.5d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith3ValuesPresentInUrl_And_With1ExactStringWith2Patterns_Returns0_66()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2,test3"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2") });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With1ExactStringWith3Patterns_Returns0_66()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2", "test3") });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2Strings_Returns1_0()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2ExactStringMatchers_Returns1_0()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1"), new ExactMatcher("test2") });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchOnKeyWithValues_PartialMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.5d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithValues_Fails()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKey()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithEmptyArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new string[] { });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuePresentInUrl_MatchOnKey()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue #849
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var options = new WireMockMiddlewareOptions
|
||||||
{
|
{
|
||||||
// Assign
|
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
};
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "KeY", true, new[] { "test1" });
|
var requestMessage = new RequestMessage(options, new UrlDetails("http://localhost?query=SELECT id, value FROM table WHERE id = 1&test=42"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "query", false, "SELECT id, value FROM table WHERE id = 1");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
score.Should().Be(1.0);
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith1ValuePresentInUrl_And_With2Strings_Or_Returns0_5()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(0.5d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith3ValuesPresentInUrl_And_With1ExactStringWith2Patterns_Returns0_66()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2,test3"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2") });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With1ExactStringWith3Patterns_Returns0_66()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1", "test2", "test3") });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsCloseTo(0.66d, 0.1d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2Strings_Returns1_0()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWith2ValuesPresentInUrl_And_With2ExactStringMatchers_Returns1_0()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new IStringMatcher[] { new ExactMatcher("test1"), new ExactMatcher("test2") });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchOnKeyWithValues_PartialMatch()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(0.5d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithValues_Fails()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new[] { "test1", "test2" });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(0.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKey()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithEmptyArray()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false, new string[] { });
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuePresentInUrl_MatchOnKey()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", false);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(score).IsEqualTo(1.0d);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Issue #849
|
|
||||||
[Fact]
|
|
||||||
public void RequestMessageParamMatcher_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
var options = new WireMockMiddlewareOptions
|
|
||||||
{
|
|
||||||
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
|
||||||
};
|
|
||||||
var requestMessage = new RequestMessage(options, new UrlDetails("http://localhost?query=SELECT id, value FROM table WHERE id = 1&test=42"), "GET", "127.0.0.1");
|
|
||||||
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "query", false, "SELECT id, value FROM table WHERE id = 1");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = new RequestMatchResult();
|
|
||||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
score.Should().Be(1.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
ClientIP: ::1,
|
||||||
|
Path: /,
|
||||||
|
AbsolutePath: /,
|
||||||
|
Url: http://localhost/,
|
||||||
|
AbsoluteUrl: http://localhost/,
|
||||||
|
Method: post,
|
||||||
|
BodyAsBytes: AA==,
|
||||||
|
DetectedBodyType: Bytes
|
||||||
|
},
|
||||||
|
Response: {
|
||||||
|
BodyAsBytes: AA==,
|
||||||
|
DetectedBodyType: Bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
ClientIP: ::1,
|
||||||
|
Path: /,
|
||||||
|
AbsolutePath: /,
|
||||||
|
Url: http://localhost/,
|
||||||
|
AbsoluteUrl: http://localhost/,
|
||||||
|
Method: get
|
||||||
|
},
|
||||||
|
Response: {
|
||||||
|
BodyAsFile: test,
|
||||||
|
DetectedBodyType: File
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
ClientIP: ::1,
|
||||||
|
Path: /,
|
||||||
|
AbsolutePath: /,
|
||||||
|
Url: http://localhost/,
|
||||||
|
AbsoluteUrl: http://localhost/,
|
||||||
|
Method: post,
|
||||||
|
BodyAsBytes: AA==,
|
||||||
|
DetectedBodyType: Bytes
|
||||||
|
},
|
||||||
|
Response: {
|
||||||
|
Body: Func<IRequestMessage, string>,
|
||||||
|
DetectedBodyType: String
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
ClientIP: ::1,
|
||||||
|
Path: /,
|
||||||
|
AbsolutePath: /,
|
||||||
|
Url: http://localhost/,
|
||||||
|
AbsoluteUrl: http://localhost/,
|
||||||
|
Method: get
|
||||||
|
},
|
||||||
|
Response: {
|
||||||
|
BodyAsFile: test,
|
||||||
|
DetectedBodyType: File,
|
||||||
|
FaultType: EMPTY_RESPONSE,
|
||||||
|
FaultPercentage: 0.5
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
using FluentAssertions;
|
#if !(NET452 || NET461)
|
||||||
using NFluent;
|
using System.Threading.Tasks;
|
||||||
|
using VerifyTests;
|
||||||
|
using VerifyXunit;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
|
using WireMock.Net.Tests.VerifyExtensions;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
@@ -11,8 +14,15 @@ using Xunit;
|
|||||||
|
|
||||||
namespace WireMock.Net.Tests.Serialization;
|
namespace WireMock.Net.Tests.Serialization;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
public class LogEntryMapperTests
|
public class LogEntryMapperTests
|
||||||
{
|
{
|
||||||
|
private static readonly VerifySettings VerifySettings = new();
|
||||||
|
static LogEntryMapperTests()
|
||||||
|
{
|
||||||
|
VerifySettings.Init<LogEntryMapperTests>();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
private readonly IWireMockMiddlewareOptions _options = new WireMockMiddlewareOptions();
|
||||||
|
|
||||||
private readonly LogEntryMapper _sut;
|
private readonly LogEntryMapper _sut;
|
||||||
@@ -23,7 +33,7 @@ public class LogEntryMapperTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
public Task LogEntryMapper_Map_LogEntry_Check_BodyTypeBytes()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var logEntry = new LogEntry
|
var logEntry = new LogEntry
|
||||||
@@ -51,23 +61,12 @@ public class LogEntryMapperTests
|
|||||||
// Act
|
// Act
|
||||||
var result = _sut.Map(logEntry);
|
var result = _sut.Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Verify
|
||||||
Check.That(result.Request.DetectedBodyType).IsEqualTo("Bytes");
|
return Verifier.Verify(result, VerifySettings);
|
||||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
|
||||||
Check.That(result.Request.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
|
||||||
Check.That(result.Request.Body).IsNull();
|
|
||||||
Check.That(result.Request.BodyAsJson).IsNull();
|
|
||||||
|
|
||||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
|
||||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsNull();
|
|
||||||
Check.That(result.Response.BodyAsBytes).ContainsExactly(new byte[] { 0 });
|
|
||||||
Check.That(result.Response.Body).IsNull();
|
|
||||||
Check.That(result.Response.BodyAsJson).IsNull();
|
|
||||||
Check.That(result.Response.BodyAsFile).IsNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
public Task LogEntryMapper_Map_LogEntry_Check_ResponseBodyTypeFile()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var logEntry = new LogEntry
|
var logEntry = new LogEntry
|
||||||
@@ -86,23 +85,12 @@ public class LogEntryMapperTests
|
|||||||
// Act
|
// Act
|
||||||
var result = _sut.Map(logEntry);
|
var result = _sut.Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Verify
|
||||||
Check.That(result.Request.DetectedBodyType).IsNull();
|
return Verifier.Verify(result, VerifySettings);
|
||||||
Check.That(result.Request.DetectedBodyTypeFromContentType).IsNull();
|
|
||||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
|
||||||
Check.That(result.Request.Body).IsNull();
|
|
||||||
Check.That(result.Request.BodyAsJson).IsNull();
|
|
||||||
|
|
||||||
Check.That(result.Response.DetectedBodyType).IsEqualTo(BodyType.File);
|
|
||||||
Check.That(result.Response.DetectedBodyTypeFromContentType).IsNull();
|
|
||||||
Check.That(result.Request.BodyAsBytes).IsNull();
|
|
||||||
Check.That(result.Response.Body).IsNull();
|
|
||||||
Check.That(result.Response.BodyAsJson).IsNull();
|
|
||||||
Check.That(result.Response.BodyAsFile).IsEqualTo("test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LogEntryMapper_Map_LogEntry_WithFault()
|
public Task LogEntryMapper_Map_LogEntry_WithFault()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var logEntry = new LogEntry
|
var logEntry = new LogEntry
|
||||||
@@ -123,13 +111,12 @@ public class LogEntryMapperTests
|
|||||||
// Act
|
// Act
|
||||||
var result = _sut.Map(logEntry);
|
var result = _sut.Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Verify
|
||||||
result.Response.FaultType.Should().Be("EMPTY_RESPONSE");
|
return Verifier.Verify(result, VerifySettings);
|
||||||
result.Response.FaultPercentage.Should().Be(0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LogEntryMapper_Map_LogEntry_WhenFuncIsUsed_And_DoNotSaveDynamicResponseInLogEntry_Is_True_Should_NotSave_StringResponse()
|
public Task LogEntryMapper_Map_LogEntry_WhenFuncIsUsed_And_DoNotSaveDynamicResponseInLogEntry_Is_True_Should_NotSave_StringResponse()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var options = new WireMockMiddlewareOptions
|
var options = new WireMockMiddlewareOptions
|
||||||
@@ -163,7 +150,8 @@ public class LogEntryMapperTests
|
|||||||
// Act
|
// Act
|
||||||
var result = new LogEntryMapper(options).Map(logEntry);
|
var result = new LogEntryMapper(options).Map(logEntry);
|
||||||
|
|
||||||
// Assert
|
// Verify
|
||||||
result.Response.Body.Should().Be(isFuncUsed);
|
return Verifier.Verify(result, VerifySettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using VerifyTests;
|
||||||
|
using VerifyXunit;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
|
using WireMock.Serialization;
|
||||||
|
using WireMock.Types;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.Serialization;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
|
public partial class MappingConverterTests
|
||||||
|
{
|
||||||
|
|
||||||
|
[ModuleInitializer]
|
||||||
|
public static void ModuleInitializer()
|
||||||
|
{
|
||||||
|
VerifierSettings.DontScrubGuids();
|
||||||
|
VerifierSettings.DontScrubDateTimes();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task ToCSharpCode_With_Builder_And_AddStartIsTrue()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var mapping = CreateMapping();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||||
|
{
|
||||||
|
AddStart = true,
|
||||||
|
ConverterType = MappingConverterType.Builder
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
code.Should().NotBeEmpty();
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task ToCSharpCode_With_Builder_And_AddStartIsFalse()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var mapping = CreateMapping();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||||
|
{
|
||||||
|
AddStart = false,
|
||||||
|
ConverterType = MappingConverterType.Builder
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
code.Should().NotBeEmpty();
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task ToCSharpCode_With_Server_And_AddStartIsTrue()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var mapping = CreateMapping();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||||
|
{
|
||||||
|
AddStart = true,
|
||||||
|
ConverterType = MappingConverterType.Server
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
code.Should().NotBeEmpty();
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task ToCSharpCode_With_Server_And_AddStartIsFalse()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var mapping = CreateMapping();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var code = _sut.ToCSharpCode(mapping, new MappingConverterSettings
|
||||||
|
{
|
||||||
|
AddStart = false,
|
||||||
|
ConverterType = MappingConverterType.Server
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
code.Should().NotBeEmpty();
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mapping CreateMapping()
|
||||||
|
{
|
||||||
|
var guid = new Guid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc");
|
||||||
|
var request = Request.Create()
|
||||||
|
.UsingGet()
|
||||||
|
.WithPath("test_path")
|
||||||
|
.WithParam("q", "42")
|
||||||
|
.WithClientIP("112.123.100.99")
|
||||||
|
.WithHeader("h-key", "h-value")
|
||||||
|
.WithCookie("c-key", "c-value")
|
||||||
|
.WithBody("b");
|
||||||
|
var response = Response.Create()
|
||||||
|
.WithHeader("Keep-Alive", "test")
|
||||||
|
.WithBody("bbb")
|
||||||
|
.WithDelay(12345)
|
||||||
|
.WithTransformer();
|
||||||
|
|
||||||
|
return new Mapping(guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
builder
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingMethod("GET")
|
||||||
|
.WithPath("test_path")
|
||||||
|
.WithParam("q", "42")
|
||||||
|
.WithClientIP("112.123.100.99")
|
||||||
|
.WithHeader("h-key", "h-value", true)
|
||||||
|
.WithCookie("c-key", "c-value", true)
|
||||||
|
.WithBody("b")
|
||||||
|
)
|
||||||
|
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithHeader("Keep-Alive)", "test")
|
||||||
|
.WithBody("bbb")
|
||||||
|
.WithDelay(12345)
|
||||||
|
.WithTransformer()
|
||||||
|
);
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
var builder = new MappingBuilder();
|
||||||
|
builder
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingMethod("GET")
|
||||||
|
.WithPath("test_path")
|
||||||
|
.WithParam("q", "42")
|
||||||
|
.WithClientIP("112.123.100.99")
|
||||||
|
.WithHeader("h-key", "h-value", true)
|
||||||
|
.WithCookie("c-key", "c-value", true)
|
||||||
|
.WithBody("b")
|
||||||
|
)
|
||||||
|
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithHeader("Keep-Alive)", "test")
|
||||||
|
.WithBody("bbb")
|
||||||
|
.WithDelay(12345)
|
||||||
|
.WithTransformer()
|
||||||
|
);
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingMethod("GET")
|
||||||
|
.WithPath("test_path")
|
||||||
|
.WithParam("q", "42")
|
||||||
|
.WithClientIP("112.123.100.99")
|
||||||
|
.WithHeader("h-key", "h-value", true)
|
||||||
|
.WithCookie("c-key", "c-value", true)
|
||||||
|
.WithBody("b")
|
||||||
|
)
|
||||||
|
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithHeader("Keep-Alive)", "test")
|
||||||
|
.WithBody("bbb")
|
||||||
|
.WithDelay(12345)
|
||||||
|
.WithTransformer()
|
||||||
|
);
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
var server = WireMockServer.Start();
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.UsingMethod("GET")
|
||||||
|
.WithPath("test_path")
|
||||||
|
.WithParam("q", "42")
|
||||||
|
.WithClientIP("112.123.100.99")
|
||||||
|
.WithHeader("h-key", "h-value", true)
|
||||||
|
.WithCookie("c-key", "c-value", true)
|
||||||
|
.WithBody("b")
|
||||||
|
)
|
||||||
|
.WithGuid("8e7b9ab7-e18e-4502-8bc9-11e6679811cc")
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithHeader("Keep-Alive)", "test")
|
||||||
|
.WithBody("bbb")
|
||||||
|
.WithDelay(12345)
|
||||||
|
.WithTransformer()
|
||||||
|
);
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Priority: 42,
|
||||||
|
Request: {},
|
||||||
|
Response: {
|
||||||
|
Delay: 1000
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Priority: 42,
|
||||||
|
Request: {},
|
||||||
|
Response: {
|
||||||
|
BodyAsJson: {
|
||||||
|
x: x
|
||||||
|
},
|
||||||
|
UseTransformer: true,
|
||||||
|
TransformerType: Handlebars,
|
||||||
|
TransformerReplaceNodeOptions: Evaluate
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Priority: 42,
|
||||||
|
Request: {},
|
||||||
|
Response: {
|
||||||
|
MinimumRandomDelay: 1000,
|
||||||
|
MaximumRandomDelay: 2000
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Priority: 42,
|
||||||
|
Request: {},
|
||||||
|
Response: {
|
||||||
|
MinimumRandomDelay: 1000,
|
||||||
|
MaximumRandomDelay: 60000
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
TimeSettings: {
|
||||||
|
Start: 2023-01-14 15:16:17,
|
||||||
|
End: 2023-01-14 15:17:57,
|
||||||
|
TTL: 100
|
||||||
|
},
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Priority: 42,
|
||||||
|
Request: {},
|
||||||
|
Response: {},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: my-title,
|
||||||
|
Description: my-description,
|
||||||
|
Request: {},
|
||||||
|
Response: {},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Request: {},
|
||||||
|
Response: {},
|
||||||
|
Webhooks: [
|
||||||
|
{
|
||||||
|
Request: {
|
||||||
|
Url: https://test1.com,
|
||||||
|
Method: post,
|
||||||
|
Headers: {
|
||||||
|
One: x
|
||||||
|
},
|
||||||
|
Body: 1,
|
||||||
|
TransformerReplaceNodeOptions: EvaluateAndTryToConvert
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Request: {
|
||||||
|
Url: https://test2.com,
|
||||||
|
Method: post,
|
||||||
|
Headers: {
|
||||||
|
First: x,
|
||||||
|
Second: a, b
|
||||||
|
},
|
||||||
|
Body: 2,
|
||||||
|
TransformerReplaceNodeOptions: EvaluateAndTryToConvert
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
UseWebhooksFireAndForget: true
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
Guid: c8eeaf99-d5c4-4341-8543-4597c3fd40d9,
|
||||||
|
UpdatedAt: 2022-12-04 11:12:13,
|
||||||
|
Title: ,
|
||||||
|
Description: ,
|
||||||
|
Request: {},
|
||||||
|
Response: {},
|
||||||
|
Webhook: {
|
||||||
|
Request: {
|
||||||
|
Url: https://test.com,
|
||||||
|
Method: post,
|
||||||
|
Headers: {
|
||||||
|
Multi: a, b,
|
||||||
|
Single: x
|
||||||
|
},
|
||||||
|
Body: b,
|
||||||
|
TransformerReplaceNodeOptions: EvaluateAndTryToConvert
|
||||||
|
}
|
||||||
|
},
|
||||||
|
UseWebhooksFireAndForget: false
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
using VerifyTests;
|
||||||
|
using VerifyXunit;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
@@ -13,9 +18,10 @@ using Xunit;
|
|||||||
|
|
||||||
namespace WireMock.Net.Tests.Serialization;
|
namespace WireMock.Net.Tests.Serialization;
|
||||||
|
|
||||||
public class MappingConverterTests
|
public partial class MappingConverterTests
|
||||||
{
|
{
|
||||||
private readonly DateTime _updatedAt = new(2022, 12, 4);
|
private readonly Guid _guid = new("c8eeaf99-d5c4-4341-8543-4597c3fd40d9");
|
||||||
|
private readonly DateTime _updatedAt = new(2022, 12, 4, 11, 12, 13);
|
||||||
private readonly WireMockServerSettings _settings = new();
|
private readonly WireMockServerSettings _settings = new();
|
||||||
|
|
||||||
private readonly MappingConverter _sut;
|
private readonly MappingConverter _sut;
|
||||||
@@ -26,7 +32,7 @@ public class MappingConverterTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_With_SingleWebHook()
|
public Task ToMappingModel_With_SingleWebHook()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
@@ -53,7 +59,7 @@ public class MappingConverterTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, false, null);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, false, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -74,10 +80,13 @@ public class MappingConverterTests
|
|||||||
model.Webhook.Request.Headers.Should().HaveCount(2);
|
model.Webhook.Request.Headers.Should().HaveCount(2);
|
||||||
model.Webhook.Request.Body.Should().Be("b");
|
model.Webhook.Request.Body.Should().Be("b");
|
||||||
model.Webhook.Request.BodyAsJson.Should().BeNull();
|
model.Webhook.Request.BodyAsJson.Should().BeNull();
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_With_MultipleWebHooks()
|
public Task ToMappingModel_With_MultipleWebHooks()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
@@ -123,7 +132,7 @@ public class MappingConverterTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, true, null);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, true, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -148,17 +157,20 @@ public class MappingConverterTests
|
|||||||
model.Webhooks[1].Request.Url.Should().Be("https://test2.com");
|
model.Webhooks[1].Request.Url.Should().Be("https://test2.com");
|
||||||
model.Webhooks[1].Request.Headers.Should().HaveCount(2);
|
model.Webhooks[1].Request.Headers.Should().HaveCount(2);
|
||||||
model.Webhooks[1].Request.Body.Should().Be("2");
|
model.Webhooks[1].Request.Body.Should().Be("2");
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithTitle_And_Description_ReturnsCorrectModel()
|
public Task ToMappingModel_WithTitle_And_Description_ReturnsCorrectModel()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var title = "my-title";
|
var title = "my-title";
|
||||||
var description = "my-description";
|
var description = "my-description";
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create();
|
var response = Response.Create();
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, title, description, null, _settings, request, response, 0, null, null, null, null, null, false, null);
|
var mapping = new Mapping(_guid, _updatedAt, title, description, null, _settings, request, response, 0, null, null, null, null, null, false, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -167,15 +179,18 @@ public class MappingConverterTests
|
|||||||
model.Should().NotBeNull();
|
model.Should().NotBeNull();
|
||||||
model.Title.Should().Be(title);
|
model.Title.Should().Be(title);
|
||||||
model.Description.Should().Be(description);
|
model.Description.Should().Be(description);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithPriority_ReturnsPriority()
|
public Task ToMappingModel_WithPriority_ReturnsPriority()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -184,13 +199,16 @@ public class MappingConverterTests
|
|||||||
model.Should().NotBeNull();
|
model.Should().NotBeNull();
|
||||||
model.Priority.Should().Be(42);
|
model.Priority.Should().Be(42);
|
||||||
model.Response.UseTransformer.Should().BeTrue();
|
model.Response.UseTransformer.Should().BeTrue();
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithTimeSettings_ReturnsCorrectTimeSettings()
|
public Task ToMappingModel_WithTimeSettings_ReturnsCorrectTimeSettings()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var start = DateTime.Now;
|
var start = new DateTime(2023, 1, 14, 15, 16, 17);
|
||||||
var ttl = 100;
|
var ttl = 100;
|
||||||
var end = start.AddSeconds(ttl);
|
var end = start.AddSeconds(ttl);
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
@@ -201,7 +219,7 @@ public class MappingConverterTests
|
|||||||
End = end,
|
End = end,
|
||||||
TTL = ttl
|
TTL = ttl
|
||||||
};
|
};
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, timeSettings);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, timeSettings);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -212,6 +230,9 @@ public class MappingConverterTests
|
|||||||
model.TimeSettings!.Start.Should().Be(start);
|
model.TimeSettings!.Start.Should().Be(start);
|
||||||
model.TimeSettings.End.Should().Be(end);
|
model.TimeSettings.End.Should().Be(end);
|
||||||
model.TimeSettings.TTL.Should().Be(ttl);
|
model.TimeSettings.TTL.Should().Be(ttl);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -241,13 +262,13 @@ public class MappingConverterTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithDelayAsMilleSeconds_ReturnsCorrectModel()
|
public Task ToMappingModel_WithDelayAsMilleSeconds_ReturnsCorrectModel()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var delay = 1000;
|
var delay = 1000;
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithDelay(delay);
|
var response = Response.Create().WithDelay(delay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -255,16 +276,19 @@ public class MappingConverterTests
|
|||||||
// Assert
|
// Assert
|
||||||
model.Should().NotBeNull();
|
model.Should().NotBeNull();
|
||||||
model.Response.Delay.Should().Be(delay);
|
model.Response.Delay.Should().Be(delay);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithRandomMinimumDelay_ReturnsCorrectModel()
|
public Task ToMappingModel_WithRandomMinimumDelay_ReturnsCorrectModel()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
int minimumDelay = 1000;
|
int minimumDelay = 1000;
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithRandomDelay(minimumDelay);
|
var response = Response.Create().WithRandomDelay(minimumDelay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -274,17 +298,20 @@ public class MappingConverterTests
|
|||||||
model.Response.Delay.Should().BeNull();
|
model.Response.Delay.Should().BeNull();
|
||||||
model.Response.MinimumRandomDelay.Should().Be(minimumDelay);
|
model.Response.MinimumRandomDelay.Should().Be(minimumDelay);
|
||||||
model.Response.MaximumRandomDelay.Should().Be(60_000);
|
model.Response.MaximumRandomDelay.Should().Be(60_000);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMappingModel_WithRandomDelay_ReturnsCorrectModel()
|
public Task ToMappingModel_WithRandomDelay_ReturnsCorrectModel()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
int minimumDelay = 1000;
|
int minimumDelay = 1000;
|
||||||
int maximumDelay = 2000;
|
int maximumDelay = 2000;
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay);
|
var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay);
|
||||||
var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
var mapping = new Mapping(_guid, _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -294,5 +321,9 @@ public class MappingConverterTests
|
|||||||
model.Response.Delay.Should().BeNull();
|
model.Response.Delay.Should().BeNull();
|
||||||
model.Response.MinimumRandomDelay.Should().Be(minimumDelay);
|
model.Response.MinimumRandomDelay.Should().Be(minimumDelay);
|
||||||
model.Response.MaximumRandomDelay.Should().Be(maximumDelay);
|
model.Response.MaximumRandomDelay.Should().Be(maximumDelay);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
Guid: ff55ac0a-fea9-4d7b-be74-5e483a2c1305,
|
||||||
|
UpdatedAt: 2022-12-04,
|
||||||
|
Title: my title,
|
||||||
|
Description: my description,
|
||||||
|
Priority: -2000000,
|
||||||
|
Request: {
|
||||||
|
Path: {
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: WildcardMatcher,
|
||||||
|
Pattern: x,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Methods: [
|
||||||
|
POST
|
||||||
|
],
|
||||||
|
Headers: [
|
||||||
|
{
|
||||||
|
Name: Content-Type,
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: ContentTypeMatcher,
|
||||||
|
Pattern: text/plain,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Cookies: [
|
||||||
|
{
|
||||||
|
Name: c,
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: WildcardMatcher,
|
||||||
|
Pattern: x,
|
||||||
|
IgnoreCase: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Params: [
|
||||||
|
{
|
||||||
|
Name: p1,
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: ExactMatcher,
|
||||||
|
Pattern: p1-v,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: p2,
|
||||||
|
Matchers: [
|
||||||
|
{
|
||||||
|
Name: ExactMatcher,
|
||||||
|
Pattern: p2-v,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
Body: {
|
||||||
|
Matcher: {
|
||||||
|
Name: RegexMatcher,
|
||||||
|
Pattern: <RequestType>Auth</RequestType>,
|
||||||
|
IgnoreCase: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Response: {}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Newtonsoft.Json;
|
using VerifyTests;
|
||||||
using System.IO;
|
using VerifyXunit;
|
||||||
using FluentAssertions;
|
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
@@ -12,6 +14,7 @@ using Xunit;
|
|||||||
|
|
||||||
namespace WireMock.Net.Tests.Serialization;
|
namespace WireMock.Net.Tests.Serialization;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
public class ProxyMappingConverterTests
|
public class ProxyMappingConverterTests
|
||||||
{
|
{
|
||||||
private readonly WireMockServerSettings _settings = new();
|
private readonly WireMockServerSettings _settings = new();
|
||||||
@@ -33,8 +36,15 @@ public class ProxyMappingConverterTests
|
|||||||
_sut = new ProxyMappingConverter(_settings, guidUtilsMock.Object, dateTimeUtilsMock.Object);
|
_sut = new ProxyMappingConverter(_settings, guidUtilsMock.Object, dateTimeUtilsMock.Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ModuleInitializer]
|
||||||
|
public static void ModuleInitializer()
|
||||||
|
{
|
||||||
|
VerifierSettings.DontScrubGuids();
|
||||||
|
VerifierSettings.DontScrubDateTimes();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToMapping_UseDefinedRequestMatchers_True()
|
public Task ToMapping_UseDefinedRequestMatchers_True()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var proxyAndRecordSettings = new ProxyAndRecordSettings
|
var proxyAndRecordSettings = new ProxyAndRecordSettings
|
||||||
@@ -49,7 +59,7 @@ public class ProxyMappingConverterTests
|
|||||||
.WithParam("p2", "p2-v")
|
.WithParam("p2", "p2-v")
|
||||||
.WithHeader("Content-Type", new ContentTypeMatcher("text/plain"))
|
.WithHeader("Content-Type", new ContentTypeMatcher("text/plain"))
|
||||||
.WithCookie("c", "x")
|
.WithCookie("c", "x")
|
||||||
.WithBody(new RegexMatcher("<RequestType>Auth</RequestType"));
|
.WithBody(new RegexMatcher("<RequestType>Auth</RequestType>"));
|
||||||
|
|
||||||
var mappingMock = new Mock<IMapping>();
|
var mappingMock = new Mock<IMapping>();
|
||||||
mappingMock.SetupGet(m => m.RequestMatcher).Returns(request);
|
mappingMock.SetupGet(m => m.RequestMatcher).Returns(request);
|
||||||
@@ -65,9 +75,9 @@ public class ProxyMappingConverterTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var model = _mappingConverter.ToMappingModel(proxyMapping);
|
var model = _mappingConverter.ToMappingModel(proxyMapping);
|
||||||
var json = JsonConvert.SerializeObject(model, JsonSerializationConstants.JsonSerializerSettingsDefault);
|
|
||||||
var expected = File.ReadAllText(Path.Combine("../../../", "Serialization", "files", "proxy.json"));
|
|
||||||
|
|
||||||
json.Should().Be(expected);
|
// Verify
|
||||||
|
return Verifier.Verify(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
Url: https://localhost,
|
||||||
|
Method: get,
|
||||||
|
Headers: {
|
||||||
|
x: [
|
||||||
|
y
|
||||||
|
]
|
||||||
|
},
|
||||||
|
BodyData: {
|
||||||
|
BodyAsJson: {
|
||||||
|
n: 12345
|
||||||
|
},
|
||||||
|
DetectedBodyType: Json,
|
||||||
|
DetectedBodyTypeFromContentType: Bytes
|
||||||
|
},
|
||||||
|
Delay: 4,
|
||||||
|
MinimumRandomDelay: 5,
|
||||||
|
MaximumRandomDelay: 6
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
Url: https://localhost,
|
||||||
|
Method: get,
|
||||||
|
Headers: {
|
||||||
|
x: [
|
||||||
|
y
|
||||||
|
]
|
||||||
|
},
|
||||||
|
BodyData: {
|
||||||
|
BodyAsString: test,
|
||||||
|
DetectedBodyType: String,
|
||||||
|
DetectedBodyTypeFromContentType: Bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
Url: https://localhost,
|
||||||
|
Method: get,
|
||||||
|
Headers: {
|
||||||
|
x: [
|
||||||
|
y
|
||||||
|
]
|
||||||
|
},
|
||||||
|
BodyData: {
|
||||||
|
BodyAsString: test,
|
||||||
|
DetectedBodyType: String,
|
||||||
|
DetectedBodyTypeFromContentType: Bytes
|
||||||
|
},
|
||||||
|
UseTransformer: true,
|
||||||
|
TransformerReplaceNodeOptions: Evaluate
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
Request: {
|
||||||
|
Url: https://localhost,
|
||||||
|
Method: get,
|
||||||
|
Headers: {
|
||||||
|
x: y
|
||||||
|
},
|
||||||
|
BodyAsJson: {
|
||||||
|
n: 12345
|
||||||
|
},
|
||||||
|
TransformerReplaceNodeOptions: EvaluateAndTryToConvert,
|
||||||
|
Delay: 4,
|
||||||
|
MinimumRandomDelay: 5,
|
||||||
|
MaximumRandomDelay: 6
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using FluentAssertions;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using VerifyTests;
|
||||||
|
using VerifyXunit;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
@@ -9,10 +13,18 @@ using Xunit;
|
|||||||
|
|
||||||
namespace WireMock.Net.Tests.Serialization;
|
namespace WireMock.Net.Tests.Serialization;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
public class WebhookMapperTests
|
public class WebhookMapperTests
|
||||||
{
|
{
|
||||||
|
[ModuleInitializer]
|
||||||
|
public static void ModuleInitializer()
|
||||||
|
{
|
||||||
|
VerifierSettings.DontScrubGuids();
|
||||||
|
VerifierSettings.DontScrubDateTimes();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsFalse()
|
public Task WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsFalse()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var model = new WebhookModel
|
var model = new WebhookModel
|
||||||
@@ -32,17 +44,12 @@ public class WebhookMapperTests
|
|||||||
|
|
||||||
var result = WebhookMapper.Map(model);
|
var result = WebhookMapper.Map(model);
|
||||||
|
|
||||||
result.Request.Url.Should().Be("https://localhost");
|
// Verify
|
||||||
result.Request.Method.Should().Be("get");
|
return Verifier.Verify(result);
|
||||||
result.Request.Headers.Should().HaveCount(1);
|
|
||||||
result.Request.BodyData!.BodyAsJson.Should().BeNull();
|
|
||||||
result.Request.BodyData.BodyAsString.Should().Be("test");
|
|
||||||
result.Request.BodyData.DetectedBodyType.Should().Be(BodyType.String);
|
|
||||||
result.Request.UseTransformer.Should().BeNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsTrue()
|
public Task WebhookMapper_Map_WebhookModel_BodyAsString_And_UseTransformerIsTrue()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var model = new WebhookModel
|
var model = new WebhookModel
|
||||||
@@ -62,18 +69,12 @@ public class WebhookMapperTests
|
|||||||
|
|
||||||
var result = WebhookMapper.Map(model);
|
var result = WebhookMapper.Map(model);
|
||||||
|
|
||||||
result.Request.Url.Should().Be("https://localhost");
|
// Verify
|
||||||
result.Request.Method.Should().Be("get");
|
return Verifier.Verify(result);
|
||||||
result.Request.Headers.Should().HaveCount(1);
|
|
||||||
result.Request.BodyData!.BodyAsJson.Should().BeNull();
|
|
||||||
result.Request.BodyData.BodyAsString.Should().Be("test");
|
|
||||||
result.Request.BodyData.DetectedBodyType.Should().Be(BodyType.String);
|
|
||||||
result.Request.UseTransformer.Should().BeTrue();
|
|
||||||
result.Request.TransformerType.Should().Be(TransformerType.Handlebars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WebhookMapper_Map_WebhookModel_BodyAsJson()
|
public Task WebhookMapper_Map_WebhookModel_BodyAsJson()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var model = new WebhookModel
|
var model = new WebhookModel
|
||||||
@@ -95,19 +96,12 @@ public class WebhookMapperTests
|
|||||||
|
|
||||||
var result = WebhookMapper.Map(model);
|
var result = WebhookMapper.Map(model);
|
||||||
|
|
||||||
result.Request.Url.Should().Be("https://localhost");
|
// Verify
|
||||||
result.Request.Method.Should().Be("get");
|
return Verifier.Verify(result);
|
||||||
result.Request.Headers.Should().HaveCount(1);
|
|
||||||
result.Request.BodyData!.BodyAsString.Should().BeNull();
|
|
||||||
result.Request.BodyData.BodyAsJson.Should().NotBeNull();
|
|
||||||
result.Request.BodyData.DetectedBodyType.Should().Be(BodyType.Json);
|
|
||||||
result.Request.Delay.Should().Be(4);
|
|
||||||
result.Request.MinimumRandomDelay.Should().Be(5);
|
|
||||||
result.Request.MaximumRandomDelay.Should().Be(6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WebhookMapper_Map_Webhook_To_Model()
|
public Task WebhookMapper_Map_Webhook_To_Model()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var webhook = new Webhook
|
var webhook = new Webhook
|
||||||
@@ -134,12 +128,8 @@ public class WebhookMapperTests
|
|||||||
|
|
||||||
var result = WebhookMapper.Map(webhook);
|
var result = WebhookMapper.Map(webhook);
|
||||||
|
|
||||||
result.Request.Url.Should().Be("https://localhost");
|
// Verify
|
||||||
result.Request.Method.Should().Be("get");
|
return Verifier.Verify(result);
|
||||||
result.Request.Headers.Should().HaveCount(1);
|
|
||||||
result.Request.BodyAsJson.Should().NotBeNull();
|
|
||||||
result.Request.Delay.Should().Be(4);
|
|
||||||
result.Request.MinimumRandomDelay.Should().Be(5);
|
|
||||||
result.Request.MaximumRandomDelay.Should().Be(6);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
{
|
|
||||||
"Guid": "ff55ac0a-fea9-4d7b-be74-5e483a2c1305",
|
|
||||||
"UpdatedAt": "2022-12-04T00:00:00",
|
|
||||||
"Title": "my title",
|
|
||||||
"Description": "my description",
|
|
||||||
"Priority": -2000000,
|
|
||||||
"Request": {
|
|
||||||
"Path": {
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "WildcardMatcher",
|
|
||||||
"Pattern": "x",
|
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"Methods": [
|
|
||||||
"POST"
|
|
||||||
],
|
|
||||||
"Headers": [
|
|
||||||
{
|
|
||||||
"Name": "Content-Type",
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "ContentTypeMatcher",
|
|
||||||
"Pattern": "text/plain",
|
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Cookies": [
|
|
||||||
{
|
|
||||||
"Name": "c",
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "WildcardMatcher",
|
|
||||||
"Pattern": "x",
|
|
||||||
"IgnoreCase": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Params": [
|
|
||||||
{
|
|
||||||
"Name": "p1",
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "ExactMatcher",
|
|
||||||
"Pattern": "p1-v",
|
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "p2",
|
|
||||||
"Matchers": [
|
|
||||||
{
|
|
||||||
"Name": "ExactMatcher",
|
|
||||||
"Pattern": "p2-v",
|
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Body": {
|
|
||||||
"Matcher": {
|
|
||||||
"Name": "RegexMatcher",
|
|
||||||
"Pattern": "<RequestType>Auth</RequestType",
|
|
||||||
"IgnoreCase": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Response": {}
|
|
||||||
}
|
|
||||||
@@ -9,109 +9,109 @@ using WireMock.Types;
|
|||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Util
|
namespace WireMock.Net.Tests.Util;
|
||||||
|
|
||||||
|
public class BodyParserTests
|
||||||
{
|
{
|
||||||
public class BodyParserTests
|
[Theory]
|
||||||
|
[InlineData("application/json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||||
|
[InlineData("application/json; charset=utf-8", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||||
|
[InlineData("application/json; odata.metadata=minimal", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||||
|
[InlineData("application/vnd.api+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||||
|
[InlineData("application/vnd.test+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
||||||
|
public async Task BodyParser_Parse_ContentTypeJson(string contentType, string bodyAsJson, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||||
{
|
{
|
||||||
[Theory]
|
// Arrange
|
||||||
[InlineData("application/json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
var bodyParserSettings = new BodyParserSettings
|
||||||
[InlineData("application/json; charset=utf-8", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
|
||||||
[InlineData("application/json; odata.metadata=minimal", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
|
||||||
[InlineData("application/vnd.api+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
|
||||||
[InlineData("application/vnd.test+json", "{ \"x\": 1 }", BodyType.Json, BodyType.Json)]
|
|
||||||
public async Task BodyParser_Parse_ContentTypeJson(string contentType, string bodyAsJson, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
|
||||||
{
|
{
|
||||||
// Arrange
|
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsJson)),
|
||||||
var bodyParserSettings = new BodyParserSettings
|
ContentType = contentType,
|
||||||
{
|
DeserializeJson = true
|
||||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsJson)),
|
};
|
||||||
ContentType = contentType,
|
|
||||||
DeserializeJson = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(body.BodyAsBytes).IsNotNull();
|
Check.That(body.BodyAsBytes).IsNotNull();
|
||||||
Check.That(body.BodyAsJson).IsNotNull();
|
Check.That(body.BodyAsJson).IsNotNull();
|
||||||
Check.That(body.BodyAsString).Equals(bodyAsJson);
|
Check.That(body.BodyAsString).Equals(bodyAsJson);
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("application/xml", "<xml>hello</xml>", BodyType.String, BodyType.String)]
|
[InlineData("application/xml", "<xml>hello</xml>", BodyType.String, BodyType.String)]
|
||||||
[InlineData("something", "hello", BodyType.String, BodyType.Bytes)]
|
[InlineData("something", "hello", BodyType.String, BodyType.Bytes)]
|
||||||
public async Task BodyParser_Parse_ContentTypeString(string contentType, string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
public async Task BodyParser_Parse_ContentTypeString(string contentType, string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
{
|
||||||
// Arrange
|
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
||||||
var bodyParserSettings = new BodyParserSettings
|
ContentType = contentType,
|
||||||
{
|
DeserializeJson = true
|
||||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
};
|
||||||
ContentType = contentType,
|
|
||||||
DeserializeJson = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(body.BodyAsBytes).IsNotNull();
|
Check.That(body.BodyAsBytes).IsNotNull();
|
||||||
Check.That(body.BodyAsJson).IsNull();
|
Check.That(body.BodyAsJson).IsNull();
|
||||||
Check.That(body.BodyAsString).Equals(bodyAsString);
|
Check.That(body.BodyAsString).Equals(bodyAsString);
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.Json)]
|
[InlineData(new byte[] { 34, 97, 34 }, BodyType.Json)]
|
||||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
[InlineData(new byte[] { 97 }, BodyType.String)]
|
||||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
||||||
public async Task BodyParser_Parse_DetectedBodyType(byte[] content, BodyType detectedBodyType)
|
public async Task BodyParser_Parse_DetectedBodyType(byte[] content, BodyType detectedBodyType)
|
||||||
|
{
|
||||||
|
// arrange
|
||||||
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
{
|
||||||
// arrange
|
Stream = new MemoryStream(content),
|
||||||
var bodyParserSettings = new BodyParserSettings
|
ContentType = null,
|
||||||
{
|
DeserializeJson = true
|
||||||
Stream = new MemoryStream(content),
|
};
|
||||||
ContentType = null,
|
|
||||||
DeserializeJson = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// act
|
// act
|
||||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.String)]
|
[InlineData(new byte[] { 34, 97, 34 }, BodyType.String)]
|
||||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
[InlineData(new byte[] { 97 }, BodyType.String)]
|
||||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
||||||
public async Task BodyParser_Parse_DetectedBodyTypeNoJsonParsing(byte[] content, BodyType detectedBodyType)
|
public async Task BodyParser_Parse_DetectedBodyTypeNoJsonParsing(byte[] content, BodyType detectedBodyType)
|
||||||
|
{
|
||||||
|
// arrange
|
||||||
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
{
|
||||||
// arrange
|
Stream = new MemoryStream(content),
|
||||||
var bodyParserSettings = new BodyParserSettings
|
ContentType = null,
|
||||||
{
|
DeserializeJson = false
|
||||||
Stream = new MemoryStream(content),
|
};
|
||||||
ContentType = null,
|
|
||||||
DeserializeJson = false
|
|
||||||
};
|
|
||||||
|
|
||||||
// act
|
// act
|
||||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BodyParser_Parse_WithUTF8EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
public async Task BodyParser_Parse_WithUTF8EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string contentType = "multipart/form-data";
|
string contentType = "multipart/form-data";
|
||||||
string body = @"
|
string body = @"
|
||||||
|
|
||||||
-----------------------------9051914041544843365972754266
|
-----------------------------9051914041544843365972754266
|
||||||
Content-Disposition: form-data; name=""text""
|
Content-Disposition: form-data; name=""text""
|
||||||
@@ -131,163 +131,162 @@ Content-Type: text/html
|
|||||||
|
|
||||||
-----------------------------9051914041544843365972754266--";
|
-----------------------------9051914041544843365972754266--";
|
||||||
|
|
||||||
var bodyParserSettings = new BodyParserSettings
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
|
||||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
|
||||||
ContentType = contentType,
|
|
||||||
DeserializeJson = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.String);
|
|
||||||
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
|
||||||
Check.That(result.BodyAsBytes).IsNotNull();
|
|
||||||
Check.That(result.BodyAsJson).IsNull();
|
|
||||||
Check.That(result.BodyAsString).IsNotNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task BodyParser_Parse_WithUTF16EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
|
||||||
{
|
{
|
||||||
// Arrange
|
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
||||||
string contentType = "multipart/form-data";
|
ContentType = contentType,
|
||||||
string body = char.ConvertFromUtf32(0x1D161); //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
|
DeserializeJson = true
|
||||||
var bodyParserSettings = new BodyParserSettings
|
};
|
||||||
{
|
|
||||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
|
||||||
ContentType = contentType,
|
|
||||||
DeserializeJson = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.String);
|
||||||
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
||||||
Check.That(result.BodyAsBytes).IsNotNull();
|
Check.That(result.BodyAsBytes).IsNotNull();
|
||||||
Check.That(result.BodyAsJson).IsNull();
|
Check.That(result.BodyAsJson).IsNull();
|
||||||
Check.That(result.BodyAsString).IsNull();
|
Check.That(result.BodyAsString).IsNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Fact]
|
||||||
[InlineData("hello", BodyType.String, BodyType.Bytes)]
|
public async Task BodyParser_Parse_WithUTF16EncodingAndContentTypeMultipart_DetectedBodyTypeEqualsString()
|
||||||
public async Task BodyParser_Parse_ContentTypeIsNull(string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
{
|
||||||
|
// Arrange
|
||||||
|
string contentType = "multipart/form-data";
|
||||||
|
string body = char.ConvertFromUtf32(0x1D161); //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
|
||||||
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
{
|
||||||
// Arrange
|
Stream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
|
||||||
var bodyParserSettings = new BodyParserSettings
|
ContentType = contentType,
|
||||||
{
|
DeserializeJson = true
|
||||||
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
};
|
||||||
ContentType = null,
|
|
||||||
DeserializeJson = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(body.BodyAsBytes).IsNotNull();
|
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||||
Check.That(body.BodyAsJson).IsNull();
|
Check.That(result.DetectedBodyTypeFromContentType).IsEqualTo(BodyType.MultiPart);
|
||||||
Check.That(body.BodyAsString).Equals(bodyAsString);
|
Check.That(result.BodyAsBytes).IsNotNull();
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
Check.That(result.BodyAsJson).IsNull();
|
||||||
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
Check.That(result.BodyAsString).IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("gzip")]
|
[InlineData("hello", BodyType.String, BodyType.Bytes)]
|
||||||
[InlineData("deflate")]
|
public async Task BodyParser_Parse_ContentTypeIsNull(string bodyAsString, BodyType detectedBodyType, BodyType detectedBodyTypeFromContentType)
|
||||||
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_True_Should_Decompress(string compression)
|
{
|
||||||
|
// Arrange
|
||||||
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
{
|
||||||
// Arrange
|
Stream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString)),
|
||||||
var bytes = Encoding.ASCII.GetBytes("0");
|
ContentType = null,
|
||||||
var compressed = CompressionUtils.Compress(compression, bytes);
|
DeserializeJson = true
|
||||||
var bodyParserSettings = new BodyParserSettings
|
};
|
||||||
{
|
|
||||||
Stream = new MemoryStream(compressed),
|
|
||||||
ContentType = "text/plain",
|
|
||||||
DeserializeJson = false,
|
|
||||||
ContentEncoding = compression.ToUpperInvariant(),
|
|
||||||
DecompressGZipAndDeflate = true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.DetectedBodyType.Should().Be(BodyType.String);
|
Check.That(body.BodyAsBytes).IsNotNull();
|
||||||
result.DetectedBodyTypeFromContentType.Should().Be(BodyType.String);
|
Check.That(body.BodyAsJson).IsNull();
|
||||||
result.BodyAsBytes.Should().BeEquivalentTo(new byte[] { 48 });
|
Check.That(body.BodyAsString).Equals(bodyAsString);
|
||||||
result.BodyAsJson.Should().BeNull();
|
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||||
result.BodyAsString.Should().Be("0");
|
Check.That(body.DetectedBodyTypeFromContentType).IsEqualTo(detectedBodyTypeFromContentType);
|
||||||
result.DetectedCompression.Should().Be(compression);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("gzip")]
|
[InlineData("gzip")]
|
||||||
[InlineData("deflate")]
|
[InlineData("deflate")]
|
||||||
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_False_Should_Not_Decompress(string compression)
|
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_True_Should_Decompress(string compression)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var bytes = Encoding.ASCII.GetBytes("0");
|
||||||
|
var compressed = CompressionUtils.Compress(compression, bytes);
|
||||||
|
var bodyParserSettings = new BodyParserSettings
|
||||||
{
|
{
|
||||||
// Arrange
|
Stream = new MemoryStream(compressed),
|
||||||
var bytes = Encoding.ASCII.GetBytes(Guid.NewGuid().ToString());
|
ContentType = "text/plain",
|
||||||
var compressed = CompressionUtils.Compress(compression, bytes);
|
DeserializeJson = false,
|
||||||
var bodyParserSettings = new BodyParserSettings
|
ContentEncoding = compression.ToUpperInvariant(),
|
||||||
{
|
DecompressGZipAndDeflate = true
|
||||||
Stream = new MemoryStream(compressed),
|
};
|
||||||
ContentType = "text/plain",
|
|
||||||
DeserializeJson = false,
|
|
||||||
ContentEncoding = compression.ToUpperInvariant(),
|
|
||||||
DecompressGZipAndDeflate = false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.BodyAsBytes.Should().BeEquivalentTo(compressed);
|
result.DetectedBodyType.Should().Be(BodyType.String);
|
||||||
result.DetectedCompression.Should().BeNull();
|
result.DetectedBodyTypeFromContentType.Should().Be(BodyType.String);
|
||||||
}
|
result.BodyAsBytes.Should().BeEquivalentTo(new byte[] { 48 });
|
||||||
|
result.BodyAsJson.Should().BeNull();
|
||||||
|
result.BodyAsString.Should().Be("0");
|
||||||
|
result.DetectedCompression.Should().Be(compression);
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("HEAD", false)]
|
[InlineData("gzip")]
|
||||||
[InlineData("GET", false)]
|
[InlineData("deflate")]
|
||||||
[InlineData("PUT", true)]
|
public async Task BodyParser_Parse_ContentEncoding_GZip_And_DecompressGzipAndDeflate_Is_False_Should_Not_Decompress(string compression)
|
||||||
[InlineData("POST", true)]
|
{
|
||||||
[InlineData("DELETE", true)]
|
// Arrange
|
||||||
[InlineData("TRACE", false)]
|
var bytes = Encoding.ASCII.GetBytes(Guid.NewGuid().ToString());
|
||||||
[InlineData("OPTIONS", true)]
|
var compressed = CompressionUtils.Compress(compression, bytes);
|
||||||
[InlineData("CONNECT", false)]
|
var bodyParserSettings = new BodyParserSettings
|
||||||
[InlineData("PATCH", true)]
|
|
||||||
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsFalse_ExpectedResultForKnownMethods(string method, bool resultShouldBe)
|
|
||||||
{
|
{
|
||||||
Check.That(BodyParser.ShouldParseBody(method, false)).Equals(resultShouldBe);
|
Stream = new MemoryStream(compressed),
|
||||||
}
|
ContentType = "text/plain",
|
||||||
|
DeserializeJson = false,
|
||||||
|
ContentEncoding = compression.ToUpperInvariant(),
|
||||||
|
DecompressGZipAndDeflate = false
|
||||||
|
};
|
||||||
|
|
||||||
[Theory]
|
// Act
|
||||||
[InlineData("HEAD")]
|
var result = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
[InlineData("GET")]
|
|
||||||
[InlineData("PUT")]
|
|
||||||
[InlineData("POST")]
|
|
||||||
[InlineData("DELETE")]
|
|
||||||
[InlineData("TRACE")]
|
|
||||||
[InlineData("OPTIONS")]
|
|
||||||
[InlineData("CONNECT")]
|
|
||||||
[InlineData("PATCH")]
|
|
||||||
[InlineData("REPORT")]
|
|
||||||
[InlineData("SOME-UNKNOWN-METHOD")]
|
|
||||||
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsTrue_ExpectedResultShouldBeTrue(string method)
|
|
||||||
{
|
|
||||||
Check.That(BodyParser.ShouldParseBody(method, true)).IsTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
// Assert
|
||||||
[InlineData("REPORT")]
|
result.BodyAsBytes.Should().BeEquivalentTo(compressed);
|
||||||
[InlineData("SOME-UNKNOWN-METHOD")]
|
result.DetectedCompression.Should().BeNull();
|
||||||
public void BodyParser_ShouldParseBody_DefaultIsTrueForUnknownMethods(string method)
|
}
|
||||||
{
|
|
||||||
Check.That(BodyParser.ShouldParseBody(method, false)).IsTrue();
|
[Theory]
|
||||||
}
|
[InlineData("HEAD", false)]
|
||||||
|
[InlineData("GET", false)]
|
||||||
|
[InlineData("PUT", true)]
|
||||||
|
[InlineData("POST", true)]
|
||||||
|
[InlineData("DELETE", true)]
|
||||||
|
[InlineData("TRACE", false)]
|
||||||
|
[InlineData("OPTIONS", true)]
|
||||||
|
[InlineData("CONNECT", false)]
|
||||||
|
[InlineData("PATCH", true)]
|
||||||
|
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsFalse_ExpectedResultForKnownMethods(string method, bool resultShouldBe)
|
||||||
|
{
|
||||||
|
Check.That(BodyParser.ShouldParseBody(method, false)).Equals(resultShouldBe);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("HEAD")]
|
||||||
|
[InlineData("GET")]
|
||||||
|
[InlineData("PUT")]
|
||||||
|
[InlineData("POST")]
|
||||||
|
[InlineData("DELETE")]
|
||||||
|
[InlineData("TRACE")]
|
||||||
|
[InlineData("OPTIONS")]
|
||||||
|
[InlineData("CONNECT")]
|
||||||
|
[InlineData("PATCH")]
|
||||||
|
[InlineData("REPORT")]
|
||||||
|
[InlineData("SOME-UNKNOWN-METHOD")]
|
||||||
|
public void BodyParser_ShouldParseBodyForMethodAndAllowAllIsTrue_ExpectedResultShouldBeTrue(string method)
|
||||||
|
{
|
||||||
|
Check.That(BodyParser.ShouldParseBody(method, true)).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("REPORT")]
|
||||||
|
[InlineData("SOME-UNKNOWN-METHOD")]
|
||||||
|
public void BodyParser_ShouldParseBody_DefaultIsTrueForUnknownMethods(string method)
|
||||||
|
{
|
||||||
|
Check.That(BodyParser.ShouldParseBody(method, false)).IsTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,29 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Util
|
namespace WireMock.Net.Tests.Util;
|
||||||
|
|
||||||
|
public class BytesEncodingUtilsTests
|
||||||
{
|
{
|
||||||
public class BytesEncodingUtilsTests
|
[Fact]
|
||||||
|
public void TryGetEncoding_UTF32()
|
||||||
{
|
{
|
||||||
[Fact]
|
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff, 0xfe, 0x00, 0x00 }, out Encoding encoding);
|
||||||
public void TryGetEncoding_UTF32()
|
|
||||||
{
|
|
||||||
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff, 0xfe, 0x00, 0x00 }, out Encoding encoding);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().BeTrue();
|
result.Should().BeTrue();
|
||||||
encoding.CodePage.Should().Be(Encoding.UTF32.CodePage);
|
encoding.CodePage.Should().Be(Encoding.UTF32.CodePage);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TryGetEncoding_Invalid()
|
public void TryGetEncoding_Invalid()
|
||||||
{
|
{
|
||||||
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff }, out Encoding encoding);
|
var result = BytesEncodingUtils.TryGetEncoding(new byte[] { 0xff }, out Encoding encoding);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().BeFalse();
|
result.Should().BeFalse();
|
||||||
encoding.Should().BeNull();
|
encoding.Should().BeNull();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,75 +1,74 @@
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Util
|
namespace WireMock.Net.Tests.Util;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Based on https://raw.githubusercontent.com/tmenier/Flurl/129565361e135e639f1d44a35a78aea4302ac6ca/Test/Flurl.Test/Http/HttpStatusRangeParserTests.cs
|
||||||
|
/// </summary>
|
||||||
|
public class HttpStatusRangeParserTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
[Theory]
|
||||||
/// Based on https://raw.githubusercontent.com/tmenier/Flurl/129565361e135e639f1d44a35a78aea4302ac6ca/Test/Flurl.Test/Http/HttpStatusRangeParserTests.cs
|
[InlineData("4**", 399, false)]
|
||||||
/// </summary>
|
[InlineData("4**", 400, true)]
|
||||||
public class HttpStatusRangeParserTests
|
[InlineData("4**", 499, true)]
|
||||||
|
[InlineData("4**", 500, false)]
|
||||||
|
|
||||||
|
[InlineData("4xx", 399, false)]
|
||||||
|
[InlineData("4xx", 400, true)]
|
||||||
|
[InlineData("4xx", 499, true)]
|
||||||
|
[InlineData("4xx", 500, false)]
|
||||||
|
|
||||||
|
[InlineData("4XX", 399, false)]
|
||||||
|
[InlineData("4XX", 400, true)]
|
||||||
|
[InlineData("4XX", 499, true)]
|
||||||
|
[InlineData("4XX", 500, false)]
|
||||||
|
|
||||||
|
[InlineData("400-499", 399, false)]
|
||||||
|
[InlineData("400-499", 400, true)]
|
||||||
|
[InlineData("400-499", 499, true)]
|
||||||
|
[InlineData("400-499", 500, false)]
|
||||||
|
|
||||||
|
[InlineData("100,3xx,600", 100, true)]
|
||||||
|
[InlineData("100,3xx,600", 101, false)]
|
||||||
|
[InlineData("100,3xx,600", 300, true)]
|
||||||
|
[InlineData("100,3xx,600", 399, true)]
|
||||||
|
[InlineData("100,3xx,600", 400, false)]
|
||||||
|
[InlineData("100,3xx,600", 600, true)]
|
||||||
|
|
||||||
|
[InlineData("400-409,490-499", 399, false)]
|
||||||
|
[InlineData("400-409,490-499", 405, true)]
|
||||||
|
[InlineData("400-409,490-499", 450, false)]
|
||||||
|
[InlineData("400-409,490-499", 495, true)]
|
||||||
|
[InlineData("400-409,490-499", 500, false)]
|
||||||
|
|
||||||
|
[InlineData("*", 0, true)]
|
||||||
|
[InlineData(",,,*", 9999, true)]
|
||||||
|
|
||||||
|
[InlineData("", 0, false)]
|
||||||
|
[InlineData(",,,", 9999, false)]
|
||||||
|
|
||||||
|
[InlineData(null, 399, true)]
|
||||||
|
public void HttpStatusRangeParser_ValidPattern_IsMatch(string pattern, int value, bool expectedResult)
|
||||||
{
|
{
|
||||||
[Theory]
|
HttpStatusRangeParser.IsMatch(pattern, value).Should().Be(expectedResult);
|
||||||
[InlineData("4**", 399, false)]
|
}
|
||||||
[InlineData("4**", 400, true)]
|
|
||||||
[InlineData("4**", 499, true)]
|
|
||||||
[InlineData("4**", 500, false)]
|
|
||||||
|
|
||||||
[InlineData("4xx", 399, false)]
|
[Fact]
|
||||||
[InlineData("4xx", 400, true)]
|
public void HttpStatusRangeParser_ValidPattern_HttpStatusCode_IsMatch()
|
||||||
[InlineData("4xx", 499, true)]
|
{
|
||||||
[InlineData("4xx", 500, false)]
|
HttpStatusRangeParser.IsMatch("4xx", HttpStatusCode.BadRequest).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[InlineData("4XX", 399, false)]
|
[Theory]
|
||||||
[InlineData("4XX", 400, true)]
|
[InlineData("-100")]
|
||||||
[InlineData("4XX", 499, true)]
|
[InlineData("100-")]
|
||||||
[InlineData("4XX", 500, false)]
|
[InlineData("1yy")]
|
||||||
|
public void HttpStatusRangeParser_InvalidPattern_ThrowsException(string pattern)
|
||||||
[InlineData("400-499", 399, false)]
|
{
|
||||||
[InlineData("400-499", 400, true)]
|
Assert.Throws<ArgumentException>(() => HttpStatusRangeParser.IsMatch(pattern, 100));
|
||||||
[InlineData("400-499", 499, true)]
|
|
||||||
[InlineData("400-499", 500, false)]
|
|
||||||
|
|
||||||
[InlineData("100,3xx,600", 100, true)]
|
|
||||||
[InlineData("100,3xx,600", 101, false)]
|
|
||||||
[InlineData("100,3xx,600", 300, true)]
|
|
||||||
[InlineData("100,3xx,600", 399, true)]
|
|
||||||
[InlineData("100,3xx,600", 400, false)]
|
|
||||||
[InlineData("100,3xx,600", 600, true)]
|
|
||||||
|
|
||||||
[InlineData("400-409,490-499", 399, false)]
|
|
||||||
[InlineData("400-409,490-499", 405, true)]
|
|
||||||
[InlineData("400-409,490-499", 450, false)]
|
|
||||||
[InlineData("400-409,490-499", 495, true)]
|
|
||||||
[InlineData("400-409,490-499", 500, false)]
|
|
||||||
|
|
||||||
[InlineData("*", 0, true)]
|
|
||||||
[InlineData(",,,*", 9999, true)]
|
|
||||||
|
|
||||||
[InlineData("", 0, false)]
|
|
||||||
[InlineData(",,,", 9999, false)]
|
|
||||||
|
|
||||||
[InlineData(null, 399, true)]
|
|
||||||
public void HttpStatusRangeParser_ValidPattern_IsMatch(string pattern, int value, bool expectedResult)
|
|
||||||
{
|
|
||||||
HttpStatusRangeParser.IsMatch(pattern, value).Should().Be(expectedResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void HttpStatusRangeParser_ValidPattern_HttpStatusCode_IsMatch()
|
|
||||||
{
|
|
||||||
HttpStatusRangeParser.IsMatch("4xx", HttpStatusCode.BadRequest).Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("-100")]
|
|
||||||
[InlineData("100-")]
|
|
||||||
[InlineData("1yy")]
|
|
||||||
public void HttpStatusRangeParser_InvalidPattern_ThrowsException(string pattern)
|
|
||||||
{
|
|
||||||
Assert.Throws<ArgumentException>(() => HttpStatusRangeParser.IsMatch(pattern, 100));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,103 +2,102 @@ using FluentAssertions;
|
|||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Util
|
namespace WireMock.Net.Tests.Util;
|
||||||
|
|
||||||
|
public class StringUtilsTests
|
||||||
{
|
{
|
||||||
public class StringUtilsTests
|
[Theory]
|
||||||
|
[InlineData("'s")]
|
||||||
|
[InlineData("\"s")]
|
||||||
|
public void StringUtils_TryParseQuotedString_With_UnexpectedUnclosedString_Returns_False(string input)
|
||||||
{
|
{
|
||||||
[Theory]
|
// Act
|
||||||
[InlineData("'s")]
|
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||||
[InlineData("\"s")]
|
|
||||||
public void StringUtils_TryParseQuotedString_With_UnexpectedUnclosedString_Returns_False(string input)
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
valid.Should().BeFalse();
|
valid.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("")]
|
[InlineData("")]
|
||||||
[InlineData(null)]
|
[InlineData(null)]
|
||||||
[InlineData("x")]
|
[InlineData("x")]
|
||||||
public void StringUtils_TryParseQuotedString_With_InvalidStringLength_Returns_False(string input)
|
public void StringUtils_TryParseQuotedString_With_InvalidStringLength_Returns_False(string input)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
valid.Should().BeFalse();
|
valid.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("xx")]
|
[InlineData("xx")]
|
||||||
[InlineData(" ")]
|
[InlineData(" ")]
|
||||||
public void StringUtils_TryParseQuotedString_With_InvalidStringQuoteCharacter_Returns_False(string input)
|
public void StringUtils_TryParseQuotedString_With_InvalidStringQuoteCharacter_Returns_False(string input)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
valid.Should().BeFalse();
|
valid.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void StringUtils_TryParseQuotedString_With_UnexpectedUnrecognizedEscapeSequence_Returns_False()
|
public void StringUtils_TryParseQuotedString_With_UnexpectedUnrecognizedEscapeSequence_Returns_False()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string input = new string(new[] { '"', '\\', 'u', '?', '"' });
|
string input = new string(new[] { '"', '\\', 'u', '?', '"' });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
valid.Should().BeFalse();
|
valid.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("''", "")]
|
[InlineData("''", "")]
|
||||||
[InlineData("'s'", "s")]
|
[InlineData("'s'", "s")]
|
||||||
[InlineData("'\\\\'", "\\")]
|
[InlineData("'\\\\'", "\\")]
|
||||||
[InlineData("'\\n'", "\n")]
|
[InlineData("'\\n'", "\n")]
|
||||||
public void StringUtils_TryParseQuotedString_SingleQuotedString(string input, string expectedResult)
|
public void StringUtils_TryParseQuotedString_SingleQuotedString(string input, string expectedResult)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
valid.Should().BeTrue();
|
valid.Should().BeTrue();
|
||||||
result.Should().Be(expectedResult);
|
result.Should().Be(expectedResult);
|
||||||
quote.Should().Be('\'');
|
quote.Should().Be('\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("\"\"", "")]
|
[InlineData("\"\"", "")]
|
||||||
[InlineData("\"\\\\\"", "\\")]
|
[InlineData("\"\\\\\"", "\\")]
|
||||||
[InlineData("\"\\n\"", "\n")]
|
[InlineData("\"\\n\"", "\n")]
|
||||||
[InlineData("\"\\\\n\"", "\\n")]
|
[InlineData("\"\\\\n\"", "\\n")]
|
||||||
[InlineData("\"\\\\new\"", "\\new")]
|
[InlineData("\"\\\\new\"", "\\new")]
|
||||||
[InlineData("\"[]\"", "[]")]
|
[InlineData("\"[]\"", "[]")]
|
||||||
[InlineData("\"()\"", "()")]
|
[InlineData("\"()\"", "()")]
|
||||||
[InlineData("\"(\\\"\\\")\"", "(\"\")")]
|
[InlineData("\"(\\\"\\\")\"", "(\"\")")]
|
||||||
[InlineData("\"/\"", "/")]
|
[InlineData("\"/\"", "/")]
|
||||||
[InlineData("\"a\"", "a")]
|
[InlineData("\"a\"", "a")]
|
||||||
[InlineData("\"This \\\"is\\\" a test.\"", "This \"is\" a test.")]
|
[InlineData("\"This \\\"is\\\" a test.\"", "This \"is\" a test.")]
|
||||||
[InlineData(@"""This \""is\"" b test.""", @"This ""is"" b test.")]
|
[InlineData(@"""This \""is\"" b test.""", @"This ""is"" b test.")]
|
||||||
[InlineData("\"ab\\\"cd\"", "ab\"cd")]
|
[InlineData("\"ab\\\"cd\"", "ab\"cd")]
|
||||||
[InlineData("\"\\\"\"", "\"")]
|
[InlineData("\"\\\"\"", "\"")]
|
||||||
[InlineData("\"\\\"\\\"\"", "\"\"")]
|
[InlineData("\"\\\"\\\"\"", "\"\"")]
|
||||||
[InlineData("\"AB YZ 19 \uD800\udc05 \u00e4\"", "AB YZ 19 \uD800\udc05 \u00e4")]
|
[InlineData("\"AB YZ 19 \uD800\udc05 \u00e4\"", "AB YZ 19 \uD800\udc05 \u00e4")]
|
||||||
[InlineData("\"\\\\\\\\192.168.1.1\\\\audio\\\\new\"", "\\\\192.168.1.1\\audio\\new")]
|
[InlineData("\"\\\\\\\\192.168.1.1\\\\audio\\\\new\"", "\\\\192.168.1.1\\audio\\new")]
|
||||||
public void StringUtils_TryParseQuotedString_DoubleQuotedString(string input, string expectedResult)
|
public void StringUtils_TryParseQuotedString_DoubleQuotedString(string input, string expectedResult)
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
bool valid = StringUtils.TryParseQuotedString(input, out var result, out var quote);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
valid.Should().BeTrue();
|
valid.Should().BeTrue();
|
||||||
result.Should().Be(expectedResult);
|
result.Should().Be(expectedResult);
|
||||||
quote.Should().Be('"');
|
quote.Should().Be('"');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
#if NET452
|
#if NET452
|
||||||
using Microsoft.Owin;
|
using Microsoft.Owin;
|
||||||
#else
|
#else
|
||||||
@@ -8,50 +8,49 @@ using NFluent;
|
|||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Util
|
namespace WireMock.Net.Tests.Util;
|
||||||
|
|
||||||
|
public class UrlUtilsTests
|
||||||
{
|
{
|
||||||
public class UrlUtilsTests
|
[Fact]
|
||||||
|
public void UriUtils_CreateUri_WithValidPathString()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Assign
|
||||||
public void UriUtils_CreateUri_WithValidPathString()
|
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = UrlUtils.Parse(uri, new PathString("/a"));
|
var result = UrlUtils.Parse(uri, new PathString("/a"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/b?x=0");
|
Check.That(result.Url.ToString()).Equals("https://localhost:1234/b?x=0");
|
||||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void UriUtils_CreateUri_WithEmptyPathString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = UrlUtils.Parse(uri, new PathString());
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
|
||||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void UriUtils_CreateUri_WithDifferentPathString()
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = UrlUtils.Parse(uri, new PathString("/test"));
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
|
||||||
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[Fact]
|
||||||
|
public void UriUtils_CreateUri_WithEmptyPathString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = UrlUtils.Parse(uri, new PathString());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||||
|
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UriUtils_CreateUri_WithDifferentPathString()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = UrlUtils.Parse(uri, new PathString("/test"));
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||||
|
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#if !(NET452 || NET461)
|
||||||
|
using VerifyTests;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.VerifyExtensions;
|
||||||
|
|
||||||
|
internal static class VerifySettingsExtensions
|
||||||
|
{
|
||||||
|
public static void Init<T>(this VerifySettings verifySettings)
|
||||||
|
{
|
||||||
|
verifySettings.DontScrubDateTimes();
|
||||||
|
verifySettings.DontScrubDateTimes();
|
||||||
|
verifySettings.UseDirectory($"{typeof(T).Name}.Verify");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -24,6 +24,18 @@
|
|||||||
<DefineConstants>NETFRAMEWORK</DefineConstants>
|
<DefineConstants>NETFRAMEWORK</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- https://stackoverflow.com/questions/59406201/filenesting-not-working-for-class-or-shared-library-projects -->
|
||||||
|
<ProjectCapability Include="ConfigurableFileNesting" />
|
||||||
|
<ProjectCapability Include="ConfigurableFileNestingFeatureEnabled" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!--<ItemGroup>
|
||||||
|
<Compile Update="**\*.*.verified.txt">
|
||||||
|
<DependentUpon>$([System.String]::Copy((Filename)*.cs))</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>-->
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
|
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
|
||||||
@@ -41,12 +53,6 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="CultureAwareTesting.xUnit" Version="0.0.1" />
|
<PackageReference Include="CultureAwareTesting.xUnit" Version="0.0.1" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
|
||||||
<PackageReference Include="xunit.core" Version="2.4.1" />
|
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
<PackageReference Include="coverlet.collector" Version="3.2.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@@ -66,10 +72,23 @@
|
|||||||
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="3.1.0" />
|
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="3.1.0" />
|
||||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.core" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' != 'net452' and '$(TargetFramework)' != 'net461'">
|
<ItemGroup Condition="'$(TargetFramework)' != 'net452' and '$(TargetFramework)' != 'net461'">
|
||||||
<PackageReference Include="FluentAssertions" Version="6.7.0" />
|
<PackageReference Include="FluentAssertions" Version="6.9.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
<PackageReference Include="xunit.core" Version="2.4.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Verify.Xunit" Version="19.6.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' != 'net452'">
|
<ItemGroup Condition="'$(TargetFramework)' != 'net452'">
|
||||||
@@ -81,9 +100,6 @@
|
|||||||
<None Update="responsebody.json">
|
<None Update="responsebody.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Serialization\files\proxy.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="__admin\mappings.org\*.json">
|
<None Update="__admin\mappings.org\*.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
@@ -108,7 +124,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Pact\files\" />
|
<Folder Include="Pact\files\" />
|
||||||
<Folder Include="Serialization\files\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -146,7 +146,7 @@ public class WireMockServerAdminTests
|
|||||||
|
|
||||||
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "responsebody.json");
|
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "responsebody.json");
|
||||||
|
|
||||||
dynamic jsonObj = JsonConvert.DeserializeObject(json);
|
dynamic jsonObj = JsonConvert.DeserializeObject(json)!;
|
||||||
jsonObj["Response"]["BodyAsFile"] = responseBodyFilePath;
|
jsonObj["Response"]["BodyAsFile"] = responseBodyFilePath;
|
||||||
|
|
||||||
string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
|
string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
|
||||||
|
|||||||
@@ -1,65 +1,65 @@
|
|||||||
using System;
|
using System;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.WithMapping
|
namespace WireMock.Net.Tests.WithMapping;
|
||||||
|
|
||||||
|
public class WireMockServerWithMappingTests
|
||||||
{
|
{
|
||||||
public class WireMockServerWithMappingTests
|
[Fact]
|
||||||
|
public void WireMockServer_WithMappingAsModel_Should_Add_Mapping()
|
||||||
{
|
{
|
||||||
[Fact]
|
// Arrange
|
||||||
public void WireMockServer_WithMappingAsModel_Should_Add_Mapping()
|
var guid = Guid.NewGuid();
|
||||||
|
var pattern = "hello wiremock";
|
||||||
|
var path = "/foo";
|
||||||
|
var response = "OK";
|
||||||
|
var mapping = new MappingModel
|
||||||
{
|
{
|
||||||
// Arrange
|
Guid = guid,
|
||||||
var guid = Guid.NewGuid();
|
Request = new RequestModel
|
||||||
var pattern = "hello wiremock";
|
|
||||||
var path = "/foo";
|
|
||||||
var response = "OK";
|
|
||||||
var mapping = new MappingModel
|
|
||||||
{
|
{
|
||||||
Guid = guid,
|
Path = path,
|
||||||
Request = new RequestModel
|
Body = new BodyModel
|
||||||
{
|
{
|
||||||
Path = path,
|
Matcher = new MatcherModel
|
||||||
Body = new BodyModel
|
|
||||||
{
|
{
|
||||||
Matcher = new MatcherModel
|
Name = "ExactMatcher",
|
||||||
{
|
Pattern = pattern
|
||||||
Name = "ExactMatcher",
|
|
||||||
Pattern = pattern
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
Response = new ResponseModel
|
|
||||||
{
|
|
||||||
Body = response,
|
|
||||||
StatusCode = 201
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
Response = new ResponseModel
|
||||||
|
{
|
||||||
|
Body = response,
|
||||||
|
StatusCode = 201
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var server = WireMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
server.WithMapping(mapping);
|
server.WithMapping(mapping);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
||||||
m.Guid == guid &&
|
m.Guid == guid &&
|
||||||
//((PathModel)m.Request.Path).Matchers.OfType<WildcardMatcher>().First().GetPatterns().First() == "/foo*"
|
//((PathModel)m.Request.Path).Matchers.OfType<WildcardMatcher>().First().GetPatterns().First() == "/foo*"
|
||||||
// m.Request.Body.Matchers.OfType<ExactMatcher>().First().GetPatterns().First() == pattern &&
|
// m.Request.Body.Matchers.OfType<ExactMatcher>().First().GetPatterns().First() == pattern &&
|
||||||
m.Response.Body == response &&
|
m.Response.Body == response &&
|
||||||
(int)m.Response.StatusCode == 201
|
(int?)m.Response.StatusCode == 201
|
||||||
);
|
);
|
||||||
|
|
||||||
server.Stop();
|
server.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WireMockServer_WithMappingAsJson_Should_Add_Mapping()
|
public void WireMockServer_WithMappingAsJson_Should_Add_Mapping()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapping = @"{
|
var mapping = @"{
|
||||||
""Guid"": ""532889c2-f84d-4dc8-b847-9ea2c6aca7d5"",
|
""Guid"": ""532889c2-f84d-4dc8-b847-9ea2c6aca7d5"",
|
||||||
""Request"": {
|
""Request"": {
|
||||||
""Path"": ""/pet"",
|
""Path"": ""/pet"",
|
||||||
@@ -78,25 +78,25 @@ namespace WireMock.Net.Tests.WithMapping
|
|||||||
}
|
}
|
||||||
}";
|
}";
|
||||||
|
|
||||||
var server = WireMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
server.WithMapping(mapping);
|
server.WithMapping(mapping);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
server.MappingModels.Should().HaveCount(1).And.Contain(m =>
|
||||||
m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") &&
|
m.Guid == Guid.Parse("532889c2-f84d-4dc8-b847-9ea2c6aca7d5") &&
|
||||||
(int)m.Response.StatusCode == 201
|
(int?)m.Response.StatusCode == 201
|
||||||
);
|
);
|
||||||
|
|
||||||
server.Stop();
|
server.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WireMockServer_WithMappingsAsJson_Should_Add_Mapping()
|
public void WireMockServer_WithMappingsAsJson_Should_Add_Mapping()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapping = @"[
|
var mapping = @"[
|
||||||
{
|
{
|
||||||
""Guid"": ""532889c2-f84d-4dc8-b847-9ea2c6aca7d1"",
|
""Guid"": ""532889c2-f84d-4dc8-b847-9ea2c6aca7d1"",
|
||||||
""Request"": {
|
""Request"": {
|
||||||
@@ -117,15 +117,14 @@ namespace WireMock.Net.Tests.WithMapping
|
|||||||
}
|
}
|
||||||
]";
|
]";
|
||||||
|
|
||||||
var server = WireMockServer.Start();
|
var server = WireMockServer.Start();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
server.WithMapping(mapping);
|
server.WithMapping(mapping);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
server.MappingModels.Should().HaveCount(2);
|
server.MappingModels.Should().HaveCount(2);
|
||||||
|
|
||||||
server.Stop();
|
server.Stop();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user