Add more QueryParameterMultipleValueSupport NoComma tests

This commit is contained in:
Stef Heyenrath
2022-11-30 07:36:13 +00:00
parent ef5f988786
commit 1562958172
3 changed files with 41 additions and 2 deletions

View File

@@ -104,7 +104,7 @@ public class RequestMessageBodyMatcher : IRequestMatcher
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="func">The function.</param>
public RequestMessageBodyMatcher(Func<IBodyData, bool> func)
public RequestMessageBodyMatcher(Func<IBodyData?, bool> func)
{
BodyDataFunc = Guard.NotNull(func);
}

View File

@@ -1,7 +1,9 @@
using FluentAssertions;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Owin;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -172,5 +174,25 @@ namespace WireMock.Net.Tests.RequestMatchers
// Assert
Check.That(score).IsEqualTo(1.0d);
}
// Issue #849
[Fact]
public void RequestMessageParamMatcher_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
{
// Assign
var options = new WireMockMiddlewareOptions
{
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
};
var requestMessage = new RequestMessage(options, new UrlDetails("http://localhostquery=SELECT id, value FROM table WHERE id = 1&test=42"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "query", false, "SELECT id, value FROM table WHERE id = 1");
// Act
var result = new RequestMatchResult();
double score = matcher.GetMatchingScore(requestMessage, result);
// Assert
score.Should().Be(1.0);
}
}
}

View File

@@ -274,7 +274,7 @@ public class QueryStringParserTests
}
[Fact]
public void Parse_With1ParamContainingSpacesAndEqualSign()
public void Parse_With1ParamContainingSpacesSingleQuoteAndEqualSign()
{
// Assign
string query = "?q=SELECT Id from User where username='user@gmail.com'";
@@ -287,6 +287,23 @@ public class QueryStringParserTests
result["q"].Should().Equal(new WireMockList<string>("SELECT Id from User where username='user@gmail.com'"));
}
// Issue #849
[Fact]
public void Parse_With1ParamContainingComma_Using_QueryParameterMultipleValueSupport_NoComma()
{
// Assign
string query = "?query=SELECT id, value FROM table WHERE id = 1&test=42";
// Act
var result = QueryStringParser.Parse(query, QueryParameterMultipleValueSupport.NoComma);
// Assert
result.Count.Should().Be(2);
result["query"].Should().Equal(new WireMockList<string>("SELECT id, value FROM table WHERE id = 1"));
result["test"].Should().Equal(new WireMockList<string>("42"));
}
[Fact]
public void Parse_WithComplex()
{