diff --git a/src/WireMock.Net/Matchers/JsonMatcher.cs b/src/WireMock.Net/Matchers/JsonMatcher.cs
index 29602318..6ff6bfce 100644
--- a/src/WireMock.Net/Matchers/JsonMatcher.cs
+++ b/src/WireMock.Net/Matchers/JsonMatcher.cs
@@ -53,7 +53,7 @@ public class JsonMatcher : IValueMatcher, IIgnoreCaseMatcher
/// Ignore the case from the PropertyName and PropertyValue (string only).
public JsonMatcher(MatchBehaviour matchBehaviour, object value, bool ignoreCase = false)
{
- Guard.NotNull(value, nameof(value));
+ Guard.NotNull(value);
MatchBehaviour = matchBehaviour;
IgnoreCase = ignoreCase;
diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
index 97070352..fcd9749c 100644
--- a/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
+++ b/src/WireMock.Net/Matchers/Request/RequestMessageParamMatcher.cs
@@ -85,11 +85,11 @@ public class RequestMessageParamMatcher : IRequestMatcher
///
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
{
- var (score, exception) = GetMatchResult(requestMessage).Expand();
- return requestMatchResult.AddScore(GetType(), score, exception);
+ var score = GetMatchScore(requestMessage);
+ return requestMatchResult.AddScore(GetType(), MatchBehaviourHelper.Convert(MatchBehaviour, score), null);
}
- private MatchResult GetMatchResult(IRequestMessage requestMessage)
+ private double GetMatchScore(IRequestMessage requestMessage)
{
if (Funcs != null)
{
@@ -100,7 +100,7 @@ public class RequestMessageParamMatcher : IRequestMatcher
if (valuesPresentInRequestMessage == null)
{
// Key is not present at all, just return Mismatch
- return default;
+ return MatchScores.Mismatch;
}
if (Matchers != null && Matchers.Any())
@@ -115,10 +115,10 @@ public class RequestMessageParamMatcher : IRequestMatcher
return MatchScores.Perfect;
}
- return default;
+ return MatchScores.Mismatch;
}
- private static MatchResult CalculateScore(IReadOnlyList matchers, WireMockList valuesPresentInRequestMessage)
+ private static double CalculateScore(IReadOnlyList matchers, WireMockList valuesPresentInRequestMessage)
{
var total = new List();
diff --git a/test/WireMock.Net.Tests/WireMockServerTests.WithParam.cs b/test/WireMock.Net.Tests/WireMockServerTests.WithParam.cs
index 8f70eb65..7cb809c8 100644
--- a/test/WireMock.Net.Tests/WireMockServerTests.WithParam.cs
+++ b/test/WireMock.Net.Tests/WireMockServerTests.WithParam.cs
@@ -2,6 +2,7 @@ using System;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
+using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
@@ -26,10 +27,10 @@ public partial class WireMockServerTests
};
var server = WireMockServer.Start(settings);
server.Given(
- Request.Create()
- .UsingGet()
- .WithPath("/foo")
- .WithParam("query", queryValue)
+ Request.Create()
+ .UsingGet()
+ .WithPath("/foo")
+ .WithParam("query", queryValue)
)
.RespondWith(
Response.Create().WithStatusCode(200)
@@ -52,10 +53,10 @@ public partial class WireMockServerTests
var queryValue = "1,2,3";
var server = WireMockServer.Start();
server.Given(
- Request.Create()
- .UsingGet()
- .WithPath("/foo")
- .WithParam("query", "1", "2", "3")
+ Request.Create()
+ .UsingGet()
+ .WithPath("/foo")
+ .WithParam("query", "1", "2", "3")
)
.RespondWith(
Response.Create().WithStatusCode(200)
@@ -70,4 +71,54 @@ public partial class WireMockServerTests
server.Stop();
}
+
+ [Fact]
+ public async Task WireMockServer_WithParam_RejectOnMatch_OnNonMatchingParam_ShouldReturnMappingOk()
+ {
+ // Arrange
+ var server = WireMockServer.Start();
+ server.Given(
+ Request.Create()
+ .WithPath("/v1/person/workers")
+ .WithParam("delta_from", MatchBehaviour.RejectOnMatch)
+ .UsingGet()
+ )
+ .RespondWith(
+ Response.Create()
+ );
+
+ // Act
+ var requestUri = new Uri($"http://localhost:{server.Port}/v1/person/workers?showsourcesystem=true&count=700&page=1§ions=personal%2Corganizations%2Cemployment");
+ var response = await server.CreateClient().GetAsync(requestUri).ConfigureAwait(false);
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.OK);
+
+ server.Stop();
+ }
+
+ [Fact]
+ public async Task WireMockServer_WithParam_AcceptOnMatch_OnNonMatchingParam_ShouldReturnMappingOk()
+ {
+ // Arrange
+ var server = WireMockServer.Start();
+ server.Given(
+ Request.Create()
+ .WithPath("/v1/person/workers")
+ .WithParam("delta_from")
+ .UsingGet()
+ )
+ .RespondWith(
+ Response.Create()
+ );
+
+ // Act
+ var requestUri = new Uri($"http://localhost:{server.Port}/v1/person/workers?showsourcesystem=true&count=700&page=1§ions=personal%2Corganizations%2Cemployment");
+ var response = await server.CreateClient().GetAsync(requestUri).ConfigureAwait(false);
+
+ // Assert
+ response.StatusCode.Should().Be(HttpStatusCode.NotFound);
+
+ server.Stop();
+ }
}
\ No newline at end of file