mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-25 02:41:53 +01:00
Add Settings.QueryParameterMultipleValueSupport (#836)
* QueryParameterMultipleValueSupport * . * , * ,
This commit is contained in:
@@ -1,243 +1,261 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Models;
|
||||
using WireMock.Owin;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
namespace WireMock.Net.Tests;
|
||||
|
||||
public class RequestTests
|
||||
{
|
||||
public class RequestTests
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/bar").UsingPut();
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_headers()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tatata");
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/bar").UsingPut();
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "abc", false);
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_headers()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tatata");
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "ABC" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_header_prefix()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tata*");
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "abc", false);
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "ABC" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_wildcard_header()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*");
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_header_prefix()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tata*");
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_not_matching_given_wildcard_header2()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*");
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_wildcard_header()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*");
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-tata", new[] { "ToTo" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_wildcard_header_rejectonmatch()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*", WireMock.Matchers.MatchBehaviour.RejectOnMatch);
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_not_matching_given_wildcard_header2()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*");
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-tata", new[] { "ToTo" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-tata", new[] { "ToTo" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_not_matching_given_wildcard_header_rejectonmatch()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*", WireMock.Matchers.MatchBehaviour.RejectOnMatch);
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_wildcard_header_rejectonmatch()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*", WireMock.Matchers.MatchBehaviour.RejectOnMatch);
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-tata", new[] { "ToTo" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithBody("Hello world!");
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_not_matching_given_wildcard_header_rejectonmatch()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "*", WireMock.Matchers.MatchBehaviour.RejectOnMatch);
|
||||
BodyAsString = "Hello world!",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "whatever",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_body()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithBody(" Hello world! ");
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body()
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithBody("Hello world!");
|
||||
BodyAsString = "xxx",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "Hello world!",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_param()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithParam("bar", "1", "2");
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_body()
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_param_WithComma()
|
||||
{
|
||||
// given
|
||||
var options = new WireMockMiddlewareOptions
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithBody(" Hello world! ");
|
||||
QueryParameterMultipleValueSupport = QueryParameterMultipleValueSupport.NoComma
|
||||
};
|
||||
var spec = Request.Create().WithParam("$filter", "startswith(name,'testName')");
|
||||
|
||||
// when
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "xxx",
|
||||
DetectedBodyType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
// when
|
||||
var request = new RequestMessage(options, new UrlDetails("http://localhost/?$filter=startswith(name,'testName')"), "PUT", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_param()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithParam("bar", "1", "2");
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_param_func()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithParam(p => p.ContainsKey("bar"));
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_param_func()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyMethod().WithParam(p => p.ContainsKey("bar"));
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_params()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithParam("bar", "1");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/test=7"), "PUT", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_params()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithParam("bar", "1");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/test=7"), "PUT", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
}
|
||||
@@ -1,267 +1,308 @@
|
||||
using FluentAssertions;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class QueryStringParserTests
|
||||
{
|
||||
public class QueryStringParserTests
|
||||
[Fact]
|
||||
public void Parse_WithNullString()
|
||||
{
|
||||
[Fact]
|
||||
public void Parse_WithNullString()
|
||||
{
|
||||
// Assign
|
||||
string query = null;
|
||||
// Assign
|
||||
string? query = null;
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Should().Equal(new Dictionary<string, WireMockList<string>>());
|
||||
}
|
||||
// Assert
|
||||
result.Should().Equal(new Dictionary<string, WireMockList<string>>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithEmptyString()
|
||||
{
|
||||
// Assign
|
||||
string query = "";
|
||||
[Fact]
|
||||
public void Parse_WithEmptyString()
|
||||
{
|
||||
// Assign
|
||||
string query = "";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Should().Equal(new Dictionary<string, WireMockList<string>>());
|
||||
}
|
||||
// Assert
|
||||
result.Should().Equal(new Dictionary<string, WireMockList<string>>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithQuestionMark()
|
||||
{
|
||||
// Assign
|
||||
string query = "?";
|
||||
[Fact]
|
||||
public void Parse_WithQuestionMark()
|
||||
{
|
||||
// Assign
|
||||
string query = "?";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Should().Equal(new Dictionary<string, WireMockList<string>>());
|
||||
}
|
||||
// Assert
|
||||
result.Should().Equal(new Dictionary<string, WireMockList<string>>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1Param()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=bla/blub.xml";
|
||||
[Fact]
|
||||
public void Parse_With1Param()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=bla/blub.xml";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("bla/blub.xml"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("bla/blub.xml"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With2Params()
|
||||
{
|
||||
// Assign
|
||||
string query = "?x=1&y=2";
|
||||
[Fact]
|
||||
public void Parse_With2Params()
|
||||
{
|
||||
// Assign
|
||||
string query = "?x=1&y=2";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(2);
|
||||
result["x"].Should().Equal(new WireMockList<string>("1"));
|
||||
result["y"].Should().Equal(new WireMockList<string>("2"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(2);
|
||||
result["x"].Should().Equal(new WireMockList<string>("1"));
|
||||
result["y"].Should().Equal(new WireMockList<string>("2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamNoValue()
|
||||
{
|
||||
// Assign
|
||||
string query = "?empty";
|
||||
[Fact]
|
||||
public void Parse_With1ParamNoValue()
|
||||
{
|
||||
// Assign
|
||||
string query = "?empty";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["empty"].Should().Equal(new WireMockList<string>());
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["empty"].Should().Equal(new WireMockList<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamNoValueWithEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?empty=";
|
||||
[Fact]
|
||||
public void Parse_With1ParamNoValueWithEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?empty=";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["empty"].Should().Equal(new WireMockList<string>());
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["empty"].Should().Equal(new WireMockList<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamAndJustAndSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=1&";
|
||||
[Fact]
|
||||
public void Parse_With1ParamAndJustAndSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=1&";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("1"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With2ParamsAndWhereOneHasAQuestion()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value?&b=c";
|
||||
[Fact]
|
||||
public void Parse_With2ParamsAndWhereOneHasAQuestion()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value?&b=c";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(2);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value?"));
|
||||
result["b"].Should().Equal(new WireMockList<string>("c"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(2);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value?"));
|
||||
result["b"].Should().Equal(new WireMockList<string>("c"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamWithEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value=what";
|
||||
[Fact]
|
||||
public void Parse_With1ParamWithEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value=what";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value=what"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value=what"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamWithTwoEqualSigns()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value==what";
|
||||
[Fact]
|
||||
public void Parse_With1ParamWithTwoEqualSigns()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value==what";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value==what"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value==what"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithMultipleParamWithSameKeySeparatedBySemiColon()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value;key=anotherValue";
|
||||
[Fact]
|
||||
public void Parse_WithMultipleParamWithSameKeySeparatedBySemiColon()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value;key=anotherValue";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>(new[] { "value", "anotherValue" }));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value", "anotherValue"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingComma()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=1,2&key=3";
|
||||
[Fact]
|
||||
public void Parse_WithMultipleParamWithSameKeySeparatedByAmp()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=1&key=2";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>(new[] { "1", "2", "3" }));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("1", "2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingEscapedAnd()
|
||||
{
|
||||
// Assign
|
||||
string query = "?winkel=C%26A";
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingComma_When_SupportMultiValueUsingComma_Is_True()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=1,2,3";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["winkel"].Should().Equal(new WireMockList<string>(new[] { "C&A" }));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("1", "2", "3"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingParentheses()
|
||||
{
|
||||
// Assign
|
||||
string query = "?Transaction=(123)";
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingCommaAndAmpCombined_When_SupportMultiValueUsingComma_Is_Comma()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=1,2&key=3";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["Transaction"].Should().Equal(new WireMockList<string>(new[] { "(123)" }));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("1", "2", "3"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithMultipleParamWithSameKey()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value&key=anotherValue";
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingComma_SupportMultiValueUsingComma_Is_AmpersandAndSemiColon()
|
||||
{
|
||||
// Assign
|
||||
string query = "?$filter=startswith(name,'testName')";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query, QueryParameterMultipleValueSupport.AmpersandAndSemiColon);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>(new[] { "value", "anotherValue" }));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["$filter"].Should().Equal(new WireMockList<string>("startswith(name,'testName')"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingSpacesAndEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?q=SELECT Id from User where username='user@gmail.com'";
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingEscapedAnd()
|
||||
{
|
||||
// Assign
|
||||
string query = "?winkel=C%26A";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["q"].Should().Equal(new WireMockList<string>("SELECT Id from User where username='user@gmail.com'"));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["winkel"].Should().Equal(new WireMockList<string>("C&A"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithComplex()
|
||||
{
|
||||
// Assign
|
||||
string query = "?q=energy+edge&rls=com.microsoft:en-au&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1%22";
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingParentheses()
|
||||
{
|
||||
// Assign
|
||||
string query = "?Transaction=(123)";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(6);
|
||||
result["q"].Should().Equal(new WireMockList<string>("energy edge"));
|
||||
result["rls"].Should().Equal(new WireMockList<string>("com.microsoft:en-au"));
|
||||
result["ie"].Should().Equal(new WireMockList<string>("UTF-8"));
|
||||
result["oe"].Should().Equal(new WireMockList<string>("UTF-8"));
|
||||
result["startIndex"].Should().Equal(new WireMockList<string>());
|
||||
result["startPage"].Should().Equal(new WireMockList<string>("1\""));
|
||||
}
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["Transaction"].Should().Equal(new WireMockList<string>("(123)"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithMultipleParamWithSameKey()
|
||||
{
|
||||
// Assign
|
||||
string query = "?key=value&key=anotherValue";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["key"].Should().Equal(new WireMockList<string>("value", "anotherValue"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_With1ParamContainingSpacesAndEqualSign()
|
||||
{
|
||||
// Assign
|
||||
string query = "?q=SELECT Id from User where username='user@gmail.com'";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(1);
|
||||
result["q"].Should().Equal(new WireMockList<string>("SELECT Id from User where username='user@gmail.com'"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WithComplex()
|
||||
{
|
||||
// Assign
|
||||
string query = "?q=energy+edge&rls=com.microsoft:en-au&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1%22";
|
||||
|
||||
// Act
|
||||
var result = QueryStringParser.Parse(query);
|
||||
|
||||
// Assert
|
||||
result.Count.Should().Be(6);
|
||||
result["q"].Should().Equal(new WireMockList<string>("energy edge"));
|
||||
result["rls"].Should().Equal(new WireMockList<string>("com.microsoft:en-au"));
|
||||
result["ie"].Should().Equal(new WireMockList<string>("UTF-8"));
|
||||
result["oe"].Should().Equal(new WireMockList<string>("UTF-8"));
|
||||
result["startIndex"].Should().Equal(new WireMockList<string>());
|
||||
result["startPage"].Should().Equal(new WireMockList<string>("1\""));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user