mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-25 10:19:04 +02:00
Write logging in case a Matcher throws an exception (#986)
* ThrowException * ... * . * ... * b * fix test * ... * . * sonar * ft * . * fix tst
This commit is contained in:
@@ -82,29 +82,17 @@ public class JsonMatcherTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
||||
public void JsonMatcher_IsMatch_WithInvalidValue_Should_ReturnMismatch_And_Exception_ShouldBeSet()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new MemoryStream());
|
||||
var result = matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonMatcher("", false, true);
|
||||
|
||||
// Act
|
||||
Action action = () => matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
result.Score.Should().Be(MatchScores.Mismatch);
|
||||
result.Exception.Should().BeAssignableTo<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -115,7 +103,7 @@ public class JsonMatcherTests
|
||||
var matcher = new JsonMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(bytes);
|
||||
double match = matcher.IsMatch(bytes).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
@@ -129,7 +117,7 @@ public class JsonMatcherTests
|
||||
var matcher = new JsonMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
double match = matcher.IsMatch(s).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
@@ -143,7 +131,7 @@ public class JsonMatcherTests
|
||||
var matcher = new JsonMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
double match = matcher.IsMatch(o).Score;
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
@@ -161,7 +149,7 @@ public class JsonMatcherTests
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
double match = matcher.IsMatch(jArray).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -179,7 +167,7 @@ public class JsonMatcherTests
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -197,7 +185,7 @@ public class JsonMatcherTests
|
||||
{ "Id", new JValue(1) },
|
||||
{ "NaMe", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -211,7 +199,7 @@ public class JsonMatcherTests
|
||||
|
||||
// Act
|
||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -225,7 +213,7 @@ public class JsonMatcherTests
|
||||
|
||||
// Act
|
||||
var jObject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -243,7 +231,7 @@ public class JsonMatcherTests
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
double match = matcher.IsMatch(jArray).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -261,7 +249,7 @@ public class JsonMatcherTests
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -279,7 +267,7 @@ public class JsonMatcherTests
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -297,7 +285,7 @@ public class JsonMatcherTests
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
@@ -314,7 +302,7 @@ public class JsonMatcherTests
|
||||
{
|
||||
{ "preferredAt", new JValue("2019-11-21T10:32:53.2210009+00:00") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
@@ -331,7 +319,7 @@ public class JsonMatcherTests
|
||||
{
|
||||
{ "NormalEnum", new JValue(0) }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
match.Should().Be(1.0);
|
||||
@@ -348,7 +336,7 @@ public class JsonMatcherTests
|
||||
{
|
||||
{ "EnumWithJsonConverter", new JValue("Type1") }
|
||||
};
|
||||
double match = matcher.IsMatch(jObject);
|
||||
double match = matcher.IsMatch(jObject).Score;
|
||||
|
||||
// Assert
|
||||
match.Should().Be(1.0);
|
||||
|
||||
Reference in New Issue
Block a user