mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-15 06:43:37 +01:00
Fixed #106
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
# 1.0.3.8 (10 March 2018)
|
||||
|
||||
- [#106](https://github.com/WireMock-Net/WireMock.Net/issues/106) - Issue: Params does not work, when there are multiple values for a key
|
||||
|
||||
Commits: f604be3c02...f604be3c02
|
||||
|
||||
|
||||
# 1.0.3.7 (09 March 2018)
|
||||
|
||||
- [#104](https://github.com/WireMock-Net/WireMock.Net/issues/104) - Issue: PlatformNotSupportedException
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
https://github.com/GitTools/GitReleaseNotes
|
||||
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3.7
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3.8
|
||||
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<Version>1.0.3.7</Version>
|
||||
<Version>1.0.3.8</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -65,9 +65,15 @@ namespace WireMock.Matchers.Request
|
||||
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
|
||||
}
|
||||
|
||||
List<string> values = requestMessage.GetParameter(Key);
|
||||
var values = requestMessage.GetParameter(Key);
|
||||
if (values == null && !Values.Any())
|
||||
{
|
||||
// Key is present, but no values, just return match
|
||||
return MatchScores.Perfect;
|
||||
}
|
||||
|
||||
return MatchScores.ToScore(values?.Intersect(Values).Count() == Values.Count());
|
||||
var matches = Values.Select(v => values != null && values.Contains(v));
|
||||
return MatchScores.ToScore(matches);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,10 +180,11 @@ namespace WireMock
|
||||
queryString = queryString.Substring(1);
|
||||
}
|
||||
|
||||
return queryString.Split('&').Aggregate(new Dictionary<string, WireMockList<string>>(),
|
||||
return queryString.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Aggregate(new Dictionary<string, WireMockList<string>>(),
|
||||
(dict, term) =>
|
||||
{
|
||||
var parts = term.Split('=');
|
||||
string[] parts = term.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string key = parts[0];
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
@@ -192,7 +193,8 @@ namespace WireMock
|
||||
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
dict[key].Add(parts[1]);
|
||||
string[] values = parts[1].Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
dict[key].AddRange(values);
|
||||
}
|
||||
|
||||
return dict;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
||||
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
||||
<Version>1.0.3.7</Version>
|
||||
<Version>1.0.3.8</Version>
|
||||
<Authors>Alexandre Victoor;Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers
|
||||
{
|
||||
public class RequestMessageParamMatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_AllMatch()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_PartialMatch()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresent()
|
||||
{
|
||||
// Assign
|
||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
||||
var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using NFluent;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
//[TestFixture]
|
||||
public class RequestMessageTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Should_handle_empty_query()
|
||||
public void RequestMessage_ParseQuery_NoKeys()
|
||||
{
|
||||
// given
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp);
|
||||
@@ -21,17 +19,36 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_parse_query_params()
|
||||
public void RequestMessage_ParseQuery_SingleKey_SingleValue()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "whatever";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost?foo=bar&multi=1&multi=2"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost?foo=bar"), "POST", ClientIp);
|
||||
|
||||
// then
|
||||
Check.That(request.GetParameter("foo")).Contains("bar");
|
||||
Check.That(request.GetParameter("multi")).Contains("1");
|
||||
Check.That(request.GetParameter("multi")).Contains("2");
|
||||
// Assert
|
||||
Check.That(request.GetParameter("foo")).ContainsExactly("bar");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_ParseQuery_MultipleKeys_MultipleValues()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost?key=1&key=2"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("key")).Contains("1");
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_ParseQuery_SingleKey_MultipleValues()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost?key=1,2&foo=bar&key=3"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.GetParameter("key")).Contains("1");
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
Check.That(request.GetParameter("key")).Contains("3");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,20 +123,6 @@ namespace WireMock.Net.Tests
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_paramNoValue()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithParam("bar");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo?bar"), "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_func()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user