Fix for url encoded path + params (1.0.2.10) - #72

Fix for url encoded path + params (1.0.2.10)
This commit is contained in:
Stef Heyenrath
2017-12-12 18:18:04 +01:00
parent fd5bc203c3
commit d0fc889f42
5 changed files with 30 additions and 22 deletions

View File

@@ -32,7 +32,7 @@ namespace WireMock.Net.ConsoleApplication
server.SetBasicAuthentication("a", "b"); server.SetBasicAuthentication("a", "b");
// server.AllowPartialMapping(); server.AllowPartialMapping();
// .WithHeader("Stef", "Stef") // .WithHeader("Stef", "Stef")
//server //server
@@ -40,6 +40,15 @@ namespace WireMock.Net.ConsoleApplication
// .RespondWith(Response.Create() // .RespondWith(Response.Create()
// .WithProxy("http://restcountries.eu")); // .WithProxy("http://restcountries.eu"));
server
.Given(Request
.Create()
.WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))
.WithParam("$filter", "(substringof(Code, 'WA')")
.UsingGet())
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""odata""}"));
server server
.Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*")) .Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
.RespondWith(Response.Create() .RespondWith(Response.Create()

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description> <Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle> <AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
<Version>1.0.2.9</Version> <Version>1.0.2.10</Version>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -30,12 +30,8 @@ namespace WireMock.Matchers.Request
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class. /// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary> /// </summary>
/// <param name="key"> /// <param name="key">The key.</param>
/// The key. /// <param name="values">The values.</param>
/// </param>
/// <param name="values">
/// The values.
/// </param>
public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable<string> values) public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable<string> values)
{ {
Check.NotNull(key, nameof(key)); Check.NotNull(key, nameof(key));
@@ -51,17 +47,11 @@ namespace WireMock.Matchers.Request
public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs) public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
{ {
Check.NotNull(funcs, nameof(funcs)); Check.NotNull(funcs, nameof(funcs));
Funcs = funcs; Funcs = funcs;
} }
/// <summary> /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">The RequestMessage.</param>
/// <param name="requestMatchResult">The RequestMatchResult.</param>
/// <returns>
/// A value between 0.0 - 1.0 of the similarity.
/// </returns>
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
{ {
double score = IsMatch(requestMessage); double score = IsMatch(requestMessage);
@@ -71,7 +61,9 @@ namespace WireMock.Matchers.Request
private double IsMatch(RequestMessage requestMessage) private double IsMatch(RequestMessage requestMessage)
{ {
if (Funcs != null) if (Funcs != null)
{
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query))); return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
}
List<string> values = requestMessage.GetParameter(Key); List<string> values = requestMessage.GetParameter(Key);

View File

@@ -1,10 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Net;
using JetBrains.Annotations; using JetBrains.Annotations;
using WireMock.Util; using WireMock.Util;
using WireMock.Validation; using WireMock.Validation;
using System.Text;
namespace WireMock namespace WireMock
{ {
@@ -53,6 +54,11 @@ namespace WireMock
/// </summary> /// </summary>
public IDictionary<string, WireMockList<string>> Query { get; } public IDictionary<string, WireMockList<string>> Query { get; }
/// <summary>
/// Gets the raw query.
/// </summary>
public string RawQuery { get; }
/// <summary> /// <summary>
/// Gets the bodyAsBytes. /// Gets the bodyAsBytes.
/// </summary> /// </summary>
@@ -110,7 +116,7 @@ namespace WireMock
Host = url.Host; Host = url.Host;
Port = url.Port; Port = url.Port;
Origin = $"{url.Scheme}://{url.Host}:{url.Port}"; Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
Path = url.AbsolutePath; Path = WebUtility.UrlDecode(url.AbsolutePath);
Method = method.ToLower(); Method = method.ToLower();
ClientIP = clientIP; ClientIP = clientIP;
BodyAsBytes = bodyAsBytes; BodyAsBytes = bodyAsBytes;
@@ -118,10 +124,11 @@ namespace WireMock
BodyEncoding = bodyEncoding; BodyEncoding = bodyEncoding;
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value)); Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
Cookies = cookies; Cookies = cookies;
Query = ParseQuery(url.Query); RawQuery = WebUtility.UrlDecode(url.Query);
Query = ParseQuery(RawQuery);
} }
private IDictionary<string, WireMockList<string>> ParseQuery(string queryString) private static IDictionary<string, WireMockList<string>> ParseQuery(string queryString)
{ {
if (string.IsNullOrEmpty(queryString)) if (string.IsNullOrEmpty(queryString))
{ {
@@ -153,7 +160,7 @@ namespace WireMock
} }
/// <summary> /// <summary>
/// The get a query parameter. /// Get a query parameter.
/// </summary> /// </summary>
/// <param name="key">The key.</param> /// <param name="key">The key.</param>
/// <returns>The query parameter.</returns> /// <returns>The query parameter.</returns>

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description> <Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
<AssemblyTitle>WireMock.Net</AssemblyTitle> <AssemblyTitle>WireMock.Net</AssemblyTitle>
<Version>1.0.2.9</Version> <Version>1.0.2.10</Version>
<Authors>Alexandre Victoor;Stef Heyenrath</Authors> <Authors>Alexandre Victoor;Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>