diff --git a/src/WireMock.Net.Abstractions/Models/IBodyData.cs b/src/WireMock.Net.Abstractions/Models/IBodyData.cs
index 3415edb01..389126664 100644
--- a/src/WireMock.Net.Abstractions/Models/IBodyData.cs
+++ b/src/WireMock.Net.Abstractions/Models/IBodyData.cs
@@ -13,12 +13,12 @@ public interface IBodyData
///
/// The body (as bytearray).
///
- byte[] BodyAsBytes { get; set; }
+ byte[]? BodyAsBytes { get; set; }
///
/// Gets or sets the body as a file.
///
- string BodyAsFile { get; set; }
+ string? BodyAsFile { get; set; }
///
/// Is the body as file cached?
@@ -38,7 +38,7 @@ public interface IBodyData
///
/// The body as string, this is defined when BodyAsString or BodyAsJson are not null.
///
- string BodyAsString { get; set; }
+ string? BodyAsString { get; set; }
///
/// The detected body type (detection based on body content).
diff --git a/src/WireMock.Net/Matchers/ExactMatcher.cs b/src/WireMock.Net/Matchers/ExactMatcher.cs
index 70fb1c92e..fecac7d2c 100644
--- a/src/WireMock.Net/Matchers/ExactMatcher.cs
+++ b/src/WireMock.Net/Matchers/ExactMatcher.cs
@@ -1,7 +1,7 @@
+using System;
using System.Linq;
using AnyOfTypes;
using Stef.Validation;
-using WireMock.Extensions;
using WireMock.Models;
namespace WireMock.Matchers;
@@ -9,8 +9,8 @@ namespace WireMock.Matchers;
///
/// ExactMatcher
///
-///
-public class ExactMatcher : IStringMatcher
+/// and
+public class ExactMatcher : IStringMatcher, IIgnoreCaseMatcher
{
private readonly AnyOf[] _values;
@@ -24,7 +24,16 @@ public class ExactMatcher : IStringMatcher
/// Initializes a new instance of the class.
///
/// The values.
- public ExactMatcher(params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, false, MatchOperator.Or, values)
+ public ExactMatcher(params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, false, false, MatchOperator.Or, values)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Ignore the case from the pattern(s).
+ /// The values.
+ public ExactMatcher(bool ignoreCase, params AnyOf[] values) : this(MatchBehaviour.AcceptOnMatch, ignoreCase, false, MatchOperator.Or, values)
{
}
@@ -32,11 +41,13 @@ public ExactMatcher(params AnyOf[] values) : this(MatchBe
/// Initializes a new instance of the class.
///
/// The match behaviour.
+ /// Ignore the case from the pattern(s).
/// Throw an exception when the internal matching fails because of invalid input.
/// The to use. (default = "Or")
/// The values.
public ExactMatcher(
MatchBehaviour matchBehaviour,
+ bool ignoreCase = false,
bool throwException = false,
MatchOperator matchOperator = MatchOperator.Or,
params AnyOf[] values)
@@ -45,13 +56,18 @@ public ExactMatcher(
MatchBehaviour = matchBehaviour;
ThrowException = throwException;
+ IgnoreCase = ignoreCase;
MatchOperator = matchOperator;
}
///
public double IsMatch(string? input)
{
- double score = MatchScores.ToScore(_values.Select(v => v.GetPattern() == input).ToArray(), MatchOperator);
+ Func equals = IgnoreCase
+ ? pattern => string.Equals(pattern, input, StringComparison.OrdinalIgnoreCase)
+ : pattern => pattern == input;
+
+ double score = MatchScores.ToScore(_values.Select(v => equals(v)).ToArray(), MatchOperator);
return MatchBehaviourHelper.Convert(MatchBehaviour, score);
}
@@ -66,4 +82,7 @@ public AnyOf[] GetPatterns()
///
public string Name => "ExactMatcher";
+
+ ///
+ public bool IgnoreCase { get; }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/JsonPartialMatcher.cs b/src/WireMock.Net/Matchers/JsonPartialMatcher.cs
index 84fbbbf57..5ba995182 100644
--- a/src/WireMock.Net/Matchers/JsonPartialMatcher.cs
+++ b/src/WireMock.Net/Matchers/JsonPartialMatcher.cs
@@ -29,7 +29,7 @@ public JsonPartialMatcher(MatchBehaviour matchBehaviour, object value, bool igno
///
protected override bool IsMatch(string value, string input)
{
- var exactStringMatcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, ThrowException, MatchOperator.Or, value);
+ var exactStringMatcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, IgnoreCase, ThrowException, MatchOperator.Or, value);
return MatchScores.IsPerfect(exactStringMatcher.IsMatch(input));
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/MatchOperator.cs b/src/WireMock.Net/Matchers/MatchOperator.cs
index b54adc9e8..50aaced8b 100644
--- a/src/WireMock.Net/Matchers/MatchOperator.cs
+++ b/src/WireMock.Net/Matchers/MatchOperator.cs
@@ -18,5 +18,5 @@ public enum MatchOperator
///
/// The average value from all patterns.
///
- Average,
+ Average
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
index e55e820a4..36d790092 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
@@ -16,22 +16,22 @@ public class RequestMessageBodyMatcher : IRequestMatcher
///
/// The body function
///
- public Func? Func { get; }
+ public Func? Func { get; }
///
/// The body data function for byte[]
///
- public Func? DataFunc { get; }
+ public Func? DataFunc { get; }
///
/// The body data function for json
///
- public Func? JsonFunc { get; }
+ public Func? JsonFunc { get; }
///
/// The body data function for BodyData
///
- public Func? BodyDataFunc { get; }
+ public Func? BodyDataFunc { get; }
///
/// The matchers.
@@ -77,7 +77,7 @@ public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, object body) :
/// Initializes a new instance of the class.
///
/// The function.
- public RequestMessageBodyMatcher(Func func)
+ public RequestMessageBodyMatcher(Func func)
{
Func = Guard.NotNull(func);
}
@@ -86,7 +86,7 @@ public RequestMessageBodyMatcher(Func func)
/// Initializes a new instance of the class.
///
/// The function.
- public RequestMessageBodyMatcher(Func func)
+ public RequestMessageBodyMatcher(Func func)
{
DataFunc = Guard.NotNull(func);
}
@@ -95,7 +95,7 @@ public RequestMessageBodyMatcher(Func func)
/// Initializes a new instance of the class.
///
/// The function.
- public RequestMessageBodyMatcher(Func func)
+ public RequestMessageBodyMatcher(Func func)
{
JsonFunc = Guard.NotNull(func);
}
@@ -158,9 +158,9 @@ private static double CalculateMatchScore(IRequestMessage requestMessage, IMatch
{
// If the body is a byte array, try to match.
var detectedBodyType = requestMessage.BodyData?.DetectedBodyType;
- if (detectedBodyType == BodyType.Bytes || detectedBodyType == BodyType.String)
+ if (detectedBodyType is BodyType.Bytes or BodyType.String)
{
- return exactObjectMatcher.IsMatch(requestMessage.BodyData.BodyAsBytes);
+ return exactObjectMatcher.IsMatch(requestMessage.BodyData?.BodyAsBytes);
}
}
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
index 8ac113d7d..949ed7de0 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
@@ -53,7 +53,7 @@ public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, boo
/// The key.
/// Defines if the key should be matched using case-ignore.
/// The values.
- public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, string[]? values) : this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, false, MatchOperator.And, value)).Cast().ToArray())
+ public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, string[]? values) : this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, ignoreCase, false, MatchOperator.And, value)).Cast().ToArray())
{
}
diff --git a/src/WireMock.Net/Models/BodyData.cs b/src/WireMock.Net/Models/BodyData.cs
index 10319cdb2..d96406375 100644
--- a/src/WireMock.Net/Models/BodyData.cs
+++ b/src/WireMock.Net/Models/BodyData.cs
@@ -11,7 +11,7 @@ public class BodyData : IBodyData
///
public Encoding? Encoding { get; set; }
- ///
+ ///
public string? BodyAsString { get; set; }
///
diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
index 45b7cdd1c..1a1688685 100644
--- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
+++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
@@ -107,7 +107,7 @@ private Task RunHost(CancellationToken token)
{
try
{
- var appLifetime = (IApplicationLifetime)_host.Services.GetService(typeof(IApplicationLifetime));
+ var appLifetime = _host.Services.GetRequiredService();
appLifetime.ApplicationStarted.Register(() =>
{
var addresses = _host.ServerFeatures
diff --git a/src/WireMock.Net/Proxy/ProxyHelper.cs b/src/WireMock.Net/Proxy/ProxyHelper.cs
index 6d6178a4a..26a32a8e9 100644
--- a/src/WireMock.Net/Proxy/ProxyHelper.cs
+++ b/src/WireMock.Net/Proxy/ProxyHelper.cs
@@ -1,10 +1,17 @@
using Stef.Validation;
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
+using WireMock.Constants;
using WireMock.Http;
+using WireMock.Matchers;
+using WireMock.RequestBuilders;
+using WireMock.ResponseBuilders;
using WireMock.Serialization;
using WireMock.Settings;
+using WireMock.Types;
using WireMock.Util;
namespace WireMock.Proxy;
@@ -55,4 +62,69 @@ public ProxyHelper(WireMockServerSettings settings)
return (responseMessage, newMapping);
}
+
+ private IMapping ToMapping(ProxyAndRecordSettings proxyAndRecordSettings, IRequestMessage requestMessage, ResponseMessage responseMessage)
+ {
+ var excludedHeaders = proxyAndRecordSettings.ExcludedHeaders ?? new string[] { };
+ var excludedCookies = proxyAndRecordSettings.ExcludedCookies ?? new string[] { };
+
+ var request = Request.Create();
+ request.WithPath(requestMessage.Path);
+ request.UsingMethod(requestMessage.Method);
+
+ requestMessage.Query?.Loop((key, value) => request.WithParam(key, false, value.ToArray()));
+ requestMessage.Cookies?.Loop((key, value) =>
+ {
+ if (!excludedCookies.Contains(key, StringComparer.OrdinalIgnoreCase))
+ {
+ request.WithCookie(key, value);
+ }
+ });
+
+ var allExcludedHeaders = new List(excludedHeaders) { "Cookie" };
+ requestMessage.Headers?.Loop((key, value) =>
+ {
+ if (!allExcludedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase))
+ {
+ request.WithHeader(key, value.ToArray());
+ }
+ });
+
+ bool throwExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails == true;
+ switch (requestMessage.BodyData?.DetectedBodyType)
+ {
+ case BodyType.Json:
+ request.WithBody(new JsonMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsJson!, true, throwExceptionWhenMatcherFails));
+ break;
+
+ case BodyType.String:
+ request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, false, throwExceptionWhenMatcherFails, MatchOperator.Or, requestMessage.BodyData.BodyAsString));
+ break;
+
+ case BodyType.Bytes:
+ request.WithBody(new ExactObjectMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsBytes, throwExceptionWhenMatcherFails));
+ break;
+ }
+
+ var response = Response.Create(responseMessage);
+
+ return new Mapping
+ (
+ guid: Guid.NewGuid(),
+ title: $"Proxy Mapping for {requestMessage.Method} {requestMessage.Path}",
+ description: string.Empty,
+ path: null,
+ settings: _settings,
+ request,
+ response,
+ priority: WireMockConstants.ProxyPriority, // This was 0
+ scenario: null,
+ executionConditionState: null,
+ nextState: null,
+ stateTimes: null,
+ webhooks: null,
+ useWebhooksFireAndForget: null,
+ timeSettings: null
+ );
+ }
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Serialization/MatcherMapper.cs b/src/WireMock.Net/Serialization/MatcherMapper.cs
index 7b147fbe8..cc5fdca06 100644
--- a/src/WireMock.Net/Serialization/MatcherMapper.cs
+++ b/src/WireMock.Net/Serialization/MatcherMapper.cs
@@ -66,7 +66,7 @@ public MatcherMapper(WireMockServerSettings settings)
return new LinqMatcher(matchBehaviour, throwExceptionWhenMatcherFails, matchOperator, stringPatterns);
case nameof(ExactMatcher):
- return new ExactMatcher(matchBehaviour, throwExceptionWhenMatcherFails, matchOperator, stringPatterns);
+ return new ExactMatcher(matchBehaviour, ignoreCase, throwExceptionWhenMatcherFails, matchOperator, stringPatterns);
case nameof(ExactObjectMatcher):
return CreateExactObjectMatcher(matchBehaviour, stringPatterns[0], throwExceptionWhenMatcherFails);
diff --git a/src/WireMock.Net/Serialization/ProxyMappingConverter.cs b/src/WireMock.Net/Serialization/ProxyMappingConverter.cs
index 67446ad5f..2ee39de5a 100644
--- a/src/WireMock.Net/Serialization/ProxyMappingConverter.cs
+++ b/src/WireMock.Net/Serialization/ProxyMappingConverter.cs
@@ -140,11 +140,11 @@ public IMapping ToMapping(IMapping? mapping, ProxyAndRecordSettings proxyAndReco
break;
case BodyType.String:
- newRequest.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, throwExceptionWhenMatcherFails, MatchOperator.Or, requestMessage.BodyData.BodyAsString));
+ newRequest.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, true, throwExceptionWhenMatcherFails, MatchOperator.Or, requestMessage.BodyData.BodyAsString!));
break;
case BodyType.Bytes:
- newRequest.WithBody(new ExactObjectMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsBytes, throwExceptionWhenMatcherFails));
+ newRequest.WithBody(new ExactObjectMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsBytes!, throwExceptionWhenMatcherFails));
break;
}
}
diff --git a/src/WireMock.Net/Server/IRespondWithAProvider.cs b/src/WireMock.Net/Server/IRespondWithAProvider.cs
index 0efa2a92c..b73d33895 100644
--- a/src/WireMock.Net/Server/IRespondWithAProvider.cs
+++ b/src/WireMock.Net/Server/IRespondWithAProvider.cs
@@ -1,171 +1,169 @@
using System;
using System.Collections.Generic;
-using JetBrains.Annotations;
using WireMock.Models;
using WireMock.ResponseProviders;
using WireMock.Types;
-namespace WireMock.Server
+namespace WireMock.Server;
+
+///
+/// IRespondWithAProvider
+///
+public interface IRespondWithAProvider
{
///
- /// IRespondWithAProvider
- ///
- public interface IRespondWithAProvider
- {
- ///
- /// Gets the unique identifier for this mapping.
- ///
- Guid Guid { get; }
-
- ///
- /// Define a unique identifier for this mapping.
- ///
- /// The unique identifier.
- /// The .
- IRespondWithAProvider WithGuid(Guid guid);
-
- ///
- /// Define the TimeSettings for this mapping.
- ///
- /// The TimeSettings.
- /// The .
- IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings);
-
- ///
- /// Define a unique title for this mapping.
- ///
- /// The unique title.
- /// The .
- IRespondWithAProvider WithTitle(string title);
-
- ///
- /// Define a description for this mapping.
- ///
- /// The description.
- /// The .
- IRespondWithAProvider WithDescription(string description);
-
- ///
- /// Define the full filepath for this mapping.
- ///
- /// The full filepath.
- /// The .
- IRespondWithAProvider WithPath(string path);
-
- ///
- /// Define a unique identifier for this mapping.
- ///
- /// The unique identifier.
- /// The .
- IRespondWithAProvider WithGuid(string guid);
-
- ///
- /// Define the priority for this mapping.
- ///
- /// The priority.
- /// The .
- IRespondWithAProvider AtPriority(int priority);
-
- ///
- /// The respond with.
- ///
- /// The provider.
- void RespondWith(IResponseProvider provider);
-
- ///
- /// Sets the the scenario.
- ///
- /// The scenario.
- /// The .
- IRespondWithAProvider InScenario(string scenario);
-
- ///
- /// Sets the the scenario with an integer value.
- ///
- /// The scenario.
- /// The .
- IRespondWithAProvider InScenario(int scenario);
-
- ///
- /// Execute this respond only in case the current state is equal to specified one.
- ///
- /// Any object which identifies the current state
- /// The .
- IRespondWithAProvider WhenStateIs(string state);
-
- ///
- /// Execute this respond only in case the current state is equal to specified one.
- ///
- /// Any object which identifies the current state
- /// The .
- IRespondWithAProvider WhenStateIs(int state);
-
- ///
- /// Once this mapping is executed the state will be changed to specified one.
- ///
- /// Any object which identifies the new state
- /// The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.
- /// The .
- IRespondWithAProvider WillSetStateTo(string state, int? times = 1);
-
- ///
- /// Once this mapping is executed the state will be changed to specified one.
- ///
- /// Any object which identifies the new state
- /// The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.
- /// The .
- IRespondWithAProvider WillSetStateTo(int state, int? times = 1);
-
- ///
- /// Add (multiple) Webhook(s) to call after the response has been generated.
- ///
- /// The Webhooks
- /// The .
- IRespondWithAProvider WithWebhook(params IWebhook[] webhooks);
-
- ///
- /// Support FireAndForget for any configured Webhooks
- ///
- ///
- ///
- IRespondWithAProvider WithWebhookFireAndForget(bool UseWebhooksFireAndForget);
-
- ///
- /// Add a Webhook to call after the response has been generated.
- ///
- /// The Webhook Url
- /// The method to use. [optional]
- /// The Headers to send. [optional]
- /// The body (as string) to send. [optional]
- /// Use Transformer. [optional]
- /// The transformer type. [optional]
- /// The .
- IRespondWithAProvider WithWebhook(
- [NotNull] string url,
- [CanBeNull] string method = "post",
- [CanBeNull] IDictionary> headers = null,
- [CanBeNull] string body = null,
- bool useTransformer = true,
- TransformerType transformerType = TransformerType.Handlebars
- );
-
- ///
- /// Add a Webhook to call after the response has been generated.
- ///
- /// The Webhook Url
- /// The method to use. [optional]
- /// The Headers to send. [optional]
- /// The body (as json) to send. [optional]
- /// Use Transformer. [optional]
- /// The transformer type. [optional]
- /// The .
- IRespondWithAProvider WithWebhook(
- [NotNull] string url,
- [CanBeNull] string method = "post",
- [CanBeNull] IDictionary> headers = null,
- [CanBeNull] object body = null,
- bool useTransformer = true,
- TransformerType transformerType = TransformerType.Handlebars
- );
- }
+ /// Gets the unique identifier for this mapping.
+ ///
+ Guid Guid { get; }
+
+ ///
+ /// Define a unique identifier for this mapping.
+ ///
+ /// The unique identifier.
+ /// The .
+ IRespondWithAProvider WithGuid(Guid guid);
+
+ ///
+ /// Define the TimeSettings for this mapping.
+ ///
+ /// The TimeSettings.
+ /// The .
+ IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings);
+
+ ///
+ /// Define a unique title for this mapping.
+ ///
+ /// The unique title.
+ /// The .
+ IRespondWithAProvider WithTitle(string title);
+
+ ///
+ /// Define a description for this mapping.
+ ///
+ /// The description.
+ /// The .
+ IRespondWithAProvider WithDescription(string description);
+
+ ///
+ /// Define the full filepath for this mapping.
+ ///
+ /// The full filepath.
+ /// The .
+ IRespondWithAProvider WithPath(string path);
+
+ ///
+ /// Define a unique identifier for this mapping.
+ ///
+ /// The unique identifier.
+ /// The .
+ IRespondWithAProvider WithGuid(string guid);
+
+ ///
+ /// Define the priority for this mapping.
+ ///
+ /// The priority.
+ /// The .
+ IRespondWithAProvider AtPriority(int priority);
+
+ ///
+ /// The respond with.
+ ///
+ /// The provider.
+ void RespondWith(IResponseProvider provider);
+
+ ///
+ /// Sets the the scenario.
+ ///
+ /// The scenario.
+ /// The .
+ IRespondWithAProvider InScenario(string scenario);
+
+ ///
+ /// Sets the the scenario with an integer value.
+ ///
+ /// The scenario.
+ /// The .
+ IRespondWithAProvider InScenario(int scenario);
+
+ ///
+ /// Execute this respond only in case the current state is equal to specified one.
+ ///
+ /// Any object which identifies the current state
+ /// The .
+ IRespondWithAProvider WhenStateIs(string state);
+
+ ///
+ /// Execute this respond only in case the current state is equal to specified one.
+ ///
+ /// Any object which identifies the current state
+ /// The .
+ IRespondWithAProvider WhenStateIs(int state);
+
+ ///
+ /// Once this mapping is executed the state will be changed to specified one.
+ ///
+ /// Any object which identifies the new state
+ /// The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.
+ /// The .
+ IRespondWithAProvider WillSetStateTo(string state, int? times = 1);
+
+ ///
+ /// Once this mapping is executed the state will be changed to specified one.
+ ///
+ /// Any object which identifies the new state
+ /// The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.
+ /// The .
+ IRespondWithAProvider WillSetStateTo(int state, int? times = 1);
+
+ ///
+ /// Add (multiple) Webhook(s) to call after the response has been generated.
+ ///
+ /// The Webhooks
+ /// The .
+ IRespondWithAProvider WithWebhook(params IWebhook[] webhooks);
+
+ ///
+ /// Support FireAndForget for any configured Webhooks
+ ///
+ ///
+ ///
+ IRespondWithAProvider WithWebhookFireAndForget(bool UseWebhooksFireAndForget);
+
+ ///
+ /// Add a Webhook to call after the response has been generated.
+ ///
+ /// The Webhook Url
+ /// The method to use. [optional]
+ /// The Headers to send. [optional]
+ /// The body (as string) to send. [optional]
+ /// Use Transformer. [optional]
+ /// The transformer type. [optional]
+ /// The .
+ IRespondWithAProvider WithWebhook(
+ string url,
+ string? method = "post",
+ IDictionary>? headers = null,
+ string? body = null,
+ bool useTransformer = true,
+ TransformerType transformerType = TransformerType.Handlebars
+ );
+
+ ///
+ /// Add a Webhook to call after the response has been generated.
+ ///
+ /// The Webhook Url
+ /// The method to use. [optional]
+ /// The Headers to send. [optional]
+ /// The body (as json) to send. [optional]
+ /// Use Transformer. [optional]
+ /// The transformer type. [optional]
+ /// The .
+ IRespondWithAProvider WithWebhook(
+ string url,
+ string? method = "post",
+ IDictionary>? headers = null,
+ object? body = null,
+ bool useTransformer = true,
+ TransformerType transformerType = TransformerType.Handlebars
+ );
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Util/DictionaryExtensions.cs b/src/WireMock.Net/Util/DictionaryExtensions.cs
index aeae8ad85..4d92d4631 100644
--- a/src/WireMock.Net/Util/DictionaryExtensions.cs
+++ b/src/WireMock.Net/Util/DictionaryExtensions.cs
@@ -17,6 +17,7 @@ public static class DictionaryExtensions
/// The dictionary to loop (can be null).
/// The action.
public static void Loop(this IDictionary? dictionary, Action action)
+ where TKey : notnull
{
Guard.NotNull(action);
diff --git a/src/WireMock.Net/Util/TypeBuilderUtils.cs b/src/WireMock.Net/Util/TypeBuilderUtils.cs
index d78e717fd..313046b98 100644
--- a/src/WireMock.Net/Util/TypeBuilderUtils.cs
+++ b/src/WireMock.Net/Util/TypeBuilderUtils.cs
@@ -32,7 +32,7 @@ public static Type BuildType(IDictionary properties, string? name
CreateGetSetMethods(typeBuilder, property.Key, property.Value);
}
- var type = typeBuilder.CreateTypeInfo().AsType();
+ var type = typeBuilder.CreateTypeInfo()!.AsType();
Types.TryAdd(properties, type);
@@ -43,6 +43,7 @@ public static Type BuildType(IDictionary properties, string? name
/// https://stackoverflow.com/questions/3804367/testing-for-equality-between-dictionaries-in-c-sharp
///
private static bool Compare(IDictionary dict1, IDictionary dict2)
+ where TKey : notnull
{
if (dict1 == dict2)
{
diff --git a/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs
index bb02ad129..2a6d1e68f 100644
--- a/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs
@@ -2,141 +2,153 @@
using WireMock.Matchers;
using Xunit;
-namespace WireMock.Net.Tests.Matchers
+namespace WireMock.Net.Tests.Matchers;
+
+public class ExactMatcherTests
{
- public class ExactMatcherTests
+ [Fact]
+ public void ExactMatcher_GetName()
+ {
+ // Assign
+ var matcher = new ExactMatcher("X");
+
+ // Act
+ string name = matcher.Name;
+
+ // Assert
+ Check.That(name).Equals("ExactMatcher");
+ }
+
+ [Fact]
+ public void ExactMatcher_GetPatterns()
+ {
+ // Assign
+ var matcher = new ExactMatcher("X");
+
+ // Act
+ var patterns = matcher.GetPatterns();
+
+ // Assert
+ Check.That(patterns).ContainsExactly("X");
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_IgnoreCase()
{
- [Fact]
- public void ExactMatcher_GetName()
- {
- // Assign
- var matcher = new ExactMatcher("X");
-
- // Act
- string name = matcher.Name;
-
- // Assert
- Check.That(name).Equals("ExactMatcher");
- }
-
- [Fact]
- public void ExactMatcher_GetPatterns()
- {
- // Assign
- var matcher = new ExactMatcher("X");
-
- // Act
- var patterns = matcher.GetPatterns();
-
- // Assert
- Check.That(patterns).ContainsExactly("X");
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_WithSinglePattern_ReturnsMatch1_0()
- {
- // Assign
- var matcher = new ExactMatcher("x");
-
- // Act
- double result = matcher.IsMatch("x");
-
- // Assert
- Check.That(result).IsEqualTo(1.0);
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_WithSinglePattern_ReturnsMatch0_0()
- {
- // Assign
- var matcher = new ExactMatcher("x");
-
- // Act
- double result = matcher.IsMatch("y");
-
- // Assert
- Check.That(result).IsEqualTo(0.0);
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_WithMultiplePatterns_Or_ReturnsMatch_1_0()
- {
- // Assign
- var matcher = new ExactMatcher("x", "y");
-
- // Act
- double result = matcher.IsMatch("x");
-
- // Assert
- Check.That(result).IsEqualTo(1.0);
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_WithMultiplePatterns_And_ReturnsMatch_0_0()
- {
- // Assign
- var matcher = new ExactMatcher("x", "y");
-
- // Act
- double result = matcher.IsMatch("x");
-
- // Assert
- Check.That(result).IsEqualTo(1.0);
- }
-
- [Theory]
- [InlineData(MatchOperator.Or, 1.0d)]
- [InlineData(MatchOperator.And, 0.0d)]
- [InlineData(MatchOperator.Average, 0.5d)]
- public void ExactMatcher_IsMatch_WithMultiplePatterns_Average_ReturnsMatch(MatchOperator matchOperator, double score)
- {
- // Assign
- var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, false, matchOperator, "x", "y");
-
- // Act
- double result = matcher.IsMatch("x");
-
- // Assert
- Check.That(result).IsEqualTo(score);
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_SinglePattern()
- {
- // Assign
- var matcher = new ExactMatcher("cat");
-
- // Act
- double result = matcher.IsMatch("caR");
-
- // Assert
- Check.That(result).IsEqualTo(0.0);
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_SinglePattern_AcceptOnMatch()
- {
- // Assign
- var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, false, MatchOperator.Or, "cat");
-
- // Act
- double result = matcher.IsMatch("cat");
-
- // Assert
- Check.That(result).IsEqualTo(1.0);
- }
-
- [Fact]
- public void ExactMatcher_IsMatch_SinglePattern_RejectOnMatch()
- {
- // Assign
- var matcher = new ExactMatcher(MatchBehaviour.RejectOnMatch, false, MatchOperator.Or, "cat");
-
- // Act
- double result = matcher.IsMatch("cat");
-
- // Assert
- Check.That(result).IsEqualTo(0.0);
- }
+ // Assign
+ var matcher = new ExactMatcher(true, "x");
+
+ // Act
+ double result = matcher.IsMatch("X");
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_WithSinglePattern_ReturnsMatch1_0()
+ {
+ // Assign
+ var matcher = new ExactMatcher("x");
+
+ // Act
+ double result = matcher.IsMatch("x");
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_WithSinglePattern_ReturnsMatch0_0()
+ {
+ // Assign
+ var matcher = new ExactMatcher("x");
+
+ // Act
+ double result = matcher.IsMatch("y");
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_WithMultiplePatterns_Or_ReturnsMatch_1_0()
+ {
+ // Assign
+ var matcher = new ExactMatcher("x", "y");
+
+ // Act
+ double result = matcher.IsMatch("x");
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_WithMultiplePatterns_And_ReturnsMatch_0_0()
+ {
+ // Assign
+ var matcher = new ExactMatcher("x", "y");
+
+ // Act
+ double result = matcher.IsMatch("x");
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Theory]
+ [InlineData(MatchOperator.Or, 1.0d)]
+ [InlineData(MatchOperator.And, 0.0d)]
+ [InlineData(MatchOperator.Average, 0.5d)]
+ public void ExactMatcher_IsMatch_WithMultiplePatterns_Average_ReturnsMatch(MatchOperator matchOperator, double score)
+ {
+ // Assign
+ var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, false, false, matchOperator, "x", "y");
+
+ // Act
+ double result = matcher.IsMatch("x");
+
+ // Assert
+ Check.That(result).IsEqualTo(score);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_SinglePattern()
+ {
+ // Assign
+ var matcher = new ExactMatcher("cat");
+
+ // Act
+ double result = matcher.IsMatch("caR");
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_SinglePattern_AcceptOnMatch()
+ {
+ // Assign
+ var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, false, false, MatchOperator.Or, "cat");
+
+ // Act
+ double result = matcher.IsMatch("cat");
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_SinglePattern_RejectOnMatch()
+ {
+ // Assign
+ var matcher = new ExactMatcher(MatchBehaviour.RejectOnMatch, false, false, MatchOperator.Or, "cat");
+
+ // Act
+ double result = matcher.IsMatch("cat");
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs b/test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs
index 86897a0e8..59a654cd0 100644
--- a/test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs
+++ b/test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs
@@ -13,455 +13,454 @@
using WireMock.Util;
using Xunit;
-namespace WireMock.Net.Tests.RequestMatchers
+namespace WireMock.Net.Tests.RequestMatchers;
+
+public class RequestMessageBodyMatcherTests
{
- public class RequestMessageBodyMatcherTests
+ [Fact]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatcher()
{
- [Fact]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatcher()
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsString = "b",
- DetectedBodyType = BodyType.String
- };
- var stringMatcherMock = new Mock();
- stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1d);
+ BodyAsString = "b",
+ DetectedBodyType = BodyType.String
+ };
+ var stringMatcherMock = new Mock();
+ stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1d);
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
+ var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(1d);
+ // Assert
+ Check.That(score).IsEqualTo(1d);
- // Verify
- stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock.Verify(m => m.IsMatch("b"), Times.Once);
- }
+ // Verify
+ stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock.Verify(m => m.IsMatch("b"), Times.Once);
+ }
- [Theory]
- [InlineData(1d, 1d, 1d)]
- [InlineData(0d, 1d, 1d)]
- [InlineData(1d, 0d, 1d)]
- [InlineData(0d, 0d, 0d)]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatchers_Or(double one, double two, double expected)
+ [Theory]
+ [InlineData(1d, 1d, 1d)]
+ [InlineData(0d, 1d, 1d)]
+ [InlineData(1d, 0d, 1d)]
+ [InlineData(0d, 0d, 0d)]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatchers_Or(double one, double two, double expected)
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsString = "b",
- DetectedBodyType = BodyType.String
- };
- var stringMatcherMock1 = new Mock();
- stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny())).Returns(one);
+ BodyAsString = "b",
+ DetectedBodyType = BodyType.String
+ };
+ var stringMatcherMock1 = new Mock();
+ stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny())).Returns(one);
- var stringMatcherMock2 = new Mock();
- stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny())).Returns(two);
+ var stringMatcherMock2 = new Mock();
+ stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny())).Returns(two);
- var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
+ var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(MatchOperator.Or, matchers.Cast().ToArray());
+ var matcher = new RequestMessageBodyMatcher(MatchOperator.Or, matchers.Cast().ToArray());
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(expected);
+ // Assert
+ Check.That(score).IsEqualTo(expected);
- // Verify
- stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock1.Verify(m => m.IsMatch("b"), Times.Once);
+ // Verify
+ stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock1.Verify(m => m.IsMatch("b"), Times.Once);
- stringMatcherMock2.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock2.Verify(m => m.IsMatch("b"), Times.Once);
- stringMatcherMock2.VerifyNoOtherCalls();
- }
+ stringMatcherMock2.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock2.Verify(m => m.IsMatch("b"), Times.Once);
+ stringMatcherMock2.VerifyNoOtherCalls();
+ }
- [Theory]
- [InlineData(1d, 1d, 1d)]
- [InlineData(0d, 1d, 0d)]
- [InlineData(1d, 0d, 0d)]
- [InlineData(0d, 0d, 0d)]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatchers_And(double one, double two, double expected)
+ [Theory]
+ [InlineData(1d, 1d, 1d)]
+ [InlineData(0d, 1d, 0d)]
+ [InlineData(1d, 0d, 0d)]
+ [InlineData(0d, 0d, 0d)]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatchers_And(double one, double two, double expected)
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsString = "b",
- DetectedBodyType = BodyType.String
- };
- var stringMatcherMock1 = new Mock();
- stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny())).Returns(one);
+ BodyAsString = "b",
+ DetectedBodyType = BodyType.String
+ };
+ var stringMatcherMock1 = new Mock();
+ stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny())).Returns(one);
- var stringMatcherMock2 = new Mock();
- stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny())).Returns(two);
+ var stringMatcherMock2 = new Mock();
+ stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny())).Returns(two);
- var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
+ var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(MatchOperator.And, matchers.Cast().ToArray());
+ var matcher = new RequestMessageBodyMatcher(MatchOperator.And, matchers.Cast().ToArray());
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(expected);
+ // Assert
+ Check.That(score).IsEqualTo(expected);
- // Verify
- stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock1.Verify(m => m.IsMatch("b"), Times.Once);
+ // Verify
+ stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock1.Verify(m => m.IsMatch("b"), Times.Once);
- stringMatcherMock2.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock2.Verify(m => m.IsMatch("b"), Times.Once);
- stringMatcherMock2.VerifyNoOtherCalls();
- }
+ stringMatcherMock2.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock2.Verify(m => m.IsMatch("b"), Times.Once);
+ stringMatcherMock2.VerifyNoOtherCalls();
+ }
- [Theory]
- [InlineData(1d, 1d, 1d)]
- [InlineData(0d, 1d, 0.5d)]
- [InlineData(1d, 0d, 0.5d)]
- [InlineData(0d, 0d, 0d)]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatchers_Average(double one, double two, double expected)
+ [Theory]
+ [InlineData(1d, 1d, 1d)]
+ [InlineData(0d, 1d, 0.5d)]
+ [InlineData(1d, 0d, 0.5d)]
+ [InlineData(0d, 0d, 0d)]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatchers_Average(double one, double two, double expected)
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsString = "b",
- DetectedBodyType = BodyType.String
- };
- var stringMatcherMock1 = new Mock();
- stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny())).Returns(one);
+ BodyAsString = "b",
+ DetectedBodyType = BodyType.String
+ };
+ var stringMatcherMock1 = new Mock();
+ stringMatcherMock1.Setup(m => m.IsMatch(It.IsAny())).Returns(one);
- var stringMatcherMock2 = new Mock();
- stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny())).Returns(two);
+ var stringMatcherMock2 = new Mock();
+ stringMatcherMock2.Setup(m => m.IsMatch(It.IsAny())).Returns(two);
- var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
+ var matchers = new[] { stringMatcherMock1.Object, stringMatcherMock2.Object };
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(MatchOperator.Average, matchers.Cast().ToArray());
+ var matcher = new RequestMessageBodyMatcher(MatchOperator.Average, matchers.Cast().ToArray());
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(expected);
+ // Assert
+ Check.That(score).IsEqualTo(expected);
- // Verify
- stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock1.Verify(m => m.IsMatch("b"), Times.Once);
+ // Verify
+ stringMatcherMock1.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock1.Verify(m => m.IsMatch("b"), Times.Once);
- stringMatcherMock2.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock2.Verify(m => m.IsMatch("b"), Times.Once);
- }
+ stringMatcherMock2.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock2.Verify(m => m.IsMatch("b"), Times.Once);
+ }
- [Fact]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_IStringMatcher()
+ [Fact]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_IStringMatcher()
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsBytes = new byte[] { 1 },
- DetectedBodyType = BodyType.Bytes
- };
- var stringMatcherMock = new Mock();
- stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(0.5d);
+ BodyAsBytes = new byte[] { 1 },
+ DetectedBodyType = BodyType.Bytes
+ };
+ var stringMatcherMock = new Mock();
+ stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(0.5d);
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
+ var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(0.0d);
+ // Assert
+ Check.That(score).IsEqualTo(0.0d);
- // Verify
- stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
- stringMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Never);
- }
+ // Verify
+ stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
+ stringMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Never);
+ }
- [Fact]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_IStringMatcher()
+ [Fact]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_IStringMatcher()
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsJson = new { value = 42 },
- DetectedBodyType = BodyType.Json
- };
- var stringMatcherMock = new Mock();
- stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1.0d);
+ BodyAsJson = new { value = 42 },
+ DetectedBodyType = BodyType.Json
+ };
+ var stringMatcherMock = new Mock();
+ stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1.0d);
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
+ var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(1.0d);
+ // Assert
+ Check.That(score).IsEqualTo(1.0d);
- // Verify
- stringMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Once);
- }
+ // Verify
+ stringMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Once);
+ }
- [Fact]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_and_BodyAsString_IStringMatcher()
+ [Fact]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_and_BodyAsString_IStringMatcher()
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsJson = new { value = 42 },
- BodyAsString = "orig",
- DetectedBodyType = BodyType.Json
- };
- var stringMatcherMock = new Mock();
- stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1d);
- stringMatcherMock.SetupGet(m => m.MatchOperator).Returns(MatchOperator.Or);
+ BodyAsJson = new { value = 42 },
+ BodyAsString = "orig",
+ DetectedBodyType = BodyType.Json
+ };
+ var stringMatcherMock = new Mock();
+ stringMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1d);
+ stringMatcherMock.SetupGet(m => m.MatchOperator).Returns(MatchOperator.Or);
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
+ var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(1d);
+ // Assert
+ Check.That(score).IsEqualTo(1d);
- // Verify
- stringMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Once);
- }
+ // Verify
+ stringMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Once);
+ }
- [Fact]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_IObjectMatcher()
+ [Fact]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_IObjectMatcher()
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsJson = 42,
- DetectedBodyType = BodyType.Json
- };
- var objectMatcherMock = new Mock();
- objectMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1d);
+ BodyAsJson = 42,
+ DetectedBodyType = BodyType.Json
+ };
+ var objectMatcherMock = new Mock();
+ objectMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1d);
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
+ var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(1d);
+ // Assert
+ Check.That(score).IsEqualTo(1d);
- // Verify
- objectMatcherMock.Verify(m => m.IsMatch(42), Times.Once);
- }
+ // Verify
+ objectMatcherMock.Verify(m => m.IsMatch(42), Times.Once);
+ }
- [Fact]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_CSharpCodeMatcher()
+ [Fact]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_CSharpCodeMatcher()
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsJson = new { value = 42 },
- DetectedBodyType = BodyType.Json
- };
+ BodyAsJson = new { value = 42 },
+ DetectedBodyType = BodyType.Json
+ };
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(new CSharpCodeMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.Or, "return it.value == 42;"));
+ var matcher = new RequestMessageBodyMatcher(new CSharpCodeMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.Or, "return it.value == 42;"));
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(1.0d);
- }
+ // Assert
+ Check.That(score).IsEqualTo(1.0d);
+ }
- [Theory]
- [InlineData(null, 0.0)]
- [InlineData(new byte[0], 0.0)]
- [InlineData(new byte[] { 48 }, 1.0)]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_NotNullOrEmptyObjectMatcher(byte[] bytes, double expected)
+ [Theory]
+ [InlineData(null, 0.0)]
+ [InlineData(new byte[0], 0.0)]
+ [InlineData(new byte[] { 48 }, 1.0)]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_NotNullOrEmptyObjectMatcher(byte[] bytes, double expected)
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsBytes = bytes,
- DetectedBodyType = BodyType.Bytes
- };
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ BodyAsBytes = bytes,
+ DetectedBodyType = BodyType.Bytes
+ };
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(new NotNullOrEmptyMatcher());
+ var matcher = new RequestMessageBodyMatcher(new NotNullOrEmptyMatcher());
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- score.Should().Be(expected);
- }
+ // Assert
+ score.Should().Be(expected);
+ }
- [Theory]
- [InlineData(null, 0.0)]
- [InlineData("", 0.0)]
- [InlineData("x", 1.0)]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_NotNullOrEmptyObjectMatcher(string data, double expected)
+ [Theory]
+ [InlineData(null, 0.0)]
+ [InlineData("", 0.0)]
+ [InlineData("x", 1.0)]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_NotNullOrEmptyObjectMatcher(string data, double expected)
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsString = data,
- DetectedBodyType = BodyType.String
- };
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ BodyAsString = data,
+ DetectedBodyType = BodyType.String
+ };
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(new NotNullOrEmptyMatcher());
+ var matcher = new RequestMessageBodyMatcher(new NotNullOrEmptyMatcher());
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- score.Should().Be(expected);
- }
+ // Assert
+ score.Should().Be(expected);
+ }
- [Theory]
- [InlineData(new byte[] { 1 })]
- [InlineData(new byte[] { 48 })]
- public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_IObjectMatcher(byte[] bytes)
+ [Theory]
+ [InlineData(new byte[] { 1 })]
+ [InlineData(new byte[] { 48 })]
+ public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_IObjectMatcher(byte[] bytes)
+ {
+ // Assign
+ var body = new BodyData
{
- // Assign
- var body = new BodyData
- {
- BodyAsBytes = bytes,
- DetectedBodyType = BodyType.Bytes
- };
- var objectMatcherMock = new Mock();
- objectMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1.0d);
+ BodyAsBytes = bytes,
+ DetectedBodyType = BodyType.Bytes
+ };
+ var objectMatcherMock = new Mock();
+ objectMatcherMock.Setup(m => m.IsMatch(It.IsAny())).Returns(1.0d);
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
- var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
+ var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
- // Act
- var result = new RequestMatchResult();
- double score = matcher.GetMatchingScore(requestMessage, result);
+ // Act
+ var result = new RequestMatchResult();
+ double score = matcher.GetMatchingScore(requestMessage, result);
- // Assert
- Check.That(score).IsEqualTo(1.0d);
+ // Assert
+ Check.That(score).IsEqualTo(1.0d);
- // Verify
- objectMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Once);
- }
+ // Verify
+ objectMatcherMock.Verify(m => m.IsMatch(It.IsAny()), Times.Once);
+ }
- [Theory]
- [MemberData(nameof(MatchingScoreData))]
- public async Task RequestMessageBodyMatcher_GetMatchingScore_Funcs_Matching(object body, RequestMessageBodyMatcher matcher, bool shouldMatch)
+ [Theory]
+ [MemberData(nameof(MatchingScoreData))]
+ public async Task RequestMessageBodyMatcher_GetMatchingScore_Funcs_Matching(object body, RequestMessageBodyMatcher matcher, bool shouldMatch)
+ {
+ // assign
+ BodyData bodyData;
+ if (body is byte[] b)
{
- // assign
- BodyData bodyData;
- if (body is byte[] b)
+ var bodyParserSettings = new BodyParserSettings
{
- var bodyParserSettings = new BodyParserSettings
- {
- Stream = new MemoryStream(b),
- ContentType = null,
- DeserializeJson = true
- };
- bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
- }
- else if (body is string s)
- {
- var bodyParserSettings = new BodyParserSettings
- {
- Stream = new MemoryStream(Encoding.UTF8.GetBytes(s)),
- ContentType = null,
- DeserializeJson = true
- };
- bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
- }
- else
+ Stream = new MemoryStream(b),
+ ContentType = null,
+ DeserializeJson = true
+ };
+ bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
+ }
+ else if (body is string s)
+ {
+ var bodyParserSettings = new BodyParserSettings
{
- throw new Exception();
- }
+ Stream = new MemoryStream(Encoding.UTF8.GetBytes(s)),
+ ContentType = null,
+ DeserializeJson = true
+ };
+ bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
+ }
+ else
+ {
+ throw new Exception();
+ }
- var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", bodyData);
+ var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", bodyData);
- // act
- var result = new RequestMatchResult();
- var score = matcher.GetMatchingScore(requestMessage, result);
+ // act
+ var result = new RequestMatchResult();
+ var score = matcher.GetMatchingScore(requestMessage, result);
- // assert
- Check.That(score).IsEqualTo(shouldMatch ? 1d : 0d);
- }
+ // assert
+ Check.That(score).IsEqualTo(shouldMatch ? 1d : 0d);
+ }
- public static TheoryData MatchingScoreData
+ public static TheoryData MatchingScoreData
+ {
+ get
{
- get
+ var json = "{'a':'b'}";
+ var str = "HelloWorld";
+ var bytes = new byte[] { 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00 };
+
+ return new TheoryData
{
- var json = "{'a':'b'}";
- var str = "HelloWorld";
- var bytes = new byte[] { 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00 };
-
- return new TheoryData
- {
- // JSON match +++
- {json, new RequestMessageBodyMatcher((object o) => ((dynamic) o).a == "b"), true},
- {json, new RequestMessageBodyMatcher((string s) => s == json), true},
- {json, new RequestMessageBodyMatcher((byte[] b) => b.SequenceEqual(Encoding.UTF8.GetBytes(json))), true},
-
- // JSON no match ---
- {json, new RequestMessageBodyMatcher((object o) => false), false},
- {json, new RequestMessageBodyMatcher((string s) => false), false},
- {json, new RequestMessageBodyMatcher((byte[] b) => false), false},
- {json, new RequestMessageBodyMatcher(), false },
-
- // string match +++
- {str, new RequestMessageBodyMatcher((object o) => o == null), true},
- {str, new RequestMessageBodyMatcher((string s) => s == str), true},
- {str, new RequestMessageBodyMatcher((byte[] b) => b.SequenceEqual(Encoding.UTF8.GetBytes(str))), true},
-
- // string no match ---
- {str, new RequestMessageBodyMatcher((object o) => false), false},
- {str, new RequestMessageBodyMatcher((string s) => false), false},
- {str, new RequestMessageBodyMatcher((byte[] b) => false), false},
- {str, new RequestMessageBodyMatcher(), false },
-
- // binary match +++
- {bytes, new RequestMessageBodyMatcher((object o) => o == null), true},
- {bytes, new RequestMessageBodyMatcher((string s) => s == null), true},
- {bytes, new RequestMessageBodyMatcher((byte[] b) => b.SequenceEqual(bytes)), true},
-
- // binary no match ---
- {bytes, new RequestMessageBodyMatcher((object o) => false), false},
- {bytes, new RequestMessageBodyMatcher((string s) => false), false},
- {bytes, new RequestMessageBodyMatcher((byte[] b) => false), false},
- {bytes, new RequestMessageBodyMatcher(), false },
- };
- }
+ // JSON match +++
+ {json, new RequestMessageBodyMatcher((object? o) => ((dynamic) o!).a == "b"), true},
+ {json, new RequestMessageBodyMatcher((string? s) => s == json), true},
+ {json, new RequestMessageBodyMatcher((byte[]? b) => b.SequenceEqual(Encoding.UTF8.GetBytes(json))), true},
+
+ // JSON no match ---
+ {json, new RequestMessageBodyMatcher((object? o) => false), false},
+ {json, new RequestMessageBodyMatcher((string? s) => false), false},
+ {json, new RequestMessageBodyMatcher((byte[]? b) => false), false},
+ {json, new RequestMessageBodyMatcher(), false },
+
+ // string match +++
+ {str, new RequestMessageBodyMatcher((object? o) => o == null), true},
+ {str, new RequestMessageBodyMatcher((string? s) => s == str), true},
+ {str, new RequestMessageBodyMatcher((byte[]? b) => b.SequenceEqual(Encoding.UTF8.GetBytes(str))), true},
+
+ // string no match ---
+ {str, new RequestMessageBodyMatcher((object? o) => false), false},
+ {str, new RequestMessageBodyMatcher((string? s) => false), false},
+ {str, new RequestMessageBodyMatcher((byte[]? b) => false), false},
+ {str, new RequestMessageBodyMatcher(), false },
+
+ // binary match +++
+ {bytes, new RequestMessageBodyMatcher((object? o) => o == null), true},
+ {bytes, new RequestMessageBodyMatcher((string? s) => s == null), true},
+ {bytes, new RequestMessageBodyMatcher((byte[]? b) => b.SequenceEqual(bytes)), true},
+
+ // binary no match ---
+ {bytes, new RequestMessageBodyMatcher((object? o) => false), false},
+ {bytes, new RequestMessageBodyMatcher((string? s) => false), false},
+ {bytes, new RequestMessageBodyMatcher((byte[]? b) => false), false},
+ {bytes, new RequestMessageBodyMatcher(), false },
+ };
}
}
-}
+}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithTransformerTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithTransformerTests.cs
index 3cf177e38..17f283539 100644
--- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithTransformerTests.cs
+++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithTransformerTests.cs
@@ -80,7 +80,7 @@ public async Task Response_ProvideResponse_Transformer_UrlPathVerb(TransformerTy
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test http://localhost/foo /foo POSt");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test http://localhost/foo /foo POSt");
}
[Theory]
@@ -104,7 +104,7 @@ public async Task Response_ProvideResponse_Transformer_UrlPath(TransformerType t
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("url=http://localhost/a/b absoluteurl=http://localhost/wiremock/a/b path=/a/b absolutepath=/wiremock/a/b");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("url=http://localhost/a/b absoluteurl=http://localhost/wiremock/a/b path=/a/b absolutepath=/wiremock/a/b");
}
[Fact]
@@ -122,7 +122,7 @@ public async Task Response_ProvideResponse_Handlebars_PathSegments()
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("a wiremock");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("a wiremock");
}
[Theory(Skip = "Invalid token `OpenBracket`")]
@@ -142,7 +142,7 @@ public async Task Response_ProvideResponse_Scriban_PathSegments(TransformerType
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("a wiremock");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("a wiremock");
}
[Fact]
@@ -164,7 +164,7 @@ public async Task Response_ProvideResponse_Handlebars_Query()
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test keya=1,2 idx=1 idx=2 keyb=5");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test keya=1,2 idx=1 idx=2 keyb=5");
}
[Theory(Skip = "Invalid token `OpenBracket`")]
@@ -188,7 +188,7 @@ public async Task Response_ProvideResponse_Scriban_Query(TransformerType transfo
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test keya=1 idx=1 idx=2 keyb=5");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test keya=1 idx=1 idx=2 keyb=5");
}
[Fact]
@@ -211,7 +211,7 @@ public async Task Response_ProvideResponse_Handlebars_StatusCode()
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.StatusCode).Equals("400");
}
@@ -237,7 +237,7 @@ public async Task Response_ProvideResponse_Scriban_StatusCode(TransformerType tr
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.StatusCode).Equals("400");
}
@@ -263,7 +263,7 @@ public async Task Response_ProvideResponse_Transformer_StatusCodeIsNull(Transfor
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.StatusCode).Equals(null);
}
@@ -331,7 +331,7 @@ public async Task Response_ProvideResponse_Handlebars_Headers()
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.Headers).ContainsKey("x");
Check.That(response.Message.Headers["x"]).Contains("text/plain");
Check.That(response.Message.Headers["x"]).Contains("http://localhost/foo");
@@ -356,7 +356,7 @@ public async Task Response_ProvideResponse_Scriban_Headers(TransformerType trans
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test");
Check.That(response.Message.Headers).ContainsKey("x");
Check.That(response.Message.Headers["x"]).Contains("text/plain");
Check.That(response.Message.Headers["x"]).Contains("http://localhost/foo");
@@ -384,7 +384,7 @@ public async Task Response_ProvideResponse_Transformer_Origin_Port_Protocol_Host
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
- Check.That(response.Message.BodyData.BodyAsString).Equals("test http://localhost:1234 1234 http localhost");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals("test http://localhost:1234 1234 http localhost");
}
[Theory]
@@ -644,7 +644,7 @@ public async Task Response_ProvideResponse_Transformer_WithBodyAsFile_And_Transf
// Assert
Check.That(response.Message.BodyData.BodyAsFile).Equals(@"c:\1\test.xml");
Check.That(response.Message.BodyData.DetectedBodyType).Equals(BodyType.String);
- Check.That(response.Message.BodyData.BodyAsString).Equals(" ");
+ Check.That(response.Message.BodyData!.BodyAsString).Equals(" ");
}
[Theory]
diff --git a/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs b/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs
index d2853f231..f72299a80 100644
--- a/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs
+++ b/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs
@@ -408,4 +408,24 @@ public void MatcherMapper_Map_MatcherModel_JsonPartialWildcardMatcher_Patterns_A
matcher.Value.Should().BeEquivalentTo(pattern);
matcher.Regex.Should().BeFalse();
}
+
+ [Fact]
+ public void MatcherMapper_Map_MatcherModel_ExactMatcher_Pattern()
+ {
+ // Assign
+ var model = new MatcherModel
+ {
+ Name = "ExactMatcher",
+ Pattern = "p",
+ IgnoreCase = true
+ };
+
+ // Act
+ var matcher = (ExactMatcher)_sut.Map(model)!;
+
+ // Assert
+ matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
+ matcher.GetPatterns().Should().Contain("p");
+ matcher.IgnoreCase.Should().BeTrue();
+ }
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Serialization/files/proxy.json b/test/WireMock.Net.Tests/Serialization/files/proxy.json
index a045bc7a9..ec51e133a 100644
--- a/test/WireMock.Net.Tests/Serialization/files/proxy.json
+++ b/test/WireMock.Net.Tests/Serialization/files/proxy.json
@@ -46,7 +46,8 @@
"Matchers": [
{
"Name": "ExactMatcher",
- "Pattern": "p1-v"
+ "Pattern": "p1-v",
+ "IgnoreCase": false
}
]
},
@@ -55,7 +56,8 @@
"Matchers": [
{
"Name": "ExactMatcher",
- "Pattern": "p2-v"
+ "Pattern": "p2-v",
+ "IgnoreCase": false
}
]
}
diff --git a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj
index 597423be5..8c3eb968a 100644
--- a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj
+++ b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj
@@ -10,9 +10,6 @@
true
{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}
-
-
true
../../src/WireMock.Net/WireMock.Net.snk
@@ -38,7 +35,6 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
@@ -53,17 +49,11 @@
-
-
-
-
-
-