diff --git a/src/WireMock.Net/Admin/Mappings/MatcherModel.cs b/src/WireMock.Net/Admin/Mappings/MatcherModel.cs
index 54266b80..5033757e 100644
--- a/src/WireMock.Net/Admin/Mappings/MatcherModel.cs
+++ b/src/WireMock.Net/Admin/Mappings/MatcherModel.cs
@@ -24,5 +24,10 @@
/// Gets or sets the ignore case.
///
public bool? IgnoreCase { get; set; }
+
+ ///
+ /// Reject on match.
+ ///
+ public bool? RejectOnMatch { get; set; }
}
}
diff --git a/src/WireMock.Net/Matchers/ExactMatcher.cs b/src/WireMock.Net/Matchers/ExactMatcher.cs
index 002a0cc2..e3dcb183 100644
--- a/src/WireMock.Net/Matchers/ExactMatcher.cs
+++ b/src/WireMock.Net/Matchers/ExactMatcher.cs
@@ -12,21 +12,34 @@ namespace WireMock.Matchers
{
private readonly string[] _values;
+ ///
+ public MatchBehaviour MatchBehaviour { get; }
+
///
/// Initializes a new instance of the class.
///
/// The values.
- public ExactMatcher([NotNull] params string[] values)
+ public ExactMatcher([NotNull] params string[] values) : this(MatchBehaviour.AcceptOnMatch, values)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The values.
+ public ExactMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] values)
{
Check.HasNoNulls(values, nameof(values));
_values = values;
+ MatchBehaviour = matchBehaviour;
}
///
public double IsMatch(string input)
{
- return MatchScores.ToScore(_values.Select(value => value.Equals(input)));
+ return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_values.Select(value => value.Equals(input))));
}
///
@@ -35,10 +48,7 @@ namespace WireMock.Matchers
return _values;
}
- ///
- public string GetName()
- {
- return "ExactMatcher";
- }
+ ///
+ public string Name => "ExactMatcher";
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/ExactObjectMatcher.cs b/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
index 8963bb5d..3f8ebfb7 100644
--- a/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
+++ b/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
@@ -1,5 +1,6 @@
using System.Linq;
using JetBrains.Annotations;
+using WireMock.Validation;
namespace WireMock.Matchers
{
@@ -12,35 +13,59 @@ namespace WireMock.Matchers
private readonly object _object;
private readonly byte[] _bytes;
+ ///
+ public MatchBehaviour MatchBehaviour { get; }
+
///
/// Initializes a new instance of the class.
///
/// The value.
- public ExactObjectMatcher([NotNull] object value)
+ public ExactObjectMatcher([NotNull] object value) : this(MatchBehaviour.AcceptOnMatch, value)
{
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The value.
+ public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] object value)
+ {
+ Check.NotNull(value, nameof(value));
+
_object = value;
+ MatchBehaviour = matchBehaviour;
}
///
/// Initializes a new instance of the class.
///
/// The value.
- public ExactObjectMatcher([NotNull] byte[] value)
+ public ExactObjectMatcher([NotNull] byte[] value) : this(MatchBehaviour.AcceptOnMatch, value)
{
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The value.
+ public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value)
+ {
+ Check.NotNull(value, nameof(value));
+
_bytes = value;
+ MatchBehaviour = matchBehaviour;
}
///
public double IsMatch(object input)
{
bool equals = _object != null ? Equals(_object, input) : _bytes.SequenceEqual((byte[])input);
- return MatchScores.ToScore(equals);
+ return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(equals));
}
- ///
- public string GetName()
- {
- return "ExactObjectMatcher";
- }
+ ///
+ public string Name => "ExactObjectMatcher";
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/IIgnoreCaseMatcher.cs b/src/WireMock.Net/Matchers/IIgnoreCaseMatcher.cs
index 0655982c..b809dbd7 100644
--- a/src/WireMock.Net/Matchers/IIgnoreCaseMatcher.cs
+++ b/src/WireMock.Net/Matchers/IIgnoreCaseMatcher.cs
@@ -3,10 +3,11 @@
///
/// IIgnoreCaseMatcher
///
+ ///
public interface IIgnoreCaseMatcher : IMatcher
{
///
- /// Ignore the case.
+ /// Ignore the case from the pattern.
///
bool IgnoreCase { get; }
}
diff --git a/src/WireMock.Net/Matchers/IMatcher.cs b/src/WireMock.Net/Matchers/IMatcher.cs
index 7462c155..8aba538b 100644
--- a/src/WireMock.Net/Matchers/IMatcher.cs
+++ b/src/WireMock.Net/Matchers/IMatcher.cs
@@ -8,7 +8,12 @@
///
/// Gets the name.
///
- /// Name
- string GetName();
+ string Name { get; }
+
+
+ ///
+ /// Gets the match behaviour.
+ ///
+ MatchBehaviour MatchBehaviour { get; }
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/IStringMatcher.cs b/src/WireMock.Net/Matchers/IStringMatcher.cs
index 7d1ab3fd..c580a33e 100644
--- a/src/WireMock.Net/Matchers/IStringMatcher.cs
+++ b/src/WireMock.Net/Matchers/IStringMatcher.cs
@@ -3,6 +3,7 @@
///
/// IStringMatcher
///
+ ///
public interface IStringMatcher : IMatcher
{
///
diff --git a/src/WireMock.Net/Matchers/JSONPathMatcher.cs b/src/WireMock.Net/Matchers/JSONPathMatcher.cs
index 64f9acf7..8f0a9dcb 100644
--- a/src/WireMock.Net/Matchers/JSONPathMatcher.cs
+++ b/src/WireMock.Net/Matchers/JSONPathMatcher.cs
@@ -14,54 +14,69 @@ namespace WireMock.Matchers
{
private readonly string[] _patterns;
+ ///
+ public MatchBehaviour MatchBehaviour { get; }
+
///
/// Initializes a new instance of the class.
///
/// The patterns.
- public JsonPathMatcher([NotNull] params string[] patterns)
+ public JsonPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The patterns.
+ public JsonPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
{
Check.NotNull(patterns, nameof(patterns));
+ MatchBehaviour = matchBehaviour;
_patterns = patterns;
}
///
public double IsMatch(string input)
{
- if (input == null)
+ double match = MatchScores.Mismatch;
+ if (input != null)
{
- return MatchScores.Mismatch;
+ try
+ {
+ var jtoken = JToken.Parse(input);
+ match = IsMatch(jtoken);
+ }
+ catch (Exception)
+ {
+ // just ignore exception
+ }
}
- try
- {
- var jtoken = JToken.Parse(input);
- return IsMatch(jtoken);
- }
- catch (Exception)
- {
- return MatchScores.Mismatch;
- }
+ return MatchBehaviourHelper.Convert(MatchBehaviour, match);
}
///
public double IsMatch(object input)
{
- if (input == null)
+ double match = MatchScores.Mismatch;
+ if (input != null)
{
- return MatchScores.Mismatch;
+ try
+ {
+ // Check if JToken or object
+ JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
+ match = IsMatch(jtoken);
+ }
+ catch (Exception)
+ {
+ // just ignore exception
+ }
}
- try
- {
- // Check if JToken or object
- JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
- return IsMatch(jtoken);
- }
- catch (Exception)
- {
- return MatchScores.Mismatch;
- }
+ return MatchBehaviourHelper.Convert(MatchBehaviour, match);
}
///
@@ -70,11 +85,8 @@ namespace WireMock.Matchers
return _patterns;
}
- ///
- public string GetName()
- {
- return "JsonPathMatcher";
- }
+ ///
+ public string Name => "JsonPathMatcher";
private double IsMatch(JToken jtoken)
{
diff --git a/src/WireMock.Net/Matchers/MatchBehaviour.cs b/src/WireMock.Net/Matchers/MatchBehaviour.cs
new file mode 100644
index 00000000..874b88eb
--- /dev/null
+++ b/src/WireMock.Net/Matchers/MatchBehaviour.cs
@@ -0,0 +1,18 @@
+namespace WireMock.Matchers
+{
+ ///
+ /// MatchBehaviour
+ ///
+ public enum MatchBehaviour
+ {
+ ///
+ /// Accept on match (default)
+ ///
+ AcceptOnMatch,
+
+ ///
+ /// Reject on match
+ ///
+ RejectOnMatch
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/MatchBehaviourHelper.cs b/src/WireMock.Net/Matchers/MatchBehaviourHelper.cs
new file mode 100644
index 00000000..a45dafec
--- /dev/null
+++ b/src/WireMock.Net/Matchers/MatchBehaviourHelper.cs
@@ -0,0 +1,28 @@
+
+namespace WireMock.Matchers
+{
+ internal static class MatchBehaviourHelper
+ {
+ ///
+ /// Converts the specified match behaviour and match value to a new match value.
+ ///
+ /// if AcceptOnMatch --> return match (default)
+ /// if RejectOnMatch and match = 0.0 --> return 1.0
+ /// if RejectOnMatch and match = 0.? --> return 0.0
+ /// if RejectOnMatch and match = 1.0 --> return 0.0
+ ///
+ ///
+ /// The match behaviour.
+ /// The match.
+ /// match value
+ internal static double Convert(MatchBehaviour matchBehaviour, double match)
+ {
+ if (matchBehaviour == MatchBehaviour.AcceptOnMatch)
+ {
+ return match;
+ }
+
+ return match <= MatchScores.Tolerance ? MatchScores.Perfect : MatchScores.Mismatch;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/RegexMatcher.cs b/src/WireMock.Net/Matchers/RegexMatcher.cs
index 388a6a36..0c73e592 100644
--- a/src/WireMock.Net/Matchers/RegexMatcher.cs
+++ b/src/WireMock.Net/Matchers/RegexMatcher.cs
@@ -9,18 +9,32 @@ namespace WireMock.Matchers
///
/// Regular Expression Matcher
///
- ///
+ ///
+ ///
public class RegexMatcher : IStringMatcher, IIgnoreCaseMatcher
{
private readonly string[] _patterns;
private readonly Regex[] _expressions;
+ ///
+ public MatchBehaviour MatchBehaviour { get; }
+
///
/// Initializes a new instance of the class.
///
/// The pattern.
- /// IgnoreCase
- public RegexMatcher([NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(new [] { pattern }, ignoreCase )
+ /// Ignore the case from the pattern.
+ public RegexMatcher([NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The pattern.
+ /// Ignore the case from the pattern.
+ public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
{
}
@@ -28,13 +42,24 @@ namespace WireMock.Matchers
/// Initializes a new instance of the class.
///
/// The patterns.
- /// IgnoreCase
- public RegexMatcher([NotNull, RegexPattern] string[] patterns, bool ignoreCase = false)
+ /// Ignore the case from the pattern.
+ public RegexMatcher([NotNull, RegexPattern] string[] patterns, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, patterns, ignoreCase)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The patterns.
+ /// Ignore the case from the pattern.
+ public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] string[] patterns, bool ignoreCase = false)
{
Check.NotNull(patterns, nameof(patterns));
_patterns = patterns;
IgnoreCase = ignoreCase;
+ MatchBehaviour = matchBehaviour;
RegexOptions options = RegexOptions.Compiled;
if (ignoreCase)
@@ -48,19 +73,20 @@ namespace WireMock.Matchers
///
public double IsMatch(string input)
{
- if (input == null)
+ double match = MatchScores.Mismatch;
+ if (input != null)
{
- return MatchScores.Mismatch;
- }
-
- try
- {
- return MatchScores.ToScore(_expressions.Select(e => e.IsMatch(input)));
- }
- catch (Exception)
- {
- return MatchScores.Mismatch;
+ try
+ {
+ match = MatchScores.ToScore(_expressions.Select(e => e.IsMatch(input)));
+ }
+ catch (Exception)
+ {
+ // just ignore exception
+ }
}
+
+ return MatchBehaviourHelper.Convert(MatchBehaviour, match);
}
///
@@ -69,11 +95,8 @@ namespace WireMock.Matchers
return _patterns;
}
- ///
- public virtual string GetName()
- {
- return "RegexMatcher";
- }
+ ///
+ public string Name => "RegexMatcher";
///
public bool IgnoreCase { get; }
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
index 2753edd5..ce9f9f5c 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
@@ -33,7 +33,8 @@ namespace WireMock.Matchers.Request
/// Initializes a new instance of the class.
///
/// The body.
- public RequestMessageBodyMatcher([NotNull] string body) : this(new SimMetricsMatcher(body))
+ /// The match behaviour.
+ public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] string body) : this(new SimMetricsMatcher(matchBehaviour, body))
{
}
@@ -41,7 +42,8 @@ namespace WireMock.Matchers.Request
/// Initializes a new instance of the class.
///
/// The body.
- public RequestMessageBodyMatcher([NotNull] byte[] body) : this(new ExactObjectMatcher(body))
+ /// The match behaviour.
+ public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] body) : this(new ExactObjectMatcher(matchBehaviour, body))
{
}
@@ -49,7 +51,8 @@ namespace WireMock.Matchers.Request
/// Initializes a new instance of the class.
///
/// The body.
- public RequestMessageBodyMatcher([NotNull] object body) : this(new ExactObjectMatcher(body))
+ /// The match behaviour.
+ public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] object body) : this(new ExactObjectMatcher(matchBehaviour, body))
{
}
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageClientIPMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageClientIPMatcher.cs
index 6b2d5d69..4ea2e2eb 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageClientIPMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageClientIPMatcher.cs
@@ -25,7 +25,8 @@ namespace WireMock.Matchers.Request
/// Initializes a new instance of the class.
///
/// The clientIPs.
- public RequestMessageClientIPMatcher([NotNull] params string[] clientIPs) : this(clientIPs.Select(ip => new WildcardMatcher(ip)).Cast().ToArray())
+ /// The match behaviour.
+ public RequestMessageClientIPMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] clientIPs) : this(clientIPs.Select(ip => new WildcardMatcher(matchBehaviour, ip)).Cast().ToArray())
{
}
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageCookieMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageCookieMatcher.cs
index 795bd243..af775739 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageCookieMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageCookieMatcher.cs
@@ -29,16 +29,17 @@ namespace WireMock.Matchers.Request
///
/// Initializes a new instance of the class.
///
+ /// The match behaviour.
/// The name.
/// The pattern.
/// The ignoreCase.
- public RequestMessageCookieMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
+ public RequestMessageCookieMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
{
Check.NotNull(name, nameof(name));
Check.NotNull(pattern, nameof(pattern));
Name = name;
- Matchers = new IStringMatcher[] { new WildcardMatcher(pattern, ignoreCase) };
+ Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) };
}
///
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs
index 94800509..b496a682 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageHeaderMatcher.cs
@@ -33,14 +33,16 @@ namespace WireMock.Matchers.Request
///
/// The name.
/// The pattern.
- /// if set to true [ignore case].
- public RequestMessageHeaderMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
+ /// Ignore the case from the pattern.
+ /// The match behaviour.
+ public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase)
{
+
Check.NotNull(name, nameof(name));
Check.NotNull(pattern, nameof(pattern));
Name = name;
- Matchers = new IStringMatcher[] { new WildcardMatcher(pattern, ignoreCase) };
+ Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) };
}
///
@@ -48,14 +50,15 @@ namespace WireMock.Matchers.Request
///
/// The name.
/// The patterns.
- /// if set to true [ignore case].
- public RequestMessageHeaderMatcher([NotNull] string name, [NotNull] string[] patterns, bool ignoreCase = true)
+ /// Ignore the case from the pattern.
+ /// The match behaviour.
+ public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string[] patterns, bool ignoreCase)
{
Check.NotNull(name, nameof(name));
Check.NotNull(patterns, nameof(patterns));
Name = name;
- Matchers = patterns.Select(pattern => new WildcardMatcher(pattern, ignoreCase)).Cast().ToArray();
+ Matchers = patterns.Select(pattern => new WildcardMatcher(matchBehaviour, pattern, ignoreCase)).Cast().ToArray();
}
///
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageMethodMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageMethodMatcher.cs
index 105df40a..59fec1d4 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageMethodMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageMethodMatcher.cs
@@ -9,6 +9,8 @@ namespace WireMock.Matchers.Request
///
internal class RequestMessageMethodMatcher : IRequestMatcher
{
+ private readonly MatchBehaviour _matchBehaviour;
+
///
/// The methods
///
@@ -17,26 +19,20 @@ namespace WireMock.Matchers.Request
///
/// Initializes a new instance of the class.
///
- ///
- /// The verb.
- ///
- public RequestMessageMethodMatcher([NotNull] params string[] methods)
+ /// The match behaviour.
+ /// The methods.
+ public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods)
{
Check.NotNull(methods, nameof(methods));
+ _matchBehaviour = matchBehaviour;
+
Methods = methods.Select(v => v.ToLower()).ToArray();
}
- ///
- /// Determines whether the specified RequestMessage is match.
- ///
- /// The RequestMessage.
- /// The RequestMatchResult.
- ///
- /// A value between 0.0 - 1.0 of the similarity.
- ///
+ ///
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
{
- double score = IsMatch(requestMessage);
+ double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
return requestMatchResult.AddScore(GetType(), score);
}
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
index 604f0880..be6fcee5 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
@@ -12,6 +12,8 @@ namespace WireMock.Matchers.Request
///
public class RequestMessageParamMatcher : IRequestMatcher
{
+ private readonly MatchBehaviour _matchBehaviour;
+
///
/// The funcs
///
@@ -30,20 +32,23 @@ namespace WireMock.Matchers.Request
///
/// Initializes a new instance of the class.
///
+ /// The match behaviour.
/// The key.
- public RequestMessageParamMatcher([NotNull] string key) : this(key, null)
+ public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key) : this(matchBehaviour, key, null)
{
}
///
/// Initializes a new instance of the class.
///
+ /// The match behaviour.
/// The key.
/// The values.
- public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable values)
+ public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] IEnumerable values)
{
Check.NotNull(key, nameof(key));
+ _matchBehaviour = matchBehaviour;
Key = key;
Values = values;
}
@@ -62,7 +67,7 @@ namespace WireMock.Matchers.Request
///
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
{
- double score = IsMatch(requestMessage);
+ double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
return requestMatchResult.AddScore(GetType(), score);
}
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessagePathMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessagePathMatcher.cs
index cec66a6a..8138fe72 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessagePathMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessagePathMatcher.cs
@@ -24,8 +24,9 @@ namespace WireMock.Matchers.Request
///
/// Initializes a new instance of the class.
///
+ /// The match behaviour.
/// The paths.
- public RequestMessagePathMatcher([NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatcher(path)).Cast().ToArray())
+ public RequestMessagePathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatcher(matchBehaviour, path)).Cast().ToArray())
{
}
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageUrlMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageUrlMatcher.cs
index ea256ddc..47432cb2 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageUrlMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageUrlMatcher.cs
@@ -24,8 +24,9 @@ namespace WireMock.Matchers.Request
///
/// Initializes a new instance of the class.
///
+ /// The match behaviour.
/// The urls.
- public RequestMessageUrlMatcher([NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(url)).Cast().ToArray())
+ public RequestMessageUrlMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(matchBehaviour, url)).Cast().ToArray())
{
}
diff --git a/src/WireMock.Net/Matchers/SimMetricsMatcher.cs b/src/WireMock.Net/Matchers/SimMetricsMatcher.cs
index 13e6ee02..4cf08b84 100644
--- a/src/WireMock.Net/Matchers/SimMetricsMatcher.cs
+++ b/src/WireMock.Net/Matchers/SimMetricsMatcher.cs
@@ -16,12 +16,25 @@ namespace WireMock.Matchers
private readonly string[] _patterns;
private readonly SimMetricType _simMetricType;
+ ///
+ public MatchBehaviour MatchBehaviour { get; }
+
///
/// Initializes a new instance of the class.
///
/// The pattern.
/// The SimMetric Type
- public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : this(new [] { pattern }, simMetricType)
+ public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : this(new[] { pattern }, simMetricType)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The pattern.
+ /// The SimMetric Type
+ public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : this(matchBehaviour, new[] { pattern }, simMetricType)
{
}
@@ -30,10 +43,21 @@ namespace WireMock.Matchers
///
/// The patterns.
/// The SimMetric Type
- public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
+ public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein) : this(MatchBehaviour.AcceptOnMatch, patterns, simMetricType)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The patterns.
+ /// The SimMetric Type
+ public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
{
Check.NotNullOrEmpty(patterns, nameof(patterns));
+ MatchBehaviour = matchBehaviour;
_patterns = patterns;
_simMetricType = simMetricType;
}
@@ -43,7 +67,7 @@ namespace WireMock.Matchers
{
IStringMetric m = GetStringMetricType();
- return MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input)));
+ return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input))));
}
private IStringMetric GetStringMetricType()
@@ -95,10 +119,7 @@ namespace WireMock.Matchers
return _patterns;
}
- ///
- public string GetName()
- {
- return $"SimMetricsMatcher.{_simMetricType}";
- }
+ ///
+ public string Name => $"SimMetricsMatcher.{_simMetricType}";
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/WildcardMatcher.cs b/src/WireMock.Net/Matchers/WildcardMatcher.cs
index caed77ec..0ceb2151 100644
--- a/src/WireMock.Net/Matchers/WildcardMatcher.cs
+++ b/src/WireMock.Net/Matchers/WildcardMatcher.cs
@@ -17,7 +17,17 @@ namespace WireMock.Matchers
///
/// The pattern.
/// IgnoreCase
- public WildcardMatcher([NotNull] string pattern, bool ignoreCase = false) : this(new [] { pattern }, ignoreCase)
+ public WildcardMatcher([NotNull] string pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The pattern.
+ /// IgnoreCase
+ public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
{
}
@@ -26,7 +36,17 @@ namespace WireMock.Matchers
///
/// The patterns.
/// IgnoreCase
- public WildcardMatcher([NotNull] string[] patterns, bool ignoreCase = false) : base(patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase)
+ public WildcardMatcher([NotNull] string[] patterns, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, patterns, ignoreCase)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The patterns.
+ /// IgnoreCase
+ public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false) : base(matchBehaviour, patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase)
{
_patterns = patterns;
}
@@ -37,10 +57,7 @@ namespace WireMock.Matchers
return _patterns;
}
- ///
- public override string GetName()
- {
- return "WildcardMatcher";
- }
+ ///
+ public new string Name => "WildcardMatcher";
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/XPathMatcher.cs b/src/WireMock.Net/Matchers/XPathMatcher.cs
index 6586da89..ec09ffe1 100644
--- a/src/WireMock.Net/Matchers/XPathMatcher.cs
+++ b/src/WireMock.Net/Matchers/XPathMatcher.cs
@@ -17,38 +17,52 @@ namespace WireMock.Matchers
{
private readonly string[] _patterns;
+ ///
+ public MatchBehaviour MatchBehaviour { get; }
+
///
/// Initializes a new instance of the class.
///
/// The patterns.
- public XPathMatcher([NotNull] params string[] patterns)
+ public XPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The match behaviour.
+ /// The patterns.
+ public XPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
{
Check.NotNull(patterns, nameof(patterns));
+ MatchBehaviour = matchBehaviour;
_patterns = patterns;
}
///
public double IsMatch(string input)
{
- if (input == null)
+ double match = MatchScores.Mismatch;
+ if (input != null)
{
- return MatchScores.Mismatch;
+ try
+ {
+ var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
+#if NETSTANDARD1_3
+ match = MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
+#else
+ match = MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
+#endif
+ }
+ catch (Exception)
+ {
+ // just ignore exception
+ }
}
- try
- {
- var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
-#if NETSTANDARD1_3
- return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
-#else
- return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
-#endif
- }
- catch (Exception)
- {
- return MatchScores.Mismatch;
- }
+ return MatchBehaviourHelper.Convert(MatchBehaviour, match);
}
///
@@ -57,10 +71,7 @@ namespace WireMock.Matchers
return _patterns;
}
- ///
- public string GetName()
- {
- return "XPathMatcher";
- }
+ ///
+ public string Name => "XPathMatcher";
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs
index 49c4f78f..b3e686f9 100644
--- a/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs
@@ -20,39 +20,42 @@ namespace WireMock.RequestBuilders
/// WithBody: Body as string
///
/// The body.
+ /// The match behaviour.
/// The .
- IRequestBuilder WithBody(string body);
+ IRequestBuilder WithBody(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
/// WithBody: Body as byte[]
///
/// The body.
+ /// The match behaviour.
/// The .
- IRequestBuilder WithBody(byte[] body);
+ IRequestBuilder WithBody(byte[] body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
/// WithBody: Body as object
///
/// The body.
+ /// The match behaviour.
/// The .
- IRequestBuilder WithBody(object body);
+ IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
- ///WithBody: func (string)
+ /// WithBody: func (string)
///
/// The function.
/// The .
IRequestBuilder WithBody([NotNull] Func func);
///
- ///WithBody: func (byte[])
+ /// WithBody: func (byte[])
///
/// The function.
/// The .
IRequestBuilder WithBody([NotNull] Func func);
///
- ///WithBody: func (object)
+ /// WithBody: func (object)
///
/// The function.
/// The .
diff --git a/src/WireMock.Net/RequestBuilders/IClientIPRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IClientIPRequestBuilder.cs
index a830ba68..a9bb8e4f 100644
--- a/src/WireMock.Net/RequestBuilders/IClientIPRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IClientIPRequestBuilder.cs
@@ -10,21 +10,29 @@ namespace WireMock.RequestBuilders
public interface IClientIPRequestBuilder : IUrlAndPathRequestBuilder
{
///
- /// The with ClientIP.
+ /// WithClientIP: add matching on ClientIP matchers.
///
/// The matchers.
/// The .
IRequestBuilder WithClientIP([NotNull] params IStringMatcher[] matchers);
///
- /// The with ClientIP.
+ /// WithClientIP: add matching on clientIPs.
///
/// The clientIPs.
/// The .
IRequestBuilder WithClientIP([NotNull] params string[] clientIPs);
///
- /// The with ClientIP.
+ /// WithClientIP: add matching on clientIPs and matchBehaviour.
+ ///
+ /// The match behaviour.
+ /// The clientIPs.
+ /// The .
+ IRequestBuilder WithClientIP(MatchBehaviour matchBehaviour, [NotNull] params string[] clientIPs);
+
+ ///
+ /// WithClientIP: add matching on ClientIP funcs.
///
/// The path funcs.
/// The .
diff --git a/src/WireMock.Net/RequestBuilders/IHeadersAndCookiesRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IHeadersAndCookiesRequestBuilder.cs
index 78b210ed..a735e564 100644
--- a/src/WireMock.Net/RequestBuilders/IHeadersAndCookiesRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IHeadersAndCookiesRequestBuilder.cs
@@ -12,25 +12,27 @@ namespace WireMock.RequestBuilders
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
{
///
- /// Add Header matching based on name, pattern and ignoreCase.
+ /// WithHeader: matching based on name, pattern, ignoreCase and matchBehaviour.
///
/// The name.
/// The pattern.
- /// ignore Case
+ /// Ignore the case from the pattern.
+ /// The match behaviour.
/// The .
- IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true);
+ IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
- /// Add Header matching based on name, patterns and ignoreCase.
+ /// WithHeader: matching based on name, patterns, ignoreCase and matchBehaviour.
///
/// The name.
/// The patterns.
- /// ignore Case
+ /// Ignore the case from the pattern.
+ /// The match behaviour.
/// The .
- IRequestBuilder WithHeader([NotNull] string name, string[] patterns, bool ignoreCase = true);
+ IRequestBuilder WithHeader([NotNull] string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
- /// The with header.
+ /// WithHeader: matching based on name and IStringMatcher[].
///
/// The name.
/// The matchers.
@@ -38,23 +40,24 @@ namespace WireMock.RequestBuilders
IRequestBuilder WithHeader([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
///
- /// The with header.
+ /// WithHeader: matching based on functions.
///
/// The headers funcs.
/// The .
IRequestBuilder WithHeader([NotNull] params Func, bool>[] funcs);
///
- /// The with cookie.
+ /// WithCookie: cookie matching based on name, pattern, ignoreCase and matchBehaviour.
///
/// The name.
/// The pattern.
- /// ignore Case
+ /// Ignore the case from the pattern.
+ /// The match behaviour.
/// The .
- IRequestBuilder WithCookie([NotNull] string name, string pattern, bool ignoreCase = true);
+ IRequestBuilder WithCookie([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
- /// The with cookie.
+ /// WithCookie: matching based on name and IStringMatcher[].
///
/// The name.
/// The matchers.
@@ -62,7 +65,7 @@ namespace WireMock.RequestBuilders
IRequestBuilder WithCookie([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
///
- /// The with cookie.
+ /// WithCookie: matching based on functions.
///
/// The funcs.
/// The .
diff --git a/src/WireMock.Net/RequestBuilders/IMethodRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IMethodRequestBuilder.cs
index b5a43b90..d7d5fe8d 100644
--- a/src/WireMock.Net/RequestBuilders/IMethodRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IMethodRequestBuilder.cs
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
+using WireMock.Matchers;
namespace WireMock.RequestBuilders
{
@@ -8,66 +9,66 @@ namespace WireMock.RequestBuilders
public interface IMethodRequestBuilder : IHeadersAndCookiesRequestBuilder
{
///
- /// The using delete.
+ /// UsingDelete: add HTTP Method matching on `delete` and matchBehaviour (optional).
///
- ///
- /// The .
- ///
- IRequestBuilder UsingDelete();
-
- ///
- /// The using get.
- ///
- ///
- /// The .
- ///
- IRequestBuilder UsingGet();
-
- ///
- /// The using head.
- ///
- ///
- /// The .
- ///
- IRequestBuilder UsingHead();
-
- ///
- /// The using post.
- ///
- ///
- /// The .
- ///
- IRequestBuilder UsingPost();
-
- ///
- /// The using patch.
- ///
- ///
- /// The .
- ///
- IRequestBuilder UsingPatch();
-
- ///
- /// The using put.
- ///
- ///
- /// The .
- ///
- IRequestBuilder UsingPut();
-
- ///
- /// The using any verb.
- ///
- ///
- /// The .
- ///
- IRequestBuilder UsingAnyVerb();
-
- ///
- /// The using verb.
- ///
- /// The verb.
+ /// The match behaviour.
/// The .
- IRequestBuilder UsingVerb([NotNull] params string[] verbs);
+ IRequestBuilder UsingDelete(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
+
+ ///
+ /// UsingGet: add HTTP Method matching on `get` and matchBehaviour (optional).
+ ///
+ /// The match behaviour.
+ /// The .
+ IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
+
+ ///
+ /// Add HTTP Method matching on `head` and matchBehaviour (optional).
+ ///
+ /// The match behaviour.
+ /// The .
+ IRequestBuilder UsingHead(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
+
+ ///
+ /// UsingPost: add HTTP Method matching on `post` and matchBehaviour (optional).
+ ///
+ /// The match behaviour.
+ /// The .
+ IRequestBuilder UsingPost(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
+
+ ///
+ /// UsingPatch: add HTTP Method matching on `patch` and matchBehaviour (optional).
+ ///
+ /// The match behaviour.
+ /// The .
+ IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
+
+ ///
+ /// UsingPut: add HTTP Method matching on `put` and matchBehaviour (optional).
+ ///
+ /// The match behaviour.
+ /// The .
+ IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
+
+ ///
+ /// UsingAnyMethod: add HTTP Method matching on any method.
+ ///
+ /// The .
+ IRequestBuilder UsingAnyMethod();
+
+ ///
+ /// UsingMethod: add HTTP Method matching on any methods and matchBehaviour.
+ ///
+ /// The match behaviour.
+ /// The methods.
+ /// The .
+ IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, [NotNull] params string[] methods);
+
+ ///
+ /// UsingMethod: add HTTP Method matching on any methods.
+ ///
+ /// The methods.
+ /// The .
+ IRequestBuilder UsingMethod([NotNull] params string[] methods);
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs
index 3b1799aa..0194de0c 100644
--- a/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IParamsRequestBuilder.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
+using WireMock.Matchers;
using WireMock.Util;
namespace WireMock.RequestBuilders
@@ -11,14 +12,15 @@ namespace WireMock.RequestBuilders
public interface IParamsRequestBuilder
{
///
- /// WithParam (key only)
+ /// WithParam: matching on key only.
///
/// The key.
+ /// The match behaviour (optional).
/// The .
- IRequestBuilder WithParam([NotNull] string key);
+ IRequestBuilder WithParam([NotNull] string key, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
///
- /// WithParam (values)
+ /// WithParam: matching on key and values.
///
/// The key.
/// The values.
@@ -26,7 +28,16 @@ namespace WireMock.RequestBuilders
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params string[] values);
///
- /// WithParam (funcs)
+ /// WithParam: matching on key, values and matchBehaviour.
+ ///
+ /// The key.
+ /// The values.
+ /// The match behaviour.
+ /// The .
+ IRequestBuilder WithParam([NotNull] string key, MatchBehaviour matchBehaviour, [CanBeNull] params string[] values);
+
+ ///
+ /// WithParam: matching on functions.
///
/// The funcs.
/// The .
diff --git a/src/WireMock.Net/RequestBuilders/IUrlAndPathRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IUrlAndPathRequestBuilder.cs
index 1f760fa3..a3f979a7 100644
--- a/src/WireMock.Net/RequestBuilders/IUrlAndPathRequestBuilder.cs
+++ b/src/WireMock.Net/RequestBuilders/IUrlAndPathRequestBuilder.cs
@@ -10,42 +10,58 @@ namespace WireMock.RequestBuilders
public interface IUrlAndPathRequestBuilder : IMethodRequestBuilder
{
///
- /// The with path.
+ /// WithPath: add path matching based on IStringMatchers.
///
/// The matchers.
/// The .
IRequestBuilder WithPath([NotNull] params IStringMatcher[] matchers);
///
- /// The with path.
+ /// WithPath: add path matching based on paths.
///
/// The paths.
/// The .
IRequestBuilder WithPath([NotNull] params string[] paths);
///
- /// The with path.
+ /// WithPath: add path matching based on paths and matchBehaviour.
+ ///
+ /// The match behaviour.
+ /// The paths.
+ /// The .
+ IRequestBuilder WithPath(MatchBehaviour matchBehaviour, [NotNull] params string[] paths);
+
+ ///
+ /// WithPath: add path matching based on functions.
///
/// The path funcs.
/// The .
IRequestBuilder WithPath([NotNull] params Func[] funcs);
///
- /// The with url.
+ /// WithUrl: add url matching based on IStringMatcher[].
///
/// The matchers.
/// The .
IRequestBuilder WithUrl([NotNull] params IStringMatcher[] matchers);
///
- /// The with url.
+ /// WithUrl: add url matching based on urls.
///
/// The urls.
/// The .
IRequestBuilder WithUrl([NotNull] params string[] urls);
///
- /// The with path.
+ /// WithUrl: add url matching based on urls.
+ ///
+ /// The match behaviour.
+ /// The urls.
+ /// The .
+ IRequestBuilder WithUrl(MatchBehaviour matchBehaviour, [NotNull] params string[] urls);
+
+ ///
+ /// WithUrl: add url matching based on functions.
///
/// The path func.
/// The .
diff --git a/src/WireMock.Net/RequestBuilders/Request.cs b/src/WireMock.Net/RequestBuilders/Request.cs
index f26e7ce7..c2051d9e 100644
--- a/src/WireMock.Net/RequestBuilders/Request.cs
+++ b/src/WireMock.Net/RequestBuilders/Request.cs
@@ -54,11 +54,7 @@ namespace WireMock.RequestBuilders
return _requestMatchers.Where(rm => rm is T).Cast().FirstOrDefault();
}
- ///
- /// The with clientIP.
- ///
- /// The matchers.
- /// The .
+ ///
public IRequestBuilder WithClientIP(params IStringMatcher[] matchers)
{
Check.NotNullOrEmpty(matchers, nameof(matchers));
@@ -67,24 +63,22 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// The with clientIP.
- ///
- /// The ClientIPs.
- /// The .
+ ///
public IRequestBuilder WithClientIP(params string[] clientIPs)
+ {
+ return WithClientIP(MatchBehaviour.AcceptOnMatch, clientIPs);
+ }
+
+ ///
+ public IRequestBuilder WithClientIP(MatchBehaviour matchBehaviour, params string[] clientIPs)
{
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
- _requestMatchers.Add(new RequestMessageClientIPMatcher(clientIPs));
+ _requestMatchers.Add(new RequestMessageClientIPMatcher(matchBehaviour, clientIPs));
return this;
}
- ///
- /// The with clientIP.
- ///
- /// The clientIP funcs.
- /// The .
+ ///
public IRequestBuilder WithClientIP(params Func[] funcs)
{
Check.NotNullOrEmpty(funcs, nameof(funcs));
@@ -93,11 +87,7 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// The with path.
- ///
- /// The matchers.
- /// The .
+ ///
public IRequestBuilder WithPath(params IStringMatcher[] matchers)
{
Check.NotNullOrEmpty(matchers, nameof(matchers));
@@ -106,24 +96,22 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// The with path.
- ///
- /// The paths.
- /// The .
+ ///
public IRequestBuilder WithPath(params string[] paths)
+ {
+ return WithPath(MatchBehaviour.AcceptOnMatch, paths);
+ }
+
+ ///
+ public IRequestBuilder WithPath(MatchBehaviour matchBehaviour, params string[] paths)
{
Check.NotNullOrEmpty(paths, nameof(paths));
- _requestMatchers.Add(new RequestMessagePathMatcher(paths));
+ _requestMatchers.Add(new RequestMessagePathMatcher(matchBehaviour, paths));
return this;
}
- ///
- /// The with path.
- ///
- /// The path func.
- /// The .
+ ///
public IRequestBuilder WithPath(params Func[] funcs)
{
Check.NotNullOrEmpty(funcs, nameof(funcs));
@@ -132,11 +120,7 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// The with url.
- ///
- /// The matchers.
- /// The .
+ ///
public IRequestBuilder WithUrl(params IStringMatcher[] matchers)
{
Check.NotNullOrEmpty(matchers, nameof(matchers));
@@ -145,24 +129,22 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// The with url.
- ///
- /// The urls.
- /// The .
+ ///
public IRequestBuilder WithUrl(params string[] urls)
+ {
+ return WithUrl(MatchBehaviour.AcceptOnMatch, urls);
+ }
+
+ ///
+ public IRequestBuilder WithUrl(MatchBehaviour matchBehaviour, params string[] urls)
{
Check.NotNullOrEmpty(urls, nameof(urls));
- _requestMatchers.Add(new RequestMessageUrlMatcher(urls));
+ _requestMatchers.Add(new RequestMessageUrlMatcher(matchBehaviour, urls));
return this;
}
- ///
- /// The with url.
- ///
- /// The url func.
- /// The .
+ ///
public IRequestBuilder WithUrl(params Func[] funcs)
{
Check.NotNullOrEmpty(funcs, nameof(funcs));
@@ -171,50 +153,50 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- public IRequestBuilder UsingDelete()
+ ///
+ public IRequestBuilder UsingDelete(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageMethodMatcher("delete"));
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "delete"));
return this;
}
- ///
- public IRequestBuilder UsingGet()
+ ///
+ public IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageMethodMatcher("get"));
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "get"));
return this;
}
- ///
- public IRequestBuilder UsingHead()
+ ///
+ public IRequestBuilder UsingHead(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageMethodMatcher("head"));
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "head"));
return this;
}
- ///
- public IRequestBuilder UsingPost()
+ ///
+ public IRequestBuilder UsingPost(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageMethodMatcher("post"));
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "post"));
return this;
}
- ///
- public IRequestBuilder UsingPatch()
+ ///
+ public IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageMethodMatcher("patch"));
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "patch"));
return this;
}
- ///
- public IRequestBuilder UsingPut()
+ ///
+ public IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageMethodMatcher("put"));
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "put"));
return this;
}
- ///
- public IRequestBuilder UsingAnyVerb()
+ ///
+ public IRequestBuilder UsingAnyMethod()
{
var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
foreach (var matcher in matchers)
@@ -225,33 +207,39 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- public IRequestBuilder UsingVerb(params string[] verbs)
+ ///
+ public IRequestBuilder UsingMethod(params string[] methods)
{
- Check.NotNullOrEmpty(verbs, nameof(verbs));
+ return UsingMethod(MatchBehaviour.AcceptOnMatch, methods);
+ }
- _requestMatchers.Add(new RequestMessageMethodMatcher(verbs));
+ ///
+ public IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, params string[] methods)
+ {
+ Check.NotNullOrEmpty(methods, nameof(methods));
+
+ _requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, methods));
return this;
}
- ///
- public IRequestBuilder WithBody(string body)
+ ///
+ public IRequestBuilder WithBody(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageBodyMatcher(body));
+ _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body));
return this;
}
- ///
- public IRequestBuilder WithBody(byte[] body)
+ ///
+ public IRequestBuilder WithBody(byte[] body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageBodyMatcher(body));
+ _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body));
return this;
}
- ///
- public IRequestBuilder WithBody(object body)
+ ///
+ public IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageBodyMatcher(body));
+ _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body));
return this;
}
@@ -291,21 +279,27 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- public IRequestBuilder WithParam(string key)
+ ///
+ public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
Check.NotNull(key, nameof(key));
- _requestMatchers.Add(new RequestMessageParamMatcher(key));
+ _requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key));
return this;
}
///
public IRequestBuilder WithParam(string key, params string[] values)
+ {
+ return WithParam(key, MatchBehaviour.AcceptOnMatch, values);
+ }
+
+ ///
+ public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, params string[] values)
{
Check.NotNull(key, nameof(key));
- _requestMatchers.Add(new RequestMessageParamMatcher(key, values));
+ _requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, values));
return this;
}
@@ -318,32 +312,27 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true)
+ ///
+ public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
Check.NotNull(name, nameof(name));
Check.NotNull(pattern, nameof(pattern));
- _requestMatchers.Add(new RequestMessageHeaderMatcher(name, pattern, ignoreCase));
+ _requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, pattern, ignoreCase));
return this;
}
- ///
- public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true)
+ ///
+ public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
Check.NotNull(name, nameof(name));
Check.NotNull(patterns, nameof(patterns));
- _requestMatchers.Add(new RequestMessageHeaderMatcher(name, patterns, ignoreCase));
+ _requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, patterns, ignoreCase));
return this;
}
- ///
- /// With header.
- ///
- /// The name.
- /// The matchers.
- /// The .
+ ///
public IRequestBuilder WithHeader(string name, params IStringMatcher[] matchers)
{
Check.NotNull(name, nameof(name));
@@ -353,11 +342,7 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// With header.
- ///
- /// The funcs.
- /// The .
+ ///
public IRequestBuilder WithHeader(params Func, bool>[] funcs)
{
Check.NotNullOrEmpty(funcs, nameof(funcs));
@@ -366,25 +351,14 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// With cookie.
- ///
- /// The name.
- /// The pattern.
- /// if set to true [ignore case].
- /// The .
- public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true)
+ ///
+ public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
- _requestMatchers.Add(new RequestMessageCookieMatcher(name, pattern, ignoreCase));
+ _requestMatchers.Add(new RequestMessageCookieMatcher(matchBehaviour, name, pattern, ignoreCase));
return this;
}
- ///
- /// With cookie.
- ///
- /// The name.
- /// The matchers.
- /// The .
+ ///
public IRequestBuilder WithCookie(string name, params IStringMatcher[] matchers)
{
Check.NotNullOrEmpty(matchers, nameof(matchers));
@@ -393,11 +367,7 @@ namespace WireMock.RequestBuilders
return this;
}
- ///
- /// With header.
- ///
- /// The funcs.
- /// The .
+ ///
public IRequestBuilder WithCookie(params Func, bool>[] funcs)
{
Check.NotNullOrEmpty(funcs, nameof(funcs));
diff --git a/src/WireMock.Net/Serialization/MatcherMapper.cs b/src/WireMock.Net/Serialization/MatcherMapper.cs
index d23ca968..9e2343d2 100644
--- a/src/WireMock.Net/Serialization/MatcherMapper.cs
+++ b/src/WireMock.Net/Serialization/MatcherMapper.cs
@@ -26,7 +26,7 @@ namespace WireMock.Serialization
return new MatcherModel
{
IgnoreCase = ignorecase,
- Name = matcher.GetName(),
+ Name = matcher.Name,
Pattern = patterns.Length == 1 ? patterns.First() : null,
Patterns = patterns.Length > 1 ? patterns : null
};
diff --git a/src/WireMock.Net/Serialization/MatcherModelMapper.cs b/src/WireMock.Net/Serialization/MatcherModelMapper.cs
index 78c1e630..2aea737d 100644
--- a/src/WireMock.Net/Serialization/MatcherModelMapper.cs
+++ b/src/WireMock.Net/Serialization/MatcherModelMapper.cs
@@ -20,23 +20,24 @@ namespace WireMock.Serialization
string matcherType = parts.Length > 1 ? parts[1] : null;
string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
+ var matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
switch (matcherName)
{
case "ExactMatcher":
- return new ExactMatcher(patterns);
+ return new ExactMatcher(matchBehaviour, patterns);
case "RegexMatcher":
- return new RegexMatcher(patterns, matcher.IgnoreCase == true);
+ return new RegexMatcher(matchBehaviour, patterns, matcher.IgnoreCase == true);
case "JsonPathMatcher":
- return new JsonPathMatcher(patterns);
+ return new JsonPathMatcher(matchBehaviour, patterns);
case "XPathMatcher":
- return new XPathMatcher(matcher.Pattern);
+ return new XPathMatcher(matchBehaviour, matcher.Pattern);
case "WildcardMatcher":
- return new WildcardMatcher(patterns, matcher.IgnoreCase == true);
+ return new WildcardMatcher(matchBehaviour, patterns, matcher.IgnoreCase == true);
case "SimMetricsMatcher":
SimMetricType type = SimMetricType.Levenstein;
@@ -45,7 +46,7 @@ namespace WireMock.Serialization
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
}
- return new SimMetricsMatcher(matcher.Pattern, type);
+ return new SimMetricsMatcher(matchBehaviour, matcher.Pattern, type);
default:
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
diff --git a/src/WireMock.Net/Server/FluentMockServer.Admin.cs b/src/WireMock.Net/Server/FluentMockServer.Admin.cs
index 6a9170ae..124215ed 100644
--- a/src/WireMock.Net/Server/FluentMockServer.Admin.cs
+++ b/src/WireMock.Net/Server/FluentMockServer.Admin.cs
@@ -36,8 +36,8 @@ namespace WireMock.Server
private const string AdminRequests = "/__admin/requests";
private const string AdminSettings = "/__admin/settings";
private const string AdminScenarios = "/__admin/scenarios";
- private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
- private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/requests\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
+ private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
+ private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/requests\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
{
@@ -50,7 +50,7 @@ namespace WireMock.Server
{
// __admin/settings
Given(Request.Create().WithPath(AdminSettings).UsingGet()).RespondWith(new DynamicResponseProvider(SettingsGet));
- Given(Request.Create().WithPath(AdminSettings).UsingVerb("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(SettingsUpdate));
+ Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(SettingsUpdate));
// __admin/mappings
@@ -196,7 +196,7 @@ namespace WireMock.Server
private void InitProxyAndRecord(IProxyAndRecordSettings settings)
{
_httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ClientX509Certificate2ThumbprintOrSubjectName);
- Given(Request.Create().WithPath("/*").UsingAnyVerb()).RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
+ Given(Request.Create().WithPath("/*").UsingAnyMethod()).RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
}
private async Task ProxyAndRecordAsync(RequestMessage requestMessage, IProxyAndRecordSettings settings)
@@ -225,7 +225,7 @@ namespace WireMock.Server
{
var request = Request.Create();
request.WithPath(requestMessage.Path);
- request.UsingVerb(requestMessage.Method);
+ request.UsingMethod(requestMessage.Method);
requestMessage.Query.Loop((key, value) => request.WithParam(key, value.ToArray()));
requestMessage.Cookies.Loop((key, value) => request.WithCookie(key, value));
@@ -241,7 +241,7 @@ namespace WireMock.Server
if (requestMessage.Body != null)
{
- request.WithBody(new ExactMatcher(requestMessage.Body));
+ request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.Body));
}
var response = Response.Create(responseMessage);
@@ -648,7 +648,7 @@ namespace WireMock.Server
if (requestModel.Methods != null)
{
- requestBuilder = requestBuilder.UsingVerb(requestModel.Methods);
+ requestBuilder = requestBuilder.UsingMethod(requestModel.Methods);
}
if (requestModel.Headers != null)
diff --git a/src/WireMock.Net/Server/FluentMockServer.cs b/src/WireMock.Net/Server/FluentMockServer.cs
index c7dfce82..cd414824 100644
--- a/src/WireMock.Net/Server/FluentMockServer.cs
+++ b/src/WireMock.Net/Server/FluentMockServer.cs
@@ -256,7 +256,7 @@ namespace WireMock.Server
[PublicAPI]
public void AddCatchAllMapping()
{
- Given(Request.Create().WithPath("/*").UsingAnyVerb())
+ Given(Request.Create().WithPath("/*").UsingAnyMethod())
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
.AtPriority(1000)
.RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }));
@@ -351,7 +351,7 @@ namespace WireMock.Server
Check.NotNull(password, nameof(password));
string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
- _options.AuthorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$");
+ _options.AuthorizationMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, "^(?i)BASIC " + authorization + "$");
}
///
diff --git a/test/WireMock.Net.Tests/FluentMockServerTests.cs b/test/WireMock.Net.Tests/FluentMockServerTests.cs
index aaf3288d..d5bae319 100644
--- a/test/WireMock.Net.Tests/FluentMockServerTests.cs
+++ b/test/WireMock.Net.Tests/FluentMockServerTests.cs
@@ -218,7 +218,7 @@ namespace WireMock.Net.Tests
// given
_server = FluentMockServer.Start();
- _server.Given(Request.Create().WithPath("/foo").UsingVerb("patch"))
+ _server.Given(Request.Create().WithPath("/foo").UsingMethod("patch"))
.RespondWith(Response.Create().WithBody("hello patch"));
// when
@@ -268,7 +268,7 @@ namespace WireMock.Net.Tests
_server = FluentMockServer.Start();
_server
- .Given(Request.Create().UsingAnyVerb())
+ .Given(Request.Create().UsingAnyMethod())
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }));
// Act
@@ -285,7 +285,7 @@ namespace WireMock.Net.Tests
_server = FluentMockServer.Start();
_server
- .Given(Request.Create().UsingAnyVerb())
+ .Given(Request.Create().UsingAnyMethod())
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }, true));
// Act
diff --git a/test/WireMock.Net.Tests/MatchBehaviourHelperTests.cs b/test/WireMock.Net.Tests/MatchBehaviourHelperTests.cs
new file mode 100644
index 00000000..19190189
--- /dev/null
+++ b/test/WireMock.Net.Tests/MatchBehaviourHelperTests.cs
@@ -0,0 +1,25 @@
+using NFluent;
+using WireMock.Matchers;
+using Xunit;
+
+namespace WireMock.Net.Tests
+{
+ 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 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);
+ }
+ }
+}
diff --git a/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs
index 1cffc9bd..1c903df0 100644
--- a/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/ExactMatcherTests.cs
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new ExactMatcher("X");
// Act
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("ExactMatcher");
@@ -46,7 +46,7 @@ namespace WireMock.Net.Tests.Matchers
}
[Fact]
- public void Request_WithBodyExactMatcher_false()
+ public void ExactMatcher_IsMatch_SinglePattern()
{
// Assign
var matcher = new ExactMatcher("cat");
@@ -55,7 +55,33 @@ namespace WireMock.Net.Tests.Matchers
double result = matcher.IsMatch("caR");
// Assert
- Check.That(result).IsStrictlyLessThan(1.0);
+ Check.That(result).IsEqualTo(0.0);
+ }
+
+ [Fact]
+ public void ExactMatcher_IsMatch_SinglePattern_AcceptOnMatch()
+ {
+ // Assign
+ var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, "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, "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/Matchers/ExactObjectMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/ExactObjectMatcherTests.cs
index abd9266f..d6422e07 100644
--- a/test/WireMock.Net.Tests/Matchers/ExactObjectMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/ExactObjectMatcherTests.cs
@@ -14,10 +14,38 @@ namespace WireMock.Net.Tests.Matchers
// Act
var matcher = new ExactObjectMatcher(obj);
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("ExactObjectMatcher");
}
+
+ [Fact]
+ public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
+ {
+ // Assign
+ object obj = 1;
+
+ // Act
+ var matcher = new ExactObjectMatcher(obj);
+ double result = matcher.IsMatch(1);
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void ExactObjectMatcher_IsMatch_RejectOnMatch()
+ {
+ // Assign
+ object obj = 1;
+
+ // Act
+ var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
+ double result = matcher.IsMatch(1);
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Matchers/JsonPathMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/JsonPathMatcherTests.cs
index 6834001b..9183dd79 100644
--- a/test/WireMock.Net.Tests/Matchers/JsonPathMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/JsonPathMatcherTests.cs
@@ -14,7 +14,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new JsonPathMatcher("X");
// Act
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("JsonPathMatcher");
@@ -131,5 +131,18 @@ namespace WireMock.Net.Tests.Matchers
// Assert
Check.That(match).IsEqualTo(1);
}
+
+ [Fact]
+ public void JsonPathMatcher_IsMatch_RejectOnMatch()
+ {
+ // Assign
+ var matcher = new JsonPathMatcher(MatchBehaviour.RejectOnMatch, "$..[?(@.Id == 1)]");
+
+ // Act
+ double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
+
+ // Assert
+ Check.That(match).IsEqualTo(0.0);
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Matchers/RegexMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/RegexMatcherTests.cs
index 0c1446f4..aa390cf6 100644
--- a/test/WireMock.Net.Tests/Matchers/RegexMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/RegexMatcherTests.cs
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new RegexMatcher("");
// Act
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("RegexMatcher");
@@ -65,10 +65,23 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new RegexMatcher("H.*o", true);
// Act
- double result = matcher.IsMatch("hello world!");
+ double result = matcher.IsMatch("hello");
// Assert
Check.That(result).IsEqualTo(1.0d);
}
+
+ [Fact]
+ public void RegexMatcher_IsMatch_RejectOnMatch()
+ {
+ // Assign
+ var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");
+
+ // Act
+ double result = matcher.IsMatch("hello");
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Matchers/SimMetricsMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/SimMetricsMatcherTests.cs
index bc7a9a57..eaa8c819 100644
--- a/test/WireMock.Net.Tests/Matchers/SimMetricsMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/SimMetricsMatcherTests.cs
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new SimMetricsMatcher("X");
// Act
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
@@ -57,5 +57,31 @@ namespace WireMock.Net.Tests.Matchers
// Assert
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
}
+
+ [Fact]
+ public void SimMetricsMatcher_IsMatch_AcceptOnMatch()
+ {
+ // Assign
+ var matcher = new SimMetricsMatcher("test");
+
+ // Act
+ double result = matcher.IsMatch("test");
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void SimMetricsMatcher_IsMatch_RejectOnMatch()
+ {
+ // Assign
+ var matcher = new SimMetricsMatcher(MatchBehaviour.RejectOnMatch, "test");
+
+ // Act
+ double result = matcher.IsMatch("test");
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Matchers/WildcardMatcherTest.cs b/test/WireMock.Net.Tests/Matchers/WildcardMatcherTest.cs
index c399db14..e2d5e636 100644
--- a/test/WireMock.Net.Tests/Matchers/WildcardMatcherTest.cs
+++ b/test/WireMock.Net.Tests/Matchers/WildcardMatcherTest.cs
@@ -65,7 +65,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new WildcardMatcher("x");
// Act
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("WildcardMatcher");
@@ -83,5 +83,17 @@ namespace WireMock.Net.Tests.Matchers
// Assert
Check.That(patterns).ContainsExactly("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);
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/Matchers/XPathMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/XPathMatcherTests.cs
index 91eef858..9102cf6f 100644
--- a/test/WireMock.Net.Tests/Matchers/XPathMatcherTests.cs
+++ b/test/WireMock.Net.Tests/Matchers/XPathMatcherTests.cs
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new XPathMatcher("X");
// Act
- string name = matcher.GetName();
+ string name = matcher.Name;
// Assert
Check.That(name).Equals("XPathMatcher");
@@ -31,5 +31,39 @@ namespace WireMock.Net.Tests.Matchers
// Assert
Check.That(patterns).ContainsExactly("X");
}
+
+ [Fact]
+ public void XPathMatcher_IsMatch_AcceptOnMatch()
+ {
+ // Assign
+ string xml = @"
+
+ abc
+ ";
+ var matcher = new XPathMatcher("/todo-list[count(todo-item) = 1]");
+
+ // Act
+ double result = matcher.IsMatch(xml);
+
+ // Assert
+ Check.That(result).IsEqualTo(1.0);
+ }
+
+ [Fact]
+ public void XPathMatcher_IsMatch_RejectOnMatch()
+ {
+ // Assign
+ string xml = @"
+
+ abc
+ ";
+ var matcher = new XPathMatcher(MatchBehaviour.RejectOnMatch, "/todo-list[count(todo-item) = 1]");
+
+ // Act
+ double result = matcher.IsMatch(xml);
+
+ // Assert
+ Check.That(result).IsEqualTo(0.0);
+ }
}
}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/RequestCookieTests.cs b/test/WireMock.Net.Tests/RequestCookieTests.cs
index 2b88c882..20dbc890 100644
--- a/test/WireMock.Net.Tests/RequestCookieTests.cs
+++ b/test/WireMock.Net.Tests/RequestCookieTests.cs
@@ -15,7 +15,7 @@ namespace WireMock.Net.Tests
public void Request_WithCookie_OK()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithCookie("session", "a*");
+ var spec = Request.Create().UsingAnyMethod().WithCookie("session", "a*");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, null, null, new Dictionary { { "session", "abc" } });
diff --git a/test/WireMock.Net.Tests/RequestMatchers/RequestMessageParamMatcherTests.cs b/test/WireMock.Net.Tests/RequestMatchers/RequestMessageParamMatcherTests.cs
index 87560baf..fa119662 100644
--- a/test/WireMock.Net.Tests/RequestMatchers/RequestMessageParamMatcherTests.cs
+++ b/test/WireMock.Net.Tests/RequestMatchers/RequestMessageParamMatcherTests.cs
@@ -1,5 +1,6 @@
using System;
using NFluent;
+using WireMock.Matchers;
using WireMock.Matchers.Request;
using Xunit;
@@ -12,7 +13,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
- var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
+ var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
var result = new RequestMatchResult();
@@ -27,7 +28,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
- var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
+ var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
var result = new RequestMatchResult();
@@ -42,7 +43,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
- var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
+ var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
var result = new RequestMatchResult();
@@ -57,7 +58,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
- var matcher = new RequestMessageParamMatcher("key");
+ var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key");
// Act
var result = new RequestMatchResult();
@@ -72,7 +73,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
- var matcher = new RequestMessageParamMatcher("key", new string[] { });
+ var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new string[] { });
// Act
var result = new RequestMatchResult();
diff --git a/test/WireMock.Net.Tests/RequestTests.cs b/test/WireMock.Net.Tests/RequestTests.cs
index dbb40711..cfdea63e 100644
--- a/test/WireMock.Net.Tests/RequestTests.cs
+++ b/test/WireMock.Net.Tests/RequestTests.cs
@@ -30,7 +30,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_headers()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tatata");
+ var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tatata");
// when
string bodyAsString = "whatever";
@@ -46,7 +46,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "abc", false);
+ var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "abc", false);
// when
string bodyAsString = "whatever";
@@ -62,7 +62,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_header_prefix()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tata*");
+ var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tata*");
// when
string bodyAsString = "whatever";
@@ -80,7 +80,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_body()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody("Hello world!");
+ var spec = Request.Create().UsingAnyMethod().WithBody("Hello world!");
// when
string bodyAsString = "Hello world!";
@@ -97,7 +97,7 @@ namespace WireMock.Net.Tests
public void Should_exclude_requests_not_matching_given_body()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(" Hello world! ");
+ var spec = Request.Create().UsingAnyMethod().WithBody(" Hello world! ");
// when
string bodyAsString = "xxx";
@@ -127,7 +127,7 @@ namespace WireMock.Net.Tests
public void Should_specify_requests_matching_given_param_func()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithParam(p => p.ContainsKey("bar"));
+ var spec = Request.Create().UsingAnyMethod().WithParam(p => p.ContainsKey("bar"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
diff --git a/test/WireMock.Net.Tests/RequestWithBodyTests.cs b/test/WireMock.Net.Tests/RequestWithBodyTests.cs
index 6e3736c5..1aae7551 100644
--- a/test/WireMock.Net.Tests/RequestWithBodyTests.cs
+++ b/test/WireMock.Net.Tests/RequestWithBodyTests.cs
@@ -19,7 +19,7 @@ namespace WireMock.Net.Tests
public void Request_WithBody_FuncString()
{
// Assign
- var requestBuilder = Request.Create().UsingAnyVerb().WithBody(b => b.Contains("b"));
+ var requestBuilder = Request.Create().UsingAnyMethod().WithBody(b => b.Contains("b"));
// Act
var body = new BodyData
@@ -37,7 +37,7 @@ namespace WireMock.Net.Tests
public void Request_WithBody_FuncJson()
{
// Assign
- var requestBuilder = Request.Create().UsingAnyVerb().WithBody(b => b != null);
+ var requestBuilder = Request.Create().UsingAnyMethod().WithBody(b => b != null);
// Act
var body = new BodyData
@@ -55,7 +55,7 @@ namespace WireMock.Net.Tests
public void Request_WithBody_FuncByteArray()
{
// Assign
- var requestBuilder = Request.Create().UsingAnyVerb().WithBody((byte[] b) => b != null);
+ var requestBuilder = Request.Create().UsingAnyMethod().WithBody((byte[] b) => b != null);
// Act
var body = new BodyData
@@ -73,7 +73,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyExactMatcher()
{
// given
- var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
+ var requestBuilder = Request.Create().UsingAnyMethod().WithBody(new ExactMatcher("cat"));
// when
string bodyAsString = "cat";
@@ -89,7 +89,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyWildcardMatcher()
{
// given
- var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new WildcardMatcher("H*o*"));
+ var spec = Request.Create().WithPath("/foo").UsingAnyMethod().WithBody(new WildcardMatcher("H*o*"));
// when
string bodyAsString = "Hello world!";
@@ -105,7 +105,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyXPathMatcher_true()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
// when
string xmlBodyAsString = @"
@@ -126,7 +126,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyXPathMatcher_false()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
// when
string xmlBodyAsString = @"
@@ -147,7 +147,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyJsonPathMatcher_true()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
// when
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
@@ -163,7 +163,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyJsonPathMatcher_false()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
// when
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
@@ -179,7 +179,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyAsJson_Object_JsonPathMatcher_true()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
// when
string jsonString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
@@ -199,7 +199,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyAsJson_Array_JsonPathMatcher_1()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..books[?(@.price < 10)]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..books[?(@.price < 10)]"));
// when
string jsonString = "{ \"books\": [ { \"category\": \"test1\", \"price\": 8.95 }, { \"category\": \"test2\", \"price\": 20 } ] }";
@@ -220,7 +220,7 @@ namespace WireMock.Net.Tests
public void Request_WithBodyAsJson_Array_JsonPathMatcher_2()
{
// given
- var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..[?(@.Id == 1)]"));
+ var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..[?(@.Id == 1)]"));
// when
string jsonString = "{ \"Id\": 1, \"Name\": \"Test\" }";
@@ -243,7 +243,7 @@ namespace WireMock.Net.Tests
{
// Assign
object body = DateTime.MinValue;
- var requestBuilder = Request.Create().UsingAnyVerb().WithBody(body);
+ var requestBuilder = Request.Create().UsingAnyMethod().WithBody(body);
var bodyData = new BodyData
{
@@ -263,7 +263,7 @@ namespace WireMock.Net.Tests
{
// Assign
byte[] body = { 123 };
- var requestBuilder = Request.Create().UsingAnyVerb().WithBody(body);
+ var requestBuilder = Request.Create().UsingAnyMethod().WithBody(body);
var bodyData = new BodyData
{
diff --git a/test/WireMock.Net.Tests/RequestWithPathTests.cs b/test/WireMock.Net.Tests/RequestWithPathTests.cs
index 6c89b09f..2693d3c0 100644
--- a/test/WireMock.Net.Tests/RequestWithPathTests.cs
+++ b/test/WireMock.Net.Tests/RequestWithPathTests.cs
@@ -17,7 +17,7 @@ namespace WireMock.Net.Tests
public void Request_WithPath_WithHeader_Match()
{
// given
- var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
+ var spec = Request.Create().WithPath("/foo").UsingAnyMethod().WithHeader("X-toto", "tata");
// when
string bodyAsString = "whatever";
diff --git a/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs b/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs
index ae43f5d3..fd306031 100644
--- a/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs
+++ b/test/WireMock.Net.Tests/Serialization/MatcherMapperTests.cs
@@ -47,7 +47,7 @@ namespace WireMock.Net.Tests.Serialization
{
// Assign
var matcherMock = new Mock();
- matcherMock.Setup(m => m.GetName()).Returns("test");
+ matcherMock.Setup(m => m.Name).Returns("test");
matcherMock.Setup(m => m.GetPatterns()).Returns(new[] { "p1", "p2" });
// Act