Write logging in case a Matcher throws an exception (#986)

* ThrowException

* ...

* .

* ...

* b

* fix test

* ...

* .

* sonar

* ft

* .

* fix tst
This commit is contained in:
Stef Heyenrath
2023-08-21 20:07:46 +02:00
committed by GitHub
parent 09a302baf2
commit 93c87845c2
88 changed files with 1266 additions and 1244 deletions

View File

@@ -60,29 +60,17 @@ public class JsonPartialMatcherTests
}
[Fact]
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
public void JsonPartialMatcher_IsMatch_WithInvalidValue_Should_ReturnMismatch_And_Exception_ShouldBeSet()
{
// Assign
var matcher = new JsonPartialMatcher("");
// Act
double match = matcher.IsMatch(new MemoryStream());
var result = matcher.IsMatch(new MemoryStream());
// Assert
Check.That(match).IsEqualTo(0);
}
[Fact]
public void JsonPartialMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
{
// Assign
var matcher = new JsonPartialMatcher("", 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]
@@ -93,7 +81,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher("");
// Act
double match = matcher.IsMatch(bytes);
double match = matcher.IsMatch(bytes).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -107,7 +95,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher("");
// Act
double match = matcher.IsMatch(s);
double match = matcher.IsMatch(s).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -121,7 +109,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher("");
// Act
double match = matcher.IsMatch(o);
double match = matcher.IsMatch(o).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -139,7 +127,7 @@ public class JsonPartialMatcherTests
"x",
"y"
};
double match = matcher.IsMatch(jArray);
double match = matcher.IsMatch(jArray).Score;
// Assert
Assert.Equal(1.0, match);
@@ -157,7 +145,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -167,7 +155,7 @@ public class JsonPartialMatcherTests
public void JsonPartialMatcher_IsMatch_WithRegexTrue()
{
// Assign
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" }, false, false, true);
var matcher = new JsonPartialMatcher(new { Id = "^\\d+$", Name = "Test" }, false, true);
// Act
var jObject = new JObject
@@ -175,7 +163,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -193,7 +181,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -203,10 +191,11 @@ public class JsonPartialMatcherTests
public void JsonPartialMatcher_IsMatch_GuidAsString_UsingRegex()
{
var guid = new Guid("1111238e-b775-44a9-a263-95e570135c94");
var matcher = new JsonPartialMatcher(new {
var matcher = new JsonPartialMatcher(new
{
Id = 1,
Name = "^1111[a-fA-F0-9]{4}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$"
}, false, false, true);
}, false, true);
// Act
var jObject = new JObject
@@ -214,7 +203,7 @@ public class JsonPartialMatcherTests
{ "Id", new JValue(1) },
{ "Name", new JValue(guid) }
};
double match = matcher.IsMatch(jObject);
double match = matcher.IsMatch(jObject).Score;
// Assert
Assert.Equal(1.0, match);
@@ -232,7 +221,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -246,7 +235,7 @@ public class JsonPartialMatcherTests
// 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);
@@ -260,7 +249,7 @@ public class JsonPartialMatcherTests
// 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);
@@ -278,7 +267,7 @@ public class JsonPartialMatcherTests
"x",
"y"
};
double match = matcher.IsMatch(jArray);
double match = matcher.IsMatch(jArray).Score;
// Assert
Assert.Equal(1.0, match);
@@ -296,7 +285,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -305,20 +294,20 @@ public class JsonPartialMatcherTests
[Fact]
public void JsonPartialMatcher_IsMatch_GuidAsString()
{
// Assign
var guid = Guid.NewGuid();
var matcher = new JsonPartialMatcher(new { Id = 1, Name = guid });
// Assign
var guid = Guid.NewGuid();
var matcher = new JsonPartialMatcher(new { Id = 1, Name = guid });
// Act
var jObject = new JObject
{
{ "Id", new JValue(1) },
{ "Name", new JValue(guid.ToString()) }
};
double match = matcher.IsMatch(jObject);
// Act
var jObject = new JObject
{
{ "Id", new JValue(1) },
{ "Name", new JValue(guid.ToString()) }
};
double match = matcher.IsMatch(jObject).Score;
// Assert
Assert.Equal(1.0, match);
// Assert
Assert.Equal(1.0, match);
}
[Fact]
@@ -333,7 +322,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -351,7 +340,7 @@ public class JsonPartialMatcherTests
{ "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);
@@ -368,7 +357,7 @@ public class JsonPartialMatcherTests
{
{ "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);
@@ -391,7 +380,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher(value);
// Act
double match = matcher.IsMatch(input);
double match = matcher.IsMatch(input).Score;
// Assert
Assert.Equal(1.0, match);
@@ -415,7 +404,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher(value);
// Act
double match = matcher.IsMatch(input);
double match = matcher.IsMatch(input).Score;
// Assert
Assert.Equal(0.0, match);
@@ -434,7 +423,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher(value);
// Act
double match = matcher.IsMatch(input);
double match = matcher.IsMatch(input).Score;
// Assert
Assert.Equal(1.0, match);
@@ -453,7 +442,7 @@ public class JsonPartialMatcherTests
var matcher = new JsonPartialMatcher(value);
// Act
double match = matcher.IsMatch(input);
double match = matcher.IsMatch(input).Score;
// Assert
Assert.Equal(0.0, match);