diff --git a/examples/WireMock.Net.ConsoleApplication/MainApp.cs b/examples/WireMock.Net.ConsoleApplication/MainApp.cs
index 09e4e290c..0627c0207 100644
--- a/examples/WireMock.Net.ConsoleApplication/MainApp.cs
+++ b/examples/WireMock.Net.ConsoleApplication/MainApp.cs
@@ -41,6 +41,15 @@ public static void Run()
// .RespondWith(Response.Create()
// .WithProxy("http://restcountries.eu"));
+ server
+ .Given(Request
+ .Create()
+ .WithPath("/jsonthings")
+ .WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"))
+ .UsingPut())
+ .RespondWith(Response.Create()
+ .WithBody(@"{ ""result"": ""JsonPathMatcher !!!""}"));
+
server
.Given(Request
.Create()
diff --git a/src/WireMock.Net/Matchers/ExactMatcher.cs b/src/WireMock.Net/Matchers/ExactMatcher.cs
index fb5354e4e..5923140e2 100644
--- a/src/WireMock.Net/Matchers/ExactMatcher.cs
+++ b/src/WireMock.Net/Matchers/ExactMatcher.cs
@@ -7,8 +7,8 @@ namespace WireMock.Matchers
///
/// ExactMatcher
///
- ///
- public class ExactMatcher : IMatcher
+ ///
+ public class ExactMatcher : IStringMatcher
{
private readonly string[] _values;
@@ -23,29 +23,19 @@ public ExactMatcher([NotNull] params string[] values)
_values = values;
}
- ///
- /// Determines whether the specified input is match.
- ///
- /// The input.
- /// A value between 0.0 - 1.0 of the similarity.
+ ///
public double IsMatch(string input)
{
return MatchScores.ToScore(_values.Select(value => value.Equals(input)));
}
- ///
- /// Gets the value.
- ///
- /// Patterns
+ ///
public string[] GetPatterns()
{
return _values;
}
- ///
- /// Gets the name.
- ///
- /// Name
+ ///
public string GetName()
{
return "ExactMatcher";
diff --git a/src/WireMock.Net/Matchers/ExactObjectMatcher.cs b/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
new file mode 100644
index 000000000..8963bb5da
--- /dev/null
+++ b/src/WireMock.Net/Matchers/ExactObjectMatcher.cs
@@ -0,0 +1,46 @@
+using System.Linq;
+using JetBrains.Annotations;
+
+namespace WireMock.Matchers
+{
+ ///
+ /// ExactMatcher
+ ///
+ ///
+ public class ExactObjectMatcher : IObjectMatcher
+ {
+ private readonly object _object;
+ private readonly byte[] _bytes;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The value.
+ public ExactObjectMatcher([NotNull] object value)
+ {
+ _object = value;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The value.
+ public ExactObjectMatcher([NotNull] byte[] value)
+ {
+ _bytes = value;
+ }
+
+ ///
+ public double IsMatch(object input)
+ {
+ bool equals = _object != null ? Equals(_object, input) : _bytes.SequenceEqual((byte[])input);
+ return MatchScores.ToScore(equals);
+ }
+
+ ///
+ public string GetName()
+ {
+ return "ExactObjectMatcher";
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/IMatcher.cs b/src/WireMock.Net/Matchers/IMatcher.cs
index 4bcd2cff6..7462c1554 100644
--- a/src/WireMock.Net/Matchers/IMatcher.cs
+++ b/src/WireMock.Net/Matchers/IMatcher.cs
@@ -5,19 +5,6 @@
///
public interface IMatcher
{
- ///
- /// Determines whether the specified input is match.
- ///
- /// The input.
- /// A value between 0.0 - 1.0 of the similarity.
- double IsMatch(string input);
-
- ///
- /// Gets the patterns.
- ///
- /// Patterns
- string[] GetPatterns();
-
///
/// Gets the name.
///
diff --git a/src/WireMock.Net/Matchers/IObjectMatcher.cs b/src/WireMock.Net/Matchers/IObjectMatcher.cs
new file mode 100644
index 000000000..883e246d9
--- /dev/null
+++ b/src/WireMock.Net/Matchers/IObjectMatcher.cs
@@ -0,0 +1,15 @@
+namespace WireMock.Matchers
+{
+ ///
+ /// IObjectMatcher
+ ///
+ public interface IObjectMatcher : IMatcher
+ {
+ ///
+ /// Determines whether the specified input is match.
+ ///
+ /// The input.
+ /// A value between 0.0 - 1.0 of the similarity.
+ double IsMatch(object input);
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/IStringMatcher.cs b/src/WireMock.Net/Matchers/IStringMatcher.cs
new file mode 100644
index 000000000..7d1ab3fdb
--- /dev/null
+++ b/src/WireMock.Net/Matchers/IStringMatcher.cs
@@ -0,0 +1,21 @@
+namespace WireMock.Matchers
+{
+ ///
+ /// IStringMatcher
+ ///
+ public interface IStringMatcher : IMatcher
+ {
+ ///
+ /// Determines whether the specified input is match.
+ ///
+ /// The input.
+ /// A value between 0.0 - 1.0 of the similarity.
+ double IsMatch(string input);
+
+ ///
+ /// Gets the patterns.
+ ///
+ /// Patterns
+ string[] GetPatterns();
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net/Matchers/JSONPathMatcher.cs b/src/WireMock.Net/Matchers/JSONPathMatcher.cs
index c92b01890..aab0b86cc 100644
--- a/src/WireMock.Net/Matchers/JSONPathMatcher.cs
+++ b/src/WireMock.Net/Matchers/JSONPathMatcher.cs
@@ -10,8 +10,9 @@ namespace WireMock.Matchers
/// JSONPathMatcher
///
///
- public class JsonPathMatcher : IMatcher
+ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
{
+ // private readonly object _jsonPattern;
private readonly string[] _patterns;
///
@@ -25,15 +26,20 @@ public JsonPathMatcher([NotNull] params string[] patterns)
_patterns = patterns;
}
- ///
- /// Determines whether the specified input is match.
- ///
- /// The input string
- /// A value between 0.0 - 1.0 of the similarity.
+ //public JsonPathMatcher([NotNull] object jsonPattern)
+ //{
+ // Check.NotNull(jsonPattern, nameof(jsonPattern));
+
+ // _jsonPattern = jsonPattern;
+ //}
+
+ ///
public double IsMatch(string input)
{
if (input == null)
+ {
return MatchScores.Mismatch;
+ }
try
{
@@ -47,19 +53,33 @@ public double IsMatch(string input)
}
}
- ///
- /// Gets the patterns.
- ///
- /// Pattern
+ ///
+ public double IsMatch(object input)
+ {
+ if (input == null)
+ {
+ return MatchScores.Mismatch;
+ }
+
+ try
+ {
+ var o = input as JObject ?? JObject.FromObject(input);
+
+ return MatchScores.ToScore(_patterns.Select(p => o.SelectToken(p) != null));
+ }
+ catch (Exception)
+ {
+ return MatchScores.Mismatch;
+ }
+ }
+
+ ///
public string[] GetPatterns()
{
return _patterns;
}
- ///
- /// Gets the name.
- ///
- /// Name
+ ///
public string GetName()
{
return "JsonPathMatcher";
diff --git a/src/WireMock.Net/Matchers/RegexMatcher.cs b/src/WireMock.Net/Matchers/RegexMatcher.cs
index 918f0e9a2..004c69d92 100644
--- a/src/WireMock.Net/Matchers/RegexMatcher.cs
+++ b/src/WireMock.Net/Matchers/RegexMatcher.cs
@@ -9,8 +9,8 @@ namespace WireMock.Matchers
///
/// Regular Expression Matcher
///
- ///
- public class RegexMatcher : IMatcher
+ ///
+ public class RegexMatcher : IStringMatcher
{
private readonly string[] _patterns;
private readonly Regex[] _expressions;
@@ -37,20 +37,20 @@ public RegexMatcher([NotNull, RegexPattern] string[] patterns, bool ignoreCase =
RegexOptions options = RegexOptions.Compiled;
if (ignoreCase)
+ {
options |= RegexOptions.IgnoreCase;
+ }
_expressions = patterns.Select(p => new Regex(p, options)).ToArray();
}
- ///
- /// Determines whether the specified input is match.
- ///
- /// The input string
- /// A value between 0.0 - 1.0 of the similarity.
+ ///
public double IsMatch(string input)
{
if (input == null)
+ {
return MatchScores.Mismatch;
+ }
try
{
@@ -62,21 +62,13 @@ public double IsMatch(string input)
}
}
- ///
- /// Gets the patterns.
- ///
- /// Pattern
+ ///
public virtual string[] GetPatterns()
{
return _patterns;
}
- ///
- /// Gets the name.
- ///
- ///
- /// Name
- ///
+ ///
public virtual string GetName()
{
return "RegexMatcher";
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
index 2e0891b45..c3cad3090 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs
@@ -9,21 +9,21 @@ namespace WireMock.Matchers.Request
///
public class RequestMessageBodyMatcher : IRequestMatcher
{
- ///
- /// The body as byte[].
- ///
- private readonly byte[] _bodyData;
-
///
/// The body function
///
public Func Func { get; }
///
- /// The body data function
+ /// The body data function for byte[]
///
public Func DataFunc { get; }
+ ///
+ /// The body data function for json
+ ///
+ public Func