Fix JsonMatcher and JsonPathMatcher

This commit is contained in:
Stef Heyenrath
2018-08-07 19:27:10 +02:00
parent f13b829c00
commit 4f7259d27a
5 changed files with 46 additions and 14 deletions
@@ -142,11 +142,11 @@ namespace WireMock.Net.ConsoleApplication
.WithBodyFromFile(@"c:\temp\x.json") .WithBodyFromFile(@"c:\temp\x.json")
); );
server //server
.Given(Request.Create().WithPath("/file_rel").UsingGet()) // .Given(Request.Create().WithPath("/file_rel").UsingGet())
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithBodyFromFile("Program.cs", false) // .WithBodyFromFile("Program.cs", false)
); // );
server server
.Given(Request.Create().WithHeader("ProxyThis", "true") .Given(Request.Create().WithHeader("ProxyThis", "true")
@@ -176,13 +176,13 @@ namespace WireMock.Net.ConsoleApplication
.WithStatusCode(200) .WithStatusCode(200)
.WithBody("hi")); .WithBody("hi"));
server //server
.Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet()) // .Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
.AtPriority(4) // .AtPriority(4)
.RespondWith(Response.Create() // .RespondWith(Response.Create()
.WithStatusCode(200) // .WithStatusCode(200)
.WithHeader("Content-Type", "application/json") // .WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""Contains x with FUNC 200""}")); // .WithBody(@"{ ""result"": ""Contains x with FUNC 200""}"));
server server
.Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e"))) .Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e")))
+3 -1
View File
@@ -63,7 +63,9 @@ namespace WireMock.Matchers
public double IsMatch(object input) public double IsMatch(object input)
{ {
double match = MatchScores.Mismatch; double match = MatchScores.Mismatch;
if (input != null)
// When input is null or byte[], return Mismatch.
if (input != null && !(input is byte[]))
{ {
try try
{ {
+3 -1
View File
@@ -65,7 +65,9 @@ namespace WireMock.Matchers
public double IsMatch(object input) public double IsMatch(object input)
{ {
bool match = false; bool match = false;
if (input != null)
// When input is null or byte[], return Mismatch.
if (input != null && !(input is byte[]))
{ {
try try
{ {
@@ -33,6 +33,20 @@ namespace WireMock.Net.Tests.Matchers
Check.That(value).Equals("{}"); Check.That(value).Equals("{}");
} }
[Fact]
public void JsonMatcher_IsMatch_ByteArray()
{
// Assign
var bytes = new byte[0];
var matcher = new JsonMatcher("");
// Act
double match = matcher.IsMatch(bytes);
// Assert
Check.That(match).IsEqualTo(0);
}
[Fact] [Fact]
public void JsonMatcher_IsMatch_NullString() public void JsonMatcher_IsMatch_NullString()
{ {
@@ -33,6 +33,20 @@ namespace WireMock.Net.Tests.Matchers
Check.That(patterns).ContainsExactly("X"); Check.That(patterns).ContainsExactly("X");
} }
[Fact]
public void JsonPathMatcher_IsMatch_ByteArray()
{
// Assign
var bytes = new byte[0];
var matcher = new JsonPathMatcher("");
// Act
double match = matcher.IsMatch(bytes);
// Assert
Check.That(match).IsEqualTo(0);
}
[Fact] [Fact]
public void JsonPathMatcher_IsMatch_NullString() public void JsonPathMatcher_IsMatch_NullString()
{ {