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

View File

@@ -142,11 +142,11 @@ namespace WireMock.Net.ConsoleApplication
.WithBodyFromFile(@"c:\temp\x.json")
);
server
.Given(Request.Create().WithPath("/file_rel").UsingGet())
.RespondWith(Response.Create()
.WithBodyFromFile("Program.cs", false)
);
//server
// .Given(Request.Create().WithPath("/file_rel").UsingGet())
// .RespondWith(Response.Create()
// .WithBodyFromFile("Program.cs", false)
// );
server
.Given(Request.Create().WithHeader("ProxyThis", "true")
@@ -176,13 +176,13 @@ namespace WireMock.Net.ConsoleApplication
.WithStatusCode(200)
.WithBody("hi"));
server
.Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
.AtPriority(4)
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""Contains x with FUNC 200""}"));
//server
// .Given(Request.Create().WithPath(p => p.Contains("x")).UsingGet())
// .AtPriority(4)
// .RespondWith(Response.Create()
// .WithStatusCode(200)
// .WithHeader("Content-Type", "application/json")
// .WithBody(@"{ ""result"": ""Contains x with FUNC 200""}"));
server
.Given(Request.Create().WithPath("/data").UsingPost().WithBody(b => b.Contains("e")))

View File

@@ -63,7 +63,9 @@ namespace WireMock.Matchers
public double IsMatch(object input)
{
double match = MatchScores.Mismatch;
if (input != null)
// When input is null or byte[], return Mismatch.
if (input != null && !(input is byte[]))
{
try
{

View File

@@ -65,7 +65,9 @@ namespace WireMock.Matchers
public double IsMatch(object input)
{
bool match = false;
if (input != null)
// When input is null or byte[], return Mismatch.
if (input != null && !(input is byte[]))
{
try
{

View File

@@ -33,6 +33,20 @@ namespace WireMock.Net.Tests.Matchers
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]
public void JsonMatcher_IsMatch_NullString()
{

View File

@@ -33,6 +33,20 @@ namespace WireMock.Net.Tests.Matchers
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]
public void JsonPathMatcher_IsMatch_NullString()
{