Closed JasonLandbridge closed 5 months ago
@JasonLandbridge Sorry, this was indeed a small breaking change introduced in https://github.com/WireMock-Net/WireMock.Net/pull/986 in version 1.5.36 (21 September 2023).
This property was removed, and now you get logging in case the matcher fails.
@StefH Thanks for tracking this down! I actually loved this option as it would make my tests fail if an URL changed or a new URL was called by my code not yet covered by my tests. But now, I assume, the tests can still pass due to the lack of a thrown exception if this happens.
Any chance this option can be returned or is there something similar available?
Cheers!
The functionality is like:
When creating a matcher using the constructor, and the pattern is invalid, an exception is thrown immediately. Like:
[Fact]
public void JsonMatcher_WithInvalidStringValue_Should_ThrowException()
{
// Act
// ReSharper disable once ObjectCreationAsStatement
Action action = () => new JsonMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
// Assert
action.Should().Throw<JsonException>();
}
// or this
[Fact]
public void GraphQLMatcher_For_InvalidSchema_ThrowsGraphQLSyntaxErrorException()
{
// Act
// ReSharper disable once ObjectCreationAsStatement
Action action = () => _ = new GraphQLMatcher("in va lid");
// Assert
action.Should().Throw<GraphQLSyntaxErrorException>();
}
When the input value for the matcher to match on, is invalid, the exception is remembered and returned in the result. Like:
[Fact]
public void GraphQLMatcher_For_ValidSchema_And_IncorrectQueryWithError_WithThrowExceptionTrue_ReturnsError()
{
// Arrange
var input = "{\"query\":\"{\\r\\n studentsX {\\r\\n fullName\\r\\n X\\r\\n }\\r\\n}\"}";
// Act
var matcher = new GraphQLMatcher(TestSchema);
var result = matcher.IsMatch(input);
// Assert
result.Score.Should().Be(MatchScores.Mismatch);
result.Exception!.Message.Should().StartWith("Cannot query field 'studentsX' on type 'Query'");
}
In the high level mapping matcher code, this error/exception is logged and this mapping is skipped because it contains errors.
Does this help you, you did you actually use it in a different way ? Because I do not understand this:
it would make my tests fail if an URL changed or a new URL was called by my code not yet covered by my tests
Thank you very much for this answer! I will try it out when I have the chance. I will close this for now
Hi there,
I just upgraded to .NET 8 and upgraded Wiremock from 1.5.16 to 1.5.51, but the
ThrowExceptionWhenMatcherFails
option seems to not be there anymore?Searching the repo for any mention of
ThrowExceptionWhenMatcherFails
seems it has disappeared.Did I miss a breaking change or migration?
Thanks!