Compare commits

..

1 Commits

Author SHA1 Message Date
Stef Heyenrath
4bfb97b192 wip 2020-10-12 21:48:37 +02:00
26 changed files with 174 additions and 323 deletions

View File

@@ -1,21 +1,3 @@
# 1.3.5 (04 November 2020)
- [#530](https://github.com/WireMock-Net/WireMock.Net/pull/530) - Fix dotnet-sonarscanner [bug] contributed by [StefH](https://github.com/StefH)
- [#531](https://github.com/WireMock-Net/WireMock.Net/pull/531) - Add WithCallback-Async [feature] contributed by [StefH](https://github.com/StefH)
# 1.3.4 (17 October 2020)
- [#522](https://github.com/WireMock-Net/WireMock.Net/pull/522) - Add ContinuousIntegrationBuild property [feature] contributed by [StefH](https://github.com/StefH)
- [#525](https://github.com/WireMock-Net/WireMock.Net/pull/525) - Handlebars.Net.Helpers Version="1.1.0" [feature] contributed by [StefH](https://github.com/StefH)
# 1.3.3 (15 October 2020)
- [#520](https://github.com/WireMock-Net/WireMock.Net/pull/520) - Make kestrel limits configurable contributed by [eduherminio](https://github.com/eduherminio)
- [#521](https://github.com/WireMock-Net/WireMock.Net/issues/521) - Make Kestrel limits configurable [feature]
# 1.3.2 (14 October 2020)
- [#505](https://github.com/WireMock-Net/WireMock.Net/pull/505) - Fix reading JsonMatcher-mapping with object as pattern [bug] contributed by [StefH](https://github.com/StefH)
- [#514](https://github.com/WireMock-Net/WireMock.Net/pull/514) - Update .NET Core 3.1 example contributed by [Crossbow78](https://github.com/Crossbow78)
- [#504](https://github.com/WireMock-Net/WireMock.Net/issues/504) - Loading mapping models with `JsonMatcher` is not working correctly [bug]
- [#513](https://github.com/WireMock-Net/WireMock.Net/issues/513) - Static mapping break from 1.2.17 to 1.2.18 and higher [bug]
# 1.3.1 (30 September 2020)
- [#509](https://github.com/WireMock-Net/WireMock.Net/pull/509) - Adding netcoreapp3.1 as a target framework [feature] contributed by [APIWT](https://github.com/APIWT)

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.3.4</VersionPrefix>
<VersionPrefix>1.3.1</VersionPrefix>
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
@@ -14,10 +14,6 @@
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
<Choose>
<!-- The environment variable `Prerelease` is set in the azure-pipelines.yml file. -->
<When Condition=" '$(Prerelease)' != '' ">

View File

@@ -1,3 +1,3 @@
https://github.com/StefH/GitHubReleaseNotes
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.3.5
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.3.1

View File

@@ -28,7 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
<PackageReference Include="Handlebars.Net.Helpers" Version="1.1.0" />
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<!--<PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.4.0" />-->

View File

@@ -12,7 +12,6 @@ using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;
using WireMock.Util;
using System.Threading.Tasks;
namespace WireMock.Net.ConsoleApplication
{
@@ -522,29 +521,9 @@ namespace WireMock.Net.ConsoleApplication
.WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" }));
server
.Given(Request.Create().WithPath("/random200or505").UsingGet())
.RespondWith(Response.Create().WithCallback(request =>
.RespondWith(Response.Create().WithCallback(request => new ResponseMessage
{
int code = new Random().Next(1, 2) == 1 ? 505 : 200;
return new ResponseMessage
{
BodyData = new BodyData { BodyAsString = "random200or505:" + code, DetectedBodyType = Types.BodyType.String },
StatusCode = code
};
}));
server
.Given(Request.Create().WithPath("/random200or505async").UsingGet())
.RespondWith(Response.Create().WithCallback(async request =>
{
await Task.Delay(1);
int code = new Random().Next(1, 2) == 1 ? 505 : 200;
return new ResponseMessage
{
BodyData = new BodyData { BodyAsString = "random200or505async:" + code, DetectedBodyType = Types.BodyType.String },
StatusCode = code
};
StatusCode = new Random().Next(1, 100) == 1 ? 504 : 200
}));
System.Console.WriteLine(JsonConvert.SerializeObject(server.MappingModels, Formatting.Indented));

View File

@@ -62,9 +62,9 @@ namespace WireMock.Server
void AddGlobalProcessingDelay(TimeSpan delay);
/// <summary>
/// Allows the partial mapping.
/// Set the partial mapping to allowed (if true, you can also provide 'enforceHttpMethod').
/// </summary>
void AllowPartialMapping(bool allow = true);
void AllowPartialMapping(bool allow = true, bool enforceHttpMethod = false);
/// <summary>
/// Deletes a LogEntry.

View File

@@ -3,8 +3,6 @@ using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace WireMock.Owin
{
@@ -36,24 +34,5 @@ namespace WireMock.Owin
}
}
}
internal static class IWebHostBuilderExtensions
{
internal static IWebHostBuilder ConfigureAppConfigurationUsingEnvironmentVariables(this IWebHostBuilder builder)
{
return builder.ConfigureAppConfiguration(config =>
{
config.AddEnvironmentVariables();
});
}
internal static IWebHostBuilder ConfigureKestrelServerOptions(this IWebHostBuilder builder)
{
return builder.ConfigureServices((context, services) =>
{
services.Configure<KestrelServerOptions>(context.Configuration.GetSection("Kestrel"));
});
}
}
}
#endif

View File

@@ -4,8 +4,6 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using WireMock.HttpsCertificate;
namespace WireMock.Owin
@@ -28,22 +26,5 @@ namespace WireMock.Owin
}
}
}
internal static class IWebHostBuilderExtensions
{
internal static IWebHostBuilder ConfigureAppConfigurationUsingEnvironmentVariables(this IWebHostBuilder builder) => builder;
internal static IWebHostBuilder ConfigureKestrelServerOptions(this IWebHostBuilder builder)
{
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();
return builder.ConfigureServices(services =>
{
services.Configure<KestrelServerOptions>(configuration.GetSection("Kestrel"));
});
}
}
}
#endif

View File

@@ -58,7 +58,6 @@ namespace WireMock.Owin
}
_host = builder
.ConfigureAppConfigurationUsingEnvironmentVariables()
.ConfigureServices(services =>
{
services.AddSingleton(_options);
@@ -82,7 +81,6 @@ namespace WireMock.Owin
SetHttpsAndUrls(options, _urlOptions.GetDetails());
})
.ConfigureKestrelServerOptions()
#if NETSTANDARD1_3
.UseUrls(_urlOptions.GetDetails().Select(u => u.Url).ToArray())
@@ -120,10 +118,8 @@ namespace WireMock.Owin
_logger.Info("WireMock.Net server using netstandard2.0");
#elif NETSTANDARD2_1
_logger.Info("WireMock.Net server using netstandard2.1");
#elif NETCOREAPP3_1
_logger.Info("WireMock.Net server using .NET Core 3.1");
#elif NET46
_logger.Info("WireMock.Net server using .NET Framework 4.6.1 or higher");
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
#endif
#if NETSTANDARD1_3

View File

@@ -4,6 +4,7 @@ using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
using WireMock.Util;
using WireMock.Settings;
#if !USE_ASPNETCORE
using Owin;
#else
@@ -22,6 +23,8 @@ namespace WireMock.Owin
bool? AllowPartialMapping { get; set; }
IPartialMappingSettings PartialMappingSettings { get; set; }
ConcurrentDictionary<Guid, IMapping> Mappings { get; }
ConcurrentDictionary<string, ScenarioState> Scenarios { get; }

View File

@@ -42,6 +42,16 @@ namespace WireMock.Owin
.OrderBy(m => m.RequestMatchResult)
.ThenBy(m => m.Mapping.Priority)
.ToList();
if (_options.PartialMappingSettings?.EnforceHttpMethod == true)
{
// Check if any partialMappings contain a HttpMethodMatcher, and check if this returns a 0
foreach (var partialMapping in partialMappings)
{
}
}
var partialMatch = partialMappings.FirstOrDefault(pm => pm.RequestMatchResult.AverageTotalScore > 0.0);
if (_options.AllowPartialMapping == true)

View File

@@ -4,6 +4,7 @@ using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
using WireMock.Util;
using WireMock.Settings;
#if !USE_ASPNETCORE
using Owin;
#else
@@ -22,6 +23,8 @@ namespace WireMock.Owin
public bool? AllowPartialMapping { get; set; }
public IPartialMappingSettings PartialMappingSettings { get; set; }
public ConcurrentDictionary<Guid, IMapping> Mappings { get; } = new ConcurrentDictionary<Guid, IMapping>();
public ConcurrentDictionary<string, ScenarioState> Scenarios { get; } = new ConcurrentDictionary<string, ScenarioState>();

View File

@@ -1,27 +1,19 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;
using WireMock.ResponseProviders;
namespace WireMock.ResponseBuilders
{
/// <summary>
/// The CallbackResponseBuilder interface.
/// </summary>
public interface ICallbackResponseBuilder : IResponseProvider
{
/// <summary>
/// The callback builder
/// </summary>
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
[PublicAPI]
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, ResponseMessage> callbackHandler);
/// <summary>
/// The async callback builder
/// </summary>
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
[PublicAPI]
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, Task<ResponseMessage>> callbackHandler);
}
using System;
using JetBrains.Annotations;
using WireMock.ResponseProviders;
namespace WireMock.ResponseBuilders
{
/// <summary>
/// The CallbackResponseBuilder interface.
/// </summary>
public interface ICallbackResponseBuilder : IResponseProvider
{
/// <summary>
/// The callback builder
/// </summary>
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
[PublicAPI]
IResponseBuilder WithCallback([NotNull] Func<RequestMessage, ResponseMessage> callbackHandler);
}
}

View File

@@ -1,60 +0,0 @@
using System;
using System.Threading.Tasks;
using WireMock.Validation;
namespace WireMock.ResponseBuilders
{
public partial class Response
{
/// <summary>
/// A delegate to execute to generate the response.
/// </summary>
public Func<RequestMessage, ResponseMessage> Callback { get; private set; }
/// <summary>
/// A delegate to execute to generate the response async.
/// </summary>
public Func<RequestMessage, Task<ResponseMessage>> CallbackAsync { get; private set; }
/// <summary>
/// Defines if the method WithCallback(...) is used.
/// </summary>
public bool WithCallbackUsed { get; private set; }
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, ResponseMessage})"/>
public IResponseBuilder WithCallback(Func<RequestMessage, ResponseMessage> callbackHandler)
{
Check.NotNull(callbackHandler, nameof(callbackHandler));
return WithCallbackInternal(true, callbackHandler);
}
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, Task{ResponseMessage}})"/>
public IResponseBuilder WithCallback(Func<RequestMessage, Task<ResponseMessage>> callbackHandler)
{
Check.NotNull(callbackHandler, nameof(callbackHandler));
return WithCallbackInternal(true, callbackHandler);
}
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, ResponseMessage> callbackHandler)
{
Check.NotNull(callbackHandler, nameof(callbackHandler));
WithCallbackUsed = withCallbackUsed;
Callback = callbackHandler;
return this;
}
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, Task<ResponseMessage>> callbackHandler)
{
Check.NotNull(callbackHandler, nameof(callbackHandler));
WithCallbackUsed = withCallbackUsed;
CallbackAsync = callbackHandler;
return this;
}
}
}

View File

@@ -42,6 +42,16 @@ namespace WireMock.ResponseBuilders
/// </summary>
public ResponseMessage ResponseMessage { get; }
/// <summary>
/// A delegate to execute to generate the response.
/// </summary>
public Func<RequestMessage, ResponseMessage> Callback { get; private set; }
/// <summary>
/// Defines if the method WithCallback(...) is used.
/// </summary>
public bool WithCallbackUsed { get; private set; }
/// <summary>
/// Creates this instance.
/// </summary>
@@ -301,6 +311,25 @@ namespace WireMock.ResponseBuilders
return WithDelay(TimeSpan.FromMilliseconds(milliseconds));
}
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback"/>
public IResponseBuilder WithCallback(Func<RequestMessage, ResponseMessage> callbackHandler)
{
Check.NotNull(callbackHandler, nameof(callbackHandler));
return WithCallbackInternal(true, callbackHandler);
}
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback"/>
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, ResponseMessage> callbackHandler)
{
Check.NotNull(callbackHandler, nameof(callbackHandler));
WithCallbackUsed = withCallbackUsed;
Callback = callbackHandler;
return this;
}
/// <inheritdoc cref="IResponseProvider.ProvideResponseAsync(RequestMessage, IWireMockServerSettings)"/>
public async Task<ResponseMessage> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings)
{
@@ -336,20 +365,13 @@ namespace WireMock.ResponseBuilders
}
ResponseMessage responseMessage;
if (Callback == null && CallbackAsync == null)
if (Callback == null)
{
responseMessage = ResponseMessage;
}
else
{
if (Callback != null)
{
responseMessage = Callback(requestMessage);
}
else
{
responseMessage = await CallbackAsync(requestMessage);
}
responseMessage = Callback(requestMessage);
if (!WithCallbackUsed)
{

View File

@@ -36,7 +36,7 @@ namespace WireMock.Serialization
string matcherName = parts[0];
string matcherType = parts.Length > 1 ? parts[1] : null;
string[] stringPatterns = (matcher.Patterns != null ? matcher.Patterns : new[] { matcher.Pattern }).OfType<string>().ToArray();
string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.OfType<string>().ToArray() : new[] { matcher.Pattern as string };
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
bool ignoreCase = matcher.IgnoreCase == true;
bool throwExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails == true;
@@ -64,8 +64,7 @@ namespace WireMock.Serialization
return new RegexMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
case "JsonMatcher":
object value = matcher.Pattern ?? matcher.Patterns;
return new JsonMatcher(matchBehaviour, value, ignoreCase, throwExceptionWhenMatcherFails);
return new JsonMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
case "JsonPathMatcher":
return new JsonPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);

View File

@@ -367,6 +367,7 @@ namespace WireMock.Server
if (settings.AllowPartialMapping != null)
{
_options.AllowPartialMapping = settings.AllowPartialMapping.Value;
// TODO stef _options.PartialMappingSettings = settings.
}
if (settings.GlobalProcessingDelay != null)

View File

@@ -283,7 +283,7 @@ namespace WireMock.Server
if (settings.AllowPartialMapping == true)
{
AllowPartialMapping();
AllowPartialMapping(true, settings.PartialMappingSettings);
}
if (settings.StartAdminInterface == true)
@@ -389,10 +389,21 @@ namespace WireMock.Server
/// <inheritdoc cref="IWireMockServer.AllowPartialMapping" />
[PublicAPI]
public void AllowPartialMapping(bool allow = true)
public void AllowPartialMapping(bool allow = true, bool enforceHttpMethod = false)
{
AllowPartialMapping(allow, new PartialMappingSettings
{
EnforceHttpMethod = enforceHttpMethod
});
}
/// <inheritdoc cref="IWireMockServer.AllowPartialMapping" />
[PublicAPI]
public void AllowPartialMapping(bool allow = true, IPartialMappingSettings partialMappingSettings = null)
{
_settings.Logger.Info("AllowPartialMapping is set to {0}", allow);
_options.AllowPartialMapping = allow;
_options.PartialMappingSettings = partialMappingSettings;
}
/// <inheritdoc cref="IWireMockServer.SetBasicAuthentication" />

View File

@@ -0,0 +1,13 @@
namespace WireMock.Settings
{
/// <summary>
/// IPartialMappingSettings
/// </summary>
public interface IPartialMappingSettings
{
/// <summary>
/// ...
/// </summary>
bool EnforceHttpMethod { get; set; }
}
}

View File

@@ -73,6 +73,12 @@ namespace WireMock.Settings
[PublicAPI]
bool? AllowPartialMapping { get; set; }
/// <summary>
/// Gets or sets the partial mapping settings (optional).
/// </summary>
[PublicAPI]
IPartialMappingSettings PartialMappingSettings { get; set; }
/// <summary>
/// The username needed for __admin access.
/// </summary>

View File

@@ -0,0 +1,15 @@
using JetBrains.Annotations;
namespace WireMock.Settings
{
/// <summary>
/// PartialMappingSettings
/// </summary>
/// <seealso cref="IPartialMappingSettings" />
public class PartialMappingSettings : IPartialMappingSettings
{
/// <inheritdoc cref="IPartialMappingSettings.EnforceHttpMethod"/>
[PublicAPI]
public bool EnforceHttpMethod { get; set; }
}
}

View File

@@ -53,6 +53,10 @@ namespace WireMock.Settings
[PublicAPI]
public bool? AllowPartialMapping { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.PartialMappingSettings"/>
[PublicAPI]
public IPartialMappingSettings PartialMappingSettings { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.AdminUsername"/>
[PublicAPI]
public string AdminUsername { get; set; }

View File

@@ -58,7 +58,7 @@
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
<PackageReference Include="Handlebars.Net.Helpers" Version="1.1.0" />
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug - Sonar'">

View File

@@ -1,5 +1,6 @@
using NFluent;
using System.Collections.Generic;
using System.Collections.Generic;
using FluentAssertions;
using NFluent;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
@@ -13,6 +14,34 @@ namespace WireMock.Net.Tests
{
private const string ClientIp = "::1";
[Fact]
public void Should_Match_When_Verb_Does_Match()
{
// Arrange
var requestPut = Request.Create().WithPath("/bar").UsingPut();
// Act
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "PUT", ClientIp);
// Assert
var requestMatchResult = new RequestMatchResult();
requestPut.GetMatchingScore(request, requestMatchResult).Should().Be(1.0);
}
[Fact]
public void Should_NotMatch_When_Verb_Does_Not_Match()
{
// Arrange
var requestGet = Request.Create().WithPath("/bar").UsingGet();
// Act
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "PUT", ClientIp);
// Assert
var requestMatchResult = new RequestMatchResult();
requestGet.GetMatchingScore(request, requestMatchResult).Should().Be(0.0);
}
[Fact]
public void Should_exclude_requests_matching_given_http_method_but_not_url()
{

View File

@@ -13,35 +13,6 @@ namespace WireMock.Net.Tests.ResponseBuilders
{
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
[Fact]
public async Task Response_WithCallbackAsync()
{
// Assign
var requestMessage = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1");
var response = Response.Create()
.WithCallback(async request =>
{
await Task.Delay(1);
return new ResponseMessage
{
BodyData = new BodyData
{
DetectedBodyType = BodyType.String,
BodyAsString = request.Path + "Bar"
},
StatusCode = 302
};
});
// Act
var responseMessage = await response.ProvideResponseAsync(requestMessage, _settings);
// Assert
responseMessage.BodyData.BodyAsString.Should().Be("/fooBar");
responseMessage.StatusCode.Should().Be(302);
}
[Fact]
public async Task Response_WithCallback()
{

View File

@@ -1,7 +1,6 @@
using System;
using FluentAssertions;
using Moq;
using Moq;
using NFluent;
using System;
using WireMock.Admin.Mappings;
using WireMock.Matchers;
using WireMock.Serialization;
@@ -27,7 +26,7 @@ namespace WireMock.Net.Tests.Serialization
var model = _sut.Map((IMatcher)null);
// Assert
model.Should().BeNull();
Check.That(model).IsNull();
}
[Fact]
@@ -37,7 +36,7 @@ namespace WireMock.Net.Tests.Serialization
var model = _sut.Map((IMatcher[])null);
// Assert
model.Should().BeNull();
Check.That(model).IsNull();
}
[Fact]
@@ -51,7 +50,7 @@ namespace WireMock.Net.Tests.Serialization
var models = _sut.Map(new[] { matcherMock1.Object, matcherMock2.Object });
// Assert
models.Should().HaveCount(2);
Check.That(models).HasSize(2);
}
[Fact]
@@ -66,10 +65,10 @@ namespace WireMock.Net.Tests.Serialization
var model = _sut.Map(matcherMock.Object);
// Assert
model.IgnoreCase.Should().BeNull();
model.Name.Should().Be("test");
model.Pattern.Should().BeNull();
model.Patterns.Should().Contain("p1", "p2");
Check.That(model.IgnoreCase).IsNull();
Check.That(model.Name).Equals("test");
Check.That(model.Pattern).IsNull();
Check.That(model.Patterns).ContainsExactly("p1", "p2");
}
[Fact]
@@ -83,7 +82,7 @@ namespace WireMock.Net.Tests.Serialization
var model = _sut.Map(matcherMock.Object);
// Assert
model.IgnoreCase.Should().BeTrue();
Check.That(model.IgnoreCase).Equals(true);
}
[Fact]
@@ -93,7 +92,7 @@ namespace WireMock.Net.Tests.Serialization
var result = _sut.Map((MatcherModel)null);
// Assert
result.Should().BeNull();
Check.That(result).IsNull();
}
[Fact]
@@ -120,8 +119,8 @@ namespace WireMock.Net.Tests.Serialization
var matcher = (LinqMatcher)_sut.Map(model);
// Assert
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
matcher.GetPatterns().Should().Contain("p");
Check.That(matcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
Check.That(matcher.GetPatterns()).ContainsExactly("p");
}
[Fact]
@@ -138,88 +137,8 @@ namespace WireMock.Net.Tests.Serialization
var matcher = (LinqMatcher)_sut.Map(model);
// Assert
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
matcher.GetPatterns().Should().Contain("p1", "p2");
}
[Fact]
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Pattern_As_String()
{
// Assign
var pattern = "{ \"AccountIds\": [ 1, 2, 3 ] }";
var model = new MatcherModel
{
Name = "JsonMatcher",
Pattern = pattern
};
// Act
var matcher = (JsonMatcher)_sut.Map(model);
// Assert
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
matcher.Value.Should().BeEquivalentTo(pattern);
}
[Fact]
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_As_String()
{
// Assign
var pattern1 = "{ \"AccountIds\": [ 1, 2, 3 ] }";
var pattern2 = "{ \"X\": \"x\" }";
var patterns = new[] { pattern1, pattern2 };
var model = new MatcherModel
{
Name = "JsonMatcher",
Pattern = patterns
};
// Act
var matcher = (JsonMatcher)_sut.Map(model);
// Assert
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
matcher.Value.Should().BeEquivalentTo(patterns);
}
[Fact]
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Pattern_As_Object()
{
// Assign
var pattern = new { AccountIds = new[] { 1, 2, 3 } };
var model = new MatcherModel
{
Name = "JsonMatcher",
Pattern = pattern
};
// Act
var matcher = (JsonMatcher)_sut.Map(model);
// Assert
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
matcher.Value.Should().BeEquivalentTo(pattern);
}
[Fact]
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Patterns_As_Object()
{
// Assign
object pattern1 = new { AccountIds = new[] { 1, 2, 3 } };
object pattern2 = new { X = "x" };
var patterns = new[] { pattern1, pattern2 };
var model = new MatcherModel
{
Name = "JsonMatcher",
Patterns = patterns
};
// Act
var matcher = (JsonMatcher)_sut.Map(model);
// Assert
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
matcher.Value.Should().BeEquivalentTo(patterns);
Check.That(matcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
Check.That(matcher.GetPatterns()).ContainsExactly("p1", "p2");
}
}
}