mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-22 08:47:51 +01:00
Fix JsonMatcher and JsonPathMatcher
This commit is contained in:
@@ -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")))
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user