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
@@ -42,7 +42,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("");
// Act
double match = matcher.IsMatch(bytes);
double match = matcher.IsMatch(bytes).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -56,7 +56,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("");
// Act
double match = matcher.IsMatch(s);
double match = matcher.IsMatch(s).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -70,7 +70,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("");
// Act
double match = matcher.IsMatch(o);
double match = matcher.IsMatch(o).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -83,7 +83,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("xxx");
// Act
double match = matcher.IsMatch("");
double match = matcher.IsMatch("").Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -96,7 +96,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("");
// Act
double match = matcher.IsMatch("x");
double match = matcher.IsMatch("x").Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -109,7 +109,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("$..[?(@.Id == 1)]");
// Act
double match = matcher.IsMatch(new { Id = 1, Name = "Test" });
double match = matcher.IsMatch(new { Id = 1, Name = "Test" }).Score;
// Assert
Check.That(match).IsEqualTo(1);
@@ -122,7 +122,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("$.things[?(@.name == 'x')]");
// Act
double match = matcher.IsMatch(new { things = new { name = "x" } });
double match = matcher.IsMatch(new { things = new { name = "x" } }).Score;
// Assert
Check.That(match).IsEqualTo(1);
@@ -136,7 +136,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("$.things[?(@.name == 'x')]");
// Act
double match = matcher.IsMatch(json);
double match = matcher.IsMatch(json).Score;
// Assert
Check.That(match).IsEqualTo(1);
@@ -150,7 +150,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("$.things[?(@.name == 'x')]");
// Act
double match = matcher.IsMatch(json);
double match = matcher.IsMatch(json).Score;
// Assert
Check.That(match).IsEqualTo(0);
@@ -169,7 +169,7 @@ public class JsonPathMatcherTests
{ "Id", new JValue(1) },
{ "Name", new JValue("Test") }
};
double match = matcher.IsMatch(jobject);
double match = matcher.IsMatch(jobject).Score;
// Assert
Check.That(match).IsEqualTo(1);
@@ -182,7 +182,7 @@ public class JsonPathMatcherTests
var matcher = new JsonPathMatcher("$..[?(@.Id == 1)]");
// Act
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}")).Score;
// Assert
Check.That(match).IsEqualTo(1);
@@ -192,10 +192,10 @@ public class JsonPathMatcherTests
public void JsonPathMatcher_IsMatch_RejectOnMatch()
{
// Arrange
var matcher = new JsonPathMatcher(MatchBehaviour.RejectOnMatch, false, MatchOperator.Or, "$..[?(@.Id == 1)]");
var matcher = new JsonPathMatcher(MatchBehaviour.RejectOnMatch, MatchOperator.Or, "$..[?(@.Id == 1)]");
// Act
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}")).Score;
// Assert
Check.That(match).IsEqualTo(0.0);
@@ -206,7 +206,7 @@ public class JsonPathMatcherTests
{
// Arrange
var matcher = new JsonPathMatcher("$.arr[0].line1");
// Act
double match = matcher.IsMatch(JObject.Parse(@"{
""name"": ""PathSelectorTest"",
@@ -215,18 +215,18 @@ public class JsonPathMatcherTests
""arr"": [{
""line1"": ""line1"",
}]
}"));
}")).Score;
// Assert
Check.That(match).IsEqualTo(1.0);
Check.That(match).IsEqualTo(1.0);
}
[Fact]
public void JsonPathMatcher_IsMatch_ObjectMatch()
{
// Arrange
var matcher = new JsonPathMatcher("$.test");
// Act
double match = matcher.IsMatch(JObject.Parse(@"{
""name"": ""PathSelectorTest"",
@@ -237,10 +237,10 @@ public class JsonPathMatcherTests
""line1"": ""line1"",
}
]
}"));
}")).Score;
// Assert
Check.That(match).IsEqualTo(1.0);
Check.That(match).IsEqualTo(1.0);
}
[Fact]
@@ -248,7 +248,7 @@ public class JsonPathMatcherTests
{
// Arrange
var matcher = new JsonPathMatcher("$.test3");
// Act
double match = matcher.IsMatch(JObject.Parse(@"{
""name"": ""PathSelectorTest"",
@@ -259,10 +259,10 @@ public class JsonPathMatcherTests
""line1"": ""line1"",
}
]
}"));
}")).Score;
// Assert
Check.That(match).IsEqualTo(0.0);
Check.That(match).IsEqualTo(0.0);
}
[Fact]
@@ -270,35 +270,35 @@ public class JsonPathMatcherTests
{
// Arrange
var matcher = new JsonPathMatcher("$arr[0].line1");
// Act
double match = matcher.IsMatch(JObject.Parse(@"{
""name"": ""PathSelectorTest"",
""test"": ""test"",
""test2"": ""test2"",
""arr"": []
}"));
}")).Score;
// Assert
Check.That(match).IsEqualTo(0.0);
Check.That(match).IsEqualTo(0.0);
}
[Fact]
public void JsonPathMatcher_IsMatch_DoesntMatchNoObjectsInArray()
{
// Arrange
var matcher = new JsonPathMatcher("$arr[2].line1");
// Act
double match = matcher.IsMatch(JObject.Parse(@"{
""name"": ""PathSelectorTest"",
""test"": ""test"",
""test2"": ""test2"",
""arr"": []
}"));
}")).Score;
// Assert
Check.That(match).IsEqualTo(0.0);
Check.That(match).IsEqualTo(0.0);
}
[Fact]
@@ -306,7 +306,7 @@ public class JsonPathMatcherTests
{
// Arrange
var matcher = new JsonPathMatcher("$.arr[0].sub[0].subline1");
// Act
double match = matcher.IsMatch(JObject.Parse(@"{
""name"": ""PathSelectorTest"",
@@ -319,9 +319,9 @@ public class JsonPathMatcherTests
""subline1"":""subline1""
}]
}]
}"));
}")).Score;
// Assert
Check.That(match).IsEqualTo(1.0);
Check.That(match).IsEqualTo(1.0);
}
}
}