mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 06:13:35 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71196b51c9 | ||
|
|
d0fc889f42 |
@@ -32,7 +32,7 @@ namespace WireMock.Net.ConsoleApplication
|
||||
|
||||
server.SetBasicAuthentication("a", "b");
|
||||
|
||||
// server.AllowPartialMapping();
|
||||
server.AllowPartialMapping();
|
||||
|
||||
// .WithHeader("Stef", "Stef")
|
||||
//server
|
||||
@@ -40,6 +40,15 @@ namespace WireMock.Net.ConsoleApplication
|
||||
// .RespondWith(Response.Create()
|
||||
// .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
|
||||
.Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
|
||||
.RespondWith(Response.Create()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<Version>1.0.2.9</Version>
|
||||
<Version>1.0.2.11</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -30,12 +30,8 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="key">
|
||||
/// The key.
|
||||
/// </param>
|
||||
/// <param name="values">
|
||||
/// The values.
|
||||
/// </param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="values">The values.</param>
|
||||
public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable<string> values)
|
||||
{
|
||||
Check.NotNull(key, nameof(key));
|
||||
@@ -51,17 +47,11 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
@@ -71,7 +61,9 @@ namespace WireMock.Matchers.Request
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (Funcs != null)
|
||||
{
|
||||
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
|
||||
}
|
||||
|
||||
List<string> values = requestMessage.GetParameter(Key);
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using System.Text;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
@@ -53,6 +54,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public IDictionary<string, WireMockList<string>> Query { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw query.
|
||||
/// </summary>
|
||||
public string RawQuery { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bodyAsBytes.
|
||||
/// </summary>
|
||||
@@ -110,7 +116,7 @@ namespace WireMock
|
||||
Host = url.Host;
|
||||
Port = url.Port;
|
||||
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
|
||||
Path = url.AbsolutePath;
|
||||
Path = WebUtility.UrlDecode(url.AbsolutePath);
|
||||
Method = method.ToLower();
|
||||
ClientIP = clientIP;
|
||||
BodyAsBytes = bodyAsBytes;
|
||||
@@ -118,10 +124,11 @@ namespace WireMock
|
||||
BodyEncoding = bodyEncoding;
|
||||
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
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))
|
||||
{
|
||||
@@ -153,7 +160,7 @@ namespace WireMock
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The get a query parameter.
|
||||
/// Get a query parameter.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns>The query parameter.</returns>
|
||||
|
||||
@@ -363,18 +363,18 @@ namespace WireMock.Server
|
||||
return new RespondWithAProvider(RegisterMapping, requestMatcher);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The register mapping.
|
||||
/// </summary>
|
||||
/// <param name="mapping">
|
||||
/// The mapping.
|
||||
/// </param>
|
||||
private void RegisterMapping(Mapping mapping)
|
||||
{
|
||||
// Check a mapping exists with the same GUID, if so, remove it first.
|
||||
DeleteMapping(mapping.Guid);
|
||||
|
||||
_options.Mappings.Add(mapping);
|
||||
// Check a mapping exists with the same Guid, if so, replace it.
|
||||
var existingMapping = _options.Mappings.FirstOrDefault(m => m.Guid == mapping.Guid);
|
||||
if (existingMapping != null)
|
||||
{
|
||||
_options.Mappings[_options.Mappings.IndexOf(existingMapping)] = mapping;
|
||||
}
|
||||
else
|
||||
{
|
||||
_options.Mappings.Add(mapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.2.9</Version>
|
||||
<Version>1.0.2.11</Version>
|
||||
<Authors>Alexandre Victoor;Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -117,20 +117,24 @@ namespace WireMock.Net.Tests
|
||||
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server.Given(Request.Create().WithPath("/1").UsingGet())
|
||||
var response1 = Response.Create().WithStatusCode(500);
|
||||
_server.Given(Request.Create().UsingGet())
|
||||
.WithGuid(guid)
|
||||
.RespondWith(Response.Create().WithStatusCode(500));
|
||||
.RespondWith(response1);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
Check.That(mappings).HasSize(1);
|
||||
Check.That(mappings.First().Guid).Equals(guid);
|
||||
var mappings1 = _server.Mappings.ToArray();
|
||||
Check.That(mappings1).HasSize(1);
|
||||
Check.That(mappings1.First().Guid).Equals(guid);
|
||||
|
||||
var response2 = Response.Create().WithStatusCode(400);
|
||||
_server.Given(Request.Create().WithPath("/2").UsingGet())
|
||||
.WithGuid(guid)
|
||||
.RespondWith(Response.Create().WithStatusCode(500));
|
||||
.RespondWith(response2);
|
||||
|
||||
Check.That(mappings).HasSize(1);
|
||||
Check.That(mappings.First().Guid).Equals(guid);
|
||||
var mappings2 = _server.Mappings.ToArray();
|
||||
Check.That(mappings2).HasSize(1);
|
||||
Check.That(mappings2.First().Guid).Equals(guid);
|
||||
Check.That(mappings2.First().Provider).Equals(response2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user