From fd304fe502566a2d3c84325578e385efc3dbc3ee Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Wed, 17 Jul 2024 15:36:57 +0200 Subject: [PATCH] . --- .../Matchers/Helpers/BodyDataMatchScoreCalculator.cs | 10 +++------- .../Matchers/Request/RequestMessageGraphQLMatcher.cs | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/WireMock.Net/Matchers/Helpers/BodyDataMatchScoreCalculator.cs b/src/WireMock.Net/Matchers/Helpers/BodyDataMatchScoreCalculator.cs index e97ad0be..bd660cf6 100644 --- a/src/WireMock.Net/Matchers/Helpers/BodyDataMatchScoreCalculator.cs +++ b/src/WireMock.Net/Matchers/Helpers/BodyDataMatchScoreCalculator.cs @@ -60,14 +60,10 @@ public static MatchResult CalculateMatchScore(IBodyData? requestMessage, IMatche } } - // Check if the matcher is a IStringMatcher - if (matcher is IStringMatcher stringMatcher) + // In case the matcher is a IStringMatcher and If body is a Json or a String, use the BodyAsString to match on. + if (matcher is IStringMatcher stringMatcher && requestMessage.DetectedBodyType is BodyType.Json or BodyType.String or BodyType.FormUrlEncoded) { - // If the body is a Json or a String, use the BodyAsString to match on. - if (requestMessage.DetectedBodyType is BodyType.Json or BodyType.String or BodyType.FormUrlEncoded) - { - return stringMatcher.IsMatch(requestMessage.BodyAsString); - } + return stringMatcher.IsMatch(requestMessage.BodyAsString); } return default; diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs index a2949059..6351909a 100644 --- a/src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs +++ b/src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs @@ -78,8 +78,7 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu private static MatchResult CalculateMatchResult(IRequestMessage requestMessage, IMatcher matcher) { - // Check if the matcher is a IStringMatcher - // If the body is a Json or a String, use the BodyAsString to match on. + // In case the matcher is a IStringMatcher and the body is a Json or a String, use the BodyAsString to match on. if (matcher is IStringMatcher stringMatcher && requestMessage.BodyData?.DetectedBodyType is BodyType.Json or BodyType.String or BodyType.FormUrlEncoded) { return stringMatcher.IsMatch(requestMessage.BodyData.BodyAsString);