mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-19 07:30:11 +02:00
Stef negate matcher (#134)
* RejectOnMatch (wip) * RejectOnMatch (wip) * RejectOnMatch (wip) * RejectOnMatch (wip) * docs: improve sample app matcher to show use of reject on match * Reworked code review comments
This commit is contained in:
committed by
Stef Heyenrath
parent
7cf283ec13
commit
a8ddd31c9c
@@ -1,5 +1,5 @@
|
|||||||
https://github.com/GitTools/GitReleaseNotes
|
https://github.com/GitTools/GitReleaseNotes
|
||||||
|
|
||||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3.16
|
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3.17
|
||||||
|
|
||||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags
|
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
@@ -150,6 +151,28 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""data deleted with 200""}"));
|
.WithBody(@"{ ""result"": ""data deleted with 200""}"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.WithPath("/needs-a-key")
|
||||||
|
.UsingGet()
|
||||||
|
.WithHeader("api-key", "*", MatchBehaviour.AcceptOnMatch)
|
||||||
|
.UsingAnyMethod())
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithStatusCode(HttpStatusCode.OK)
|
||||||
|
.WithBody(@"{ ""result"": ""api-key found""}"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.WithPath("/needs-a-key")
|
||||||
|
.UsingGet()
|
||||||
|
.WithHeader("api-key", "*", MatchBehaviour.RejectOnMatch)
|
||||||
|
.UsingAnyMethod())
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithStatusCode(HttpStatusCode.Unauthorized)
|
||||||
|
.WithBody(@"{ ""result"": ""api-key missing""}"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
||||||
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
|
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
|
||||||
|
|||||||
@@ -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.3.16</Version>
|
<Version>1.0.3.17</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>
|
||||||
|
|||||||
@@ -24,5 +24,10 @@
|
|||||||
/// Gets or sets the ignore case.
|
/// Gets or sets the ignore case.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? IgnoreCase { get; set; }
|
public bool? IgnoreCase { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reject on match.
|
||||||
|
/// </summary>
|
||||||
|
public bool? RejectOnMatch { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,21 +12,34 @@ namespace WireMock.Matchers
|
|||||||
{
|
{
|
||||||
private readonly string[] _values;
|
private readonly string[] _values;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public ExactMatcher([NotNull] params string[] values)
|
public ExactMatcher([NotNull] params string[] values) : this(MatchBehaviour.AcceptOnMatch, values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="values">The values.</param>
|
||||||
|
public ExactMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] values)
|
||||||
{
|
{
|
||||||
Check.HasNoNulls(values, nameof(values));
|
Check.HasNoNulls(values, nameof(values));
|
||||||
|
|
||||||
_values = values;
|
_values = values;
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||||
public double IsMatch(string input)
|
public double IsMatch(string input)
|
||||||
{
|
{
|
||||||
return MatchScores.ToScore(_values.Select(value => value.Equals(input)));
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_values.Select(value => value.Equals(input))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
||||||
@@ -35,10 +48,7 @@ namespace WireMock.Matchers
|
|||||||
return _values;
|
return _values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public string GetName()
|
public string Name => "ExactMatcher";
|
||||||
{
|
|
||||||
return "ExactMatcher";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using WireMock.Validation;
|
||||||
|
|
||||||
namespace WireMock.Matchers
|
namespace WireMock.Matchers
|
||||||
{
|
{
|
||||||
@@ -12,35 +13,59 @@ namespace WireMock.Matchers
|
|||||||
private readonly object _object;
|
private readonly object _object;
|
||||||
private readonly byte[] _bytes;
|
private readonly byte[] _bytes;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public ExactObjectMatcher([NotNull] object value)
|
public ExactObjectMatcher([NotNull] object value) : this(MatchBehaviour.AcceptOnMatch, value)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] object value)
|
||||||
|
{
|
||||||
|
Check.NotNull(value, nameof(value));
|
||||||
|
|
||||||
_object = value;
|
_object = value;
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public ExactObjectMatcher([NotNull] byte[] value)
|
public ExactObjectMatcher([NotNull] byte[] value) : this(MatchBehaviour.AcceptOnMatch, value)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value)
|
||||||
|
{
|
||||||
|
Check.NotNull(value, nameof(value));
|
||||||
|
|
||||||
_bytes = value;
|
_bytes = value;
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
||||||
public double IsMatch(object input)
|
public double IsMatch(object input)
|
||||||
{
|
{
|
||||||
bool equals = _object != null ? Equals(_object, input) : _bytes.SequenceEqual((byte[])input);
|
bool equals = _object != null ? Equals(_object, input) : _bytes.SequenceEqual((byte[])input);
|
||||||
return MatchScores.ToScore(equals);
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(equals));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public string GetName()
|
public string Name => "ExactObjectMatcher";
|
||||||
{
|
|
||||||
return "ExactObjectMatcher";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,11 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// IIgnoreCaseMatcher
|
/// IIgnoreCaseMatcher
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <inheritdoc cref="IMatcher"/>
|
||||||
public interface IIgnoreCaseMatcher : IMatcher
|
public interface IIgnoreCaseMatcher : IMatcher
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ignore the case.
|
/// Ignore the case from the pattern.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool IgnoreCase { get; }
|
bool IgnoreCase { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,12 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name.
|
/// Gets the name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Name</returns>
|
string Name { get; }
|
||||||
string GetName();
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the match behaviour.
|
||||||
|
/// </summary>
|
||||||
|
MatchBehaviour MatchBehaviour { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// IStringMatcher
|
/// IStringMatcher
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <inheritdoc cref="IMatcher"/>
|
||||||
public interface IStringMatcher : IMatcher
|
public interface IStringMatcher : IMatcher
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
@@ -14,54 +14,69 @@ namespace WireMock.Matchers
|
|||||||
{
|
{
|
||||||
private readonly string[] _patterns;
|
private readonly string[] _patterns;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public JsonPathMatcher([NotNull] params string[] patterns)
|
public JsonPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
public JsonPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||||
public double IsMatch(string input)
|
public double IsMatch(string input)
|
||||||
{
|
{
|
||||||
if (input == null)
|
double match = MatchScores.Mismatch;
|
||||||
|
if (input != null)
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
try
|
||||||
|
{
|
||||||
|
var jtoken = JToken.Parse(input);
|
||||||
|
match = IsMatch(jtoken);
|
||||||
|
}
|
||||||
|
catch (JsonException)
|
||||||
|
{
|
||||||
|
// just ignore JsonException
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
{
|
|
||||||
var jtoken = JToken.Parse(input);
|
|
||||||
return IsMatch(jtoken);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return MatchScores.Mismatch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
||||||
public double IsMatch(object input)
|
public double IsMatch(object input)
|
||||||
{
|
{
|
||||||
if (input == null)
|
double match = MatchScores.Mismatch;
|
||||||
|
if (input != null)
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
try
|
||||||
|
{
|
||||||
|
// Check if JToken or object
|
||||||
|
JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
|
||||||
|
match = IsMatch(jtoken);
|
||||||
|
}
|
||||||
|
catch (JsonException)
|
||||||
|
{
|
||||||
|
// just ignore JsonException
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
{
|
|
||||||
// Check if JToken or object
|
|
||||||
JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
|
|
||||||
return IsMatch(jtoken);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return MatchScores.Mismatch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
||||||
@@ -70,11 +85,8 @@ namespace WireMock.Matchers
|
|||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public string GetName()
|
public string Name => "JsonPathMatcher";
|
||||||
{
|
|
||||||
return "JsonPathMatcher";
|
|
||||||
}
|
|
||||||
|
|
||||||
private double IsMatch(JToken jtoken)
|
private double IsMatch(JToken jtoken)
|
||||||
{
|
{
|
||||||
|
|||||||
18
src/WireMock.Net/Matchers/MatchBehaviour.cs
Normal file
18
src/WireMock.Net/Matchers/MatchBehaviour.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace WireMock.Matchers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MatchBehaviour
|
||||||
|
/// </summary>
|
||||||
|
public enum MatchBehaviour
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Accept on match (default)
|
||||||
|
/// </summary>
|
||||||
|
AcceptOnMatch,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reject on match
|
||||||
|
/// </summary>
|
||||||
|
RejectOnMatch
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/WireMock.Net/Matchers/MatchBehaviourHelper.cs
Normal file
28
src/WireMock.Net/Matchers/MatchBehaviourHelper.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
namespace WireMock.Matchers
|
||||||
|
{
|
||||||
|
internal static class MatchBehaviourHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the specified match behaviour and match value to a new match value.
|
||||||
|
///
|
||||||
|
/// if AcceptOnMatch --> return match (default)
|
||||||
|
/// if RejectOnMatch and match = 0.0 --> return 1.0
|
||||||
|
/// if RejectOnMatch and match = 0.? --> return 0.0
|
||||||
|
/// if RejectOnMatch and match = 1.0 --> return 0.0
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="match">The match.</param>
|
||||||
|
/// <returns>match value</returns>
|
||||||
|
internal static double Convert(MatchBehaviour matchBehaviour, double match)
|
||||||
|
{
|
||||||
|
if (matchBehaviour == MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match <= MatchScores.Tolerance ? MatchScores.Perfect : MatchScores.Mismatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,18 +9,32 @@ namespace WireMock.Matchers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Regular Expression Matcher
|
/// Regular Expression Matcher
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="IStringMatcher" />
|
/// <inheritdoc cref="IStringMatcher"/>
|
||||||
|
/// <inheritdoc cref="IIgnoreCaseMatcher"/>
|
||||||
public class RegexMatcher : IStringMatcher, IIgnoreCaseMatcher
|
public class RegexMatcher : IStringMatcher, IIgnoreCaseMatcher
|
||||||
{
|
{
|
||||||
private readonly string[] _patterns;
|
private readonly string[] _patterns;
|
||||||
private readonly Regex[] _expressions;
|
private readonly Regex[] _expressions;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">IgnoreCase</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
public RegexMatcher([NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(new [] { pattern }, ignoreCase )
|
public RegexMatcher([NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="pattern">The pattern.</param>
|
||||||
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
|
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] string pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,13 +42,24 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">IgnoreCase</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
public RegexMatcher([NotNull, RegexPattern] string[] patterns, bool ignoreCase = false)
|
public RegexMatcher([NotNull, RegexPattern] string[] patterns, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, patterns, ignoreCase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
|
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] string[] patterns, bool ignoreCase = false)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
IgnoreCase = ignoreCase;
|
IgnoreCase = ignoreCase;
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
|
|
||||||
RegexOptions options = RegexOptions.Compiled;
|
RegexOptions options = RegexOptions.Compiled;
|
||||||
if (ignoreCase)
|
if (ignoreCase)
|
||||||
@@ -48,19 +73,20 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||||
public double IsMatch(string input)
|
public double IsMatch(string input)
|
||||||
{
|
{
|
||||||
if (input == null)
|
double match = MatchScores.Mismatch;
|
||||||
|
if (input != null)
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
try
|
||||||
}
|
{
|
||||||
|
match = MatchScores.ToScore(_expressions.Select(e => e.IsMatch(input)));
|
||||||
try
|
}
|
||||||
{
|
catch (Exception)
|
||||||
return MatchScores.ToScore(_expressions.Select(e => e.IsMatch(input)));
|
{
|
||||||
}
|
// just ignore exception
|
||||||
catch (Exception)
|
}
|
||||||
{
|
|
||||||
return MatchScores.Mismatch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
||||||
@@ -69,11 +95,8 @@ namespace WireMock.Matchers
|
|||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public virtual string GetName()
|
public virtual string Name => "RegexMatcher";
|
||||||
{
|
|
||||||
return "RegexMatcher";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
||||||
public bool IgnoreCase { get; }
|
public bool IgnoreCase { get; }
|
||||||
|
|||||||
@@ -32,24 +32,27 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
public RequestMessageBodyMatcher([NotNull] string body) : this(new SimMetricsMatcher(body))
|
public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] string body) : this(new WildcardMatcher(matchBehaviour, body))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
public RequestMessageBodyMatcher([NotNull] byte[] body) : this(new ExactObjectMatcher(body))
|
public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] body) : this(new ExactObjectMatcher(matchBehaviour, body))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
public RequestMessageBodyMatcher([NotNull] object body) : this(new ExactObjectMatcher(body))
|
public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] object body) : this(new ExactObjectMatcher(matchBehaviour, body))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ namespace WireMock.Matchers.Request
|
|||||||
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientIPs">The clientIPs.</param>
|
/// <param name="clientIPs">The clientIPs.</param>
|
||||||
public RequestMessageClientIPMatcher([NotNull] params string[] clientIPs) : this(clientIPs.Select(ip => new WildcardMatcher(ip)).Cast<IStringMatcher>().ToArray())
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
public RequestMessageClientIPMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] clientIPs) : this(clientIPs.Select(ip => new WildcardMatcher(matchBehaviour, ip)).Cast<IStringMatcher>().ToArray())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestMessageCookieMatcher : IRequestMatcher
|
public class RequestMessageCookieMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
|
private readonly MatchBehaviour _matchBehaviour;
|
||||||
|
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The funcs.
|
/// The funcs.
|
||||||
/// </value>
|
/// </value>
|
||||||
@@ -29,16 +31,18 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">The ignoreCase.</param>
|
/// <param name="ignoreCase">The ignoreCase.</param>
|
||||||
public RequestMessageCookieMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
|
public RequestMessageCookieMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
|
||||||
{
|
{
|
||||||
Check.NotNull(name, nameof(name));
|
Check.NotNull(name, nameof(name));
|
||||||
Check.NotNull(pattern, nameof(pattern));
|
Check.NotNull(pattern, nameof(pattern));
|
||||||
|
|
||||||
|
_matchBehaviour = matchBehaviour;
|
||||||
Name = name;
|
Name = name;
|
||||||
Matchers = new IStringMatcher[] { new WildcardMatcher(pattern, ignoreCase) };
|
Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -77,7 +81,7 @@ namespace WireMock.Matchers.Request
|
|||||||
{
|
{
|
||||||
if (requestMessage.Cookies == null)
|
if (requestMessage.Cookies == null)
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Funcs != null)
|
if (Funcs != null)
|
||||||
@@ -92,7 +96,7 @@ namespace WireMock.Matchers.Request
|
|||||||
|
|
||||||
if (!requestMessage.Cookies.ContainsKey(Name))
|
if (!requestMessage.Cookies.ContainsKey(Name))
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
string value = requestMessage.Cookies[Name];
|
string value = requestMessage.Cookies[Name];
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <inheritdoc cref="IRequestMatcher"/>
|
/// <inheritdoc cref="IRequestMatcher"/>
|
||||||
public class RequestMessageHeaderMatcher : IRequestMatcher
|
public class RequestMessageHeaderMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
|
private readonly MatchBehaviour _matchBehaviour;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The functions
|
/// The functions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -33,14 +35,16 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
public RequestMessageHeaderMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase)
|
||||||
{
|
{
|
||||||
Check.NotNull(name, nameof(name));
|
Check.NotNull(name, nameof(name));
|
||||||
Check.NotNull(pattern, nameof(pattern));
|
Check.NotNull(pattern, nameof(pattern));
|
||||||
|
|
||||||
|
_matchBehaviour = matchBehaviour;
|
||||||
Name = name;
|
Name = name;
|
||||||
Matchers = new IStringMatcher[] { new WildcardMatcher(pattern, ignoreCase) };
|
Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,14 +52,16 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
public RequestMessageHeaderMatcher([NotNull] string name, [NotNull] string[] patterns, bool ignoreCase = true)
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string[] patterns, bool ignoreCase)
|
||||||
{
|
{
|
||||||
Check.NotNull(name, nameof(name));
|
Check.NotNull(name, nameof(name));
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
|
_matchBehaviour = matchBehaviour;
|
||||||
Name = name;
|
Name = name;
|
||||||
Matchers = patterns.Select(pattern => new WildcardMatcher(pattern, ignoreCase)).Cast<IStringMatcher>().ToArray();
|
Matchers = patterns.Select(pattern => new WildcardMatcher(matchBehaviour, pattern, ignoreCase)).Cast<IStringMatcher>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -94,7 +100,7 @@ namespace WireMock.Matchers.Request
|
|||||||
{
|
{
|
||||||
if (requestMessage.Headers == null)
|
if (requestMessage.Headers == null)
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Funcs != null)
|
if (Funcs != null)
|
||||||
@@ -109,7 +115,7 @@ namespace WireMock.Matchers.Request
|
|||||||
|
|
||||||
if (!requestMessage.Headers.ContainsKey(Name))
|
if (!requestMessage.Headers.ContainsKey(Name))
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
WireMockList<string> list = requestMessage.Headers[Name];
|
WireMockList<string> list = requestMessage.Headers[Name];
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class RequestMessageMethodMatcher : IRequestMatcher
|
internal class RequestMessageMethodMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
|
private readonly MatchBehaviour _matchBehaviour;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The methods
|
/// The methods
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -17,26 +19,20 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageMethodMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="methods">
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The verb.
|
/// <param name="methods">The methods.</param>
|
||||||
/// </param>
|
public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods)
|
||||||
public RequestMessageMethodMatcher([NotNull] params string[] methods)
|
|
||||||
{
|
{
|
||||||
Check.NotNull(methods, nameof(methods));
|
Check.NotNull(methods, nameof(methods));
|
||||||
|
_matchBehaviour = matchBehaviour;
|
||||||
|
|
||||||
Methods = methods.Select(v => v.ToLower()).ToArray();
|
Methods = methods.Select(v => v.ToLower()).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <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 = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestMessageParamMatcher : IRequestMatcher
|
public class RequestMessageParamMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
|
private readonly MatchBehaviour _matchBehaviour;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The funcs
|
/// The funcs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -30,20 +32,23 @@ 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="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
public RequestMessageParamMatcher([NotNull] string key) : this(key, null)
|
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key) : this(matchBehaviour, key, null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <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="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable<string> values)
|
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] IEnumerable<string> values)
|
||||||
{
|
{
|
||||||
Check.NotNull(key, nameof(key));
|
Check.NotNull(key, nameof(key));
|
||||||
|
|
||||||
|
_matchBehaviour = matchBehaviour;
|
||||||
Key = key;
|
Key = key;
|
||||||
Values = values;
|
Values = values;
|
||||||
}
|
}
|
||||||
@@ -62,7 +67,7 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||||
{
|
{
|
||||||
double score = IsMatch(requestMessage);
|
double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage));
|
||||||
return requestMatchResult.AddScore(GetType(), score);
|
return requestMatchResult.AddScore(GetType(), score);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace WireMock.Matchers.Request
|
|||||||
public class RequestMessagePathMatcher : IRequestMatcher
|
public class RequestMessagePathMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The matcher.
|
/// The matchers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<IStringMatcher> Matchers { get; }
|
public IReadOnlyList<IStringMatcher> Matchers { get; }
|
||||||
|
|
||||||
@@ -24,8 +24,9 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="paths">The paths.</param>
|
/// <param name="paths">The paths.</param>
|
||||||
public RequestMessagePathMatcher([NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatcher(path)).Cast<IStringMatcher>().ToArray())
|
public RequestMessagePathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatcher(matchBehaviour, path)).Cast<IStringMatcher>().ToArray())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ namespace WireMock.Matchers.Request
|
|||||||
public RequestMessagePathMatcher([NotNull] params IStringMatcher[] matchers)
|
public RequestMessagePathMatcher([NotNull] params IStringMatcher[] matchers)
|
||||||
{
|
{
|
||||||
Check.NotNull(matchers, nameof(matchers));
|
Check.NotNull(matchers, nameof(matchers));
|
||||||
|
|
||||||
Matchers = matchers;
|
Matchers = matchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +48,7 @@ namespace WireMock.Matchers.Request
|
|||||||
public RequestMessagePathMatcher([NotNull] params Func<string, bool>[] funcs)
|
public RequestMessagePathMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||||
{
|
{
|
||||||
Check.NotNull(funcs, nameof(funcs));
|
Check.NotNull(funcs, nameof(funcs));
|
||||||
|
|
||||||
Funcs = funcs;
|
Funcs = funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="urls">The urls.</param>
|
/// <param name="urls">The urls.</param>
|
||||||
public RequestMessageUrlMatcher([NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(url)).Cast<IStringMatcher>().ToArray())
|
public RequestMessageUrlMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(matchBehaviour, url)).Cast<IStringMatcher>().ToArray())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,25 @@ namespace WireMock.Matchers
|
|||||||
private readonly string[] _patterns;
|
private readonly string[] _patterns;
|
||||||
private readonly SimMetricType _simMetricType;
|
private readonly SimMetricType _simMetricType;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
|
/// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="simMetricType">The SimMetric Type</param>
|
/// <param name="simMetricType">The SimMetric Type</param>
|
||||||
public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : this(new [] { pattern }, simMetricType)
|
public SimMetricsMatcher([NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : this(new[] { pattern }, simMetricType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="pattern">The pattern.</param>
|
||||||
|
/// <param name="simMetricType">The SimMetric Type</param>
|
||||||
|
public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern, SimMetricType simMetricType = SimMetricType.Levenstein) : this(matchBehaviour, new[] { pattern }, simMetricType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,10 +43,21 @@ namespace WireMock.Matchers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="simMetricType">The SimMetric Type</param>
|
/// <param name="simMetricType">The SimMetric Type</param>
|
||||||
public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
|
public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein) : this(MatchBehaviour.AcceptOnMatch, patterns, simMetricType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
/// <param name="simMetricType">The SimMetric Type</param>
|
||||||
|
public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(patterns, nameof(patterns));
|
Check.NotNullOrEmpty(patterns, nameof(patterns));
|
||||||
|
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
_simMetricType = simMetricType;
|
_simMetricType = simMetricType;
|
||||||
}
|
}
|
||||||
@@ -43,7 +67,7 @@ namespace WireMock.Matchers
|
|||||||
{
|
{
|
||||||
IStringMetric m = GetStringMetricType();
|
IStringMetric m = GetStringMetricType();
|
||||||
|
|
||||||
return MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input)));
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_patterns.Select(p => m.GetSimilarity(p, input))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IStringMetric GetStringMetricType()
|
private IStringMetric GetStringMetricType()
|
||||||
@@ -95,10 +119,7 @@ namespace WireMock.Matchers
|
|||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public string GetName()
|
public string Name => $"SimMetricsMatcher.{_simMetricType}";
|
||||||
{
|
|
||||||
return $"SimMetricsMatcher.{_simMetricType}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,17 @@ namespace WireMock.Matchers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">IgnoreCase</param>
|
/// <param name="ignoreCase">IgnoreCase</param>
|
||||||
public WildcardMatcher([NotNull] string pattern, bool ignoreCase = false) : this(new [] { pattern }, ignoreCase)
|
public WildcardMatcher([NotNull] string pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="WildcardMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="pattern">The pattern.</param>
|
||||||
|
/// <param name="ignoreCase">IgnoreCase</param>
|
||||||
|
public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +36,17 @@ namespace WireMock.Matchers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">IgnoreCase</param>
|
/// <param name="ignoreCase">IgnoreCase</param>
|
||||||
public WildcardMatcher([NotNull] string[] patterns, bool ignoreCase = false) : base(patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase)
|
public WildcardMatcher([NotNull] string[] patterns, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, patterns, ignoreCase)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="WildcardMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
/// <param name="ignoreCase">IgnoreCase</param>
|
||||||
|
public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false) : base(matchBehaviour, patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase)
|
||||||
{
|
{
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
@@ -37,10 +57,7 @@ namespace WireMock.Matchers
|
|||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public override string GetName()
|
public override string Name => "WildcardMatcher";
|
||||||
{
|
|
||||||
return "WildcardMatcher";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,38 +17,52 @@ namespace WireMock.Matchers
|
|||||||
{
|
{
|
||||||
private readonly string[] _patterns;
|
private readonly string[] _patterns;
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public XPathMatcher([NotNull] params string[] patterns)
|
public XPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
public XPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
|
MatchBehaviour = matchBehaviour;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||||
public double IsMatch(string input)
|
public double IsMatch(string input)
|
||||||
{
|
{
|
||||||
if (input == null)
|
double match = MatchScores.Mismatch;
|
||||||
|
if (input != null)
|
||||||
{
|
{
|
||||||
return MatchScores.Mismatch;
|
try
|
||||||
|
{
|
||||||
|
var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
|
||||||
|
#if NETSTANDARD1_3
|
||||||
|
match = MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
|
||||||
|
#else
|
||||||
|
match = MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// just ignore exception
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
{
|
|
||||||
var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
|
|
||||||
#if NETSTANDARD1_3
|
|
||||||
return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
|
|
||||||
#else
|
|
||||||
return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
return MatchScores.Mismatch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
|
||||||
@@ -57,10 +71,7 @@ namespace WireMock.Matchers
|
|||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.GetName"/>
|
/// <inheritdoc cref="IMatcher.Name"/>
|
||||||
public string GetName()
|
public string Name => "XPathMatcher";
|
||||||
{
|
|
||||||
return "XPathMatcher";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,39 +20,42 @@ namespace WireMock.RequestBuilders
|
|||||||
/// WithBody: Body as string
|
/// WithBody: Body as string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(string body);
|
IRequestBuilder WithBody(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody: Body as byte[]
|
/// WithBody: Body as byte[]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(byte[] body);
|
IRequestBuilder WithBody(byte[] body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody: Body as object
|
/// WithBody: Body as object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(object body);
|
IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///WithBody: func (string)
|
/// WithBody: func (string)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">The function.</param>
|
/// <param name="func">The function.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody([NotNull] Func<string, bool> func);
|
IRequestBuilder WithBody([NotNull] Func<string, bool> func);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///WithBody: func (byte[])
|
/// WithBody: func (byte[])
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">The function.</param>
|
/// <param name="func">The function.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody([NotNull] Func<byte[], bool> func);
|
IRequestBuilder WithBody([NotNull] Func<byte[], bool> func);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///WithBody: func (object)
|
/// WithBody: func (object)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">The function.</param>
|
/// <param name="func">The function.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
|||||||
@@ -10,21 +10,29 @@ namespace WireMock.RequestBuilders
|
|||||||
public interface IClientIPRequestBuilder : IUrlAndPathRequestBuilder
|
public interface IClientIPRequestBuilder : IUrlAndPathRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with ClientIP.
|
/// WithClientIP: add matching on ClientIP matchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithClientIP([NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithClientIP([NotNull] params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with ClientIP.
|
/// WithClientIP: add matching on clientIPs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientIPs">The clientIPs.</param>
|
/// <param name="clientIPs">The clientIPs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithClientIP([NotNull] params string[] clientIPs);
|
IRequestBuilder WithClientIP([NotNull] params string[] clientIPs);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with ClientIP.
|
/// WithClientIP: add matching on clientIPs and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="clientIPs">The clientIPs.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithClientIP(MatchBehaviour matchBehaviour, [NotNull] params string[] clientIPs);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithClientIP: add matching on ClientIP funcs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="funcs">The path funcs.</param>
|
/// <param name="funcs">The path funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
|||||||
@@ -12,25 +12,45 @@ namespace WireMock.RequestBuilders
|
|||||||
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
|
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add Header matching based on name, pattern and ignoreCase.
|
/// WithHeader: matching based on name, pattern and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">ignore Case</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true);
|
IRequestBuilder WithHeader([NotNull] string name, string pattern, MatchBehaviour matchBehaviour);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add Header matching based on name, patterns and ignoreCase.
|
/// WithHeader: matching based on name, pattern, ignoreCase and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="pattern">The pattern.</param>
|
||||||
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithHeader: matching based on name, patterns and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">ignore Case</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithHeader([NotNull] string name, string[] patterns, bool ignoreCase = true);
|
IRequestBuilder WithHeader([NotNull] string name, string[] patterns, MatchBehaviour matchBehaviour);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with header.
|
/// WithHeader: matching based on name, patterns, ignoreCase and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithHeader([NotNull] string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithHeader: matching based on name and IStringMatcher[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
@@ -38,23 +58,24 @@ namespace WireMock.RequestBuilders
|
|||||||
IRequestBuilder WithHeader([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithHeader([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with header.
|
/// WithHeader: matching based on functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="funcs">The headers funcs.</param>
|
/// <param name="funcs">The headers funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithHeader([NotNull] params Func<IDictionary<string, string[]>, bool>[] funcs);
|
IRequestBuilder WithHeader([NotNull] params Func<IDictionary<string, string[]>, bool>[] funcs);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with cookie.
|
/// WithCookie: cookie matching based on name, pattern, ignoreCase and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
/// <param name="ignoreCase">ignore Case</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithCookie([NotNull] string name, string pattern, bool ignoreCase = true);
|
IRequestBuilder WithCookie([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with cookie.
|
/// WithCookie: matching based on name and IStringMatcher[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
@@ -62,7 +83,7 @@ namespace WireMock.RequestBuilders
|
|||||||
IRequestBuilder WithCookie([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithCookie([NotNull] string name, [NotNull] params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with cookie.
|
/// WithCookie: matching based on functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cookieFuncs">The funcs.</param>
|
/// <param name="cookieFuncs">The funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using JetBrains.Annotations;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using WireMock.Matchers;
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders
|
namespace WireMock.RequestBuilders
|
||||||
{
|
{
|
||||||
@@ -8,66 +10,81 @@ namespace WireMock.RequestBuilders
|
|||||||
public interface IMethodRequestBuilder : IHeadersAndCookiesRequestBuilder
|
public interface IMethodRequestBuilder : IHeadersAndCookiesRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using delete.
|
/// UsingDelete: add HTTP Method matching on `delete` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </returns>
|
IRequestBuilder UsingDelete(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
IRequestBuilder UsingDelete();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using get.
|
/// UsingGet: add HTTP Method matching on `get` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </returns>
|
IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
IRequestBuilder UsingGet();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using head.
|
/// Add HTTP Method matching on `head` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </returns>
|
IRequestBuilder UsingHead(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
IRequestBuilder UsingHead();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using post.
|
/// UsingPost: add HTTP Method matching on `post` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </returns>
|
IRequestBuilder UsingPost(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
IRequestBuilder UsingPost();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using patch.
|
/// UsingPatch: add HTTP Method matching on `patch` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </returns>
|
IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
IRequestBuilder UsingPatch();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using put.
|
/// UsingPut: add HTTP Method matching on `put` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// </returns>
|
IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
IRequestBuilder UsingPut();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using any verb.
|
/// UsingAnyMethod: add HTTP Method matching on any method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
/// The <see cref="IRequestBuilder"/>.
|
IRequestBuilder UsingAnyMethod();
|
||||||
/// </returns>
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingAnyVerb: add HTTP Method matching on any method.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
[Obsolete]
|
||||||
IRequestBuilder UsingAnyVerb();
|
IRequestBuilder UsingAnyVerb();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using verb.
|
/// UsingMethod: add HTTP Method matching on any methods and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="verbs">The verb.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="methods">The methods.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, [NotNull] params string[] methods);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingMethod: add HTTP Method matching on any methods.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="methods">The methods.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder UsingMethod([NotNull] params string[] methods);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsingVerb: add HTTP Method matching on any methods.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="verbs">The methods.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
[Obsolete]
|
||||||
IRequestBuilder UsingVerb([NotNull] params string[] verbs);
|
IRequestBuilder UsingVerb([NotNull] params string[] verbs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using WireMock.Matchers;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders
|
namespace WireMock.RequestBuilders
|
||||||
@@ -11,14 +12,15 @@ namespace WireMock.RequestBuilders
|
|||||||
public interface IParamsRequestBuilder
|
public interface IParamsRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithParam (key only)
|
/// WithParam: matching on key only.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour (optional).</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithParam([NotNull] string key);
|
IRequestBuilder WithParam([NotNull] string key, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithParam (values)
|
/// WithParam: matching on key and values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
@@ -26,7 +28,16 @@ namespace WireMock.RequestBuilders
|
|||||||
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params string[] values);
|
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params string[] values);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithParam (funcs)
|
/// WithParam: matching on key, values and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key.</param>
|
||||||
|
/// <param name="values">The values.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithParam([NotNull] string key, MatchBehaviour matchBehaviour, [CanBeNull] params string[] values);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithParam: matching on functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="funcs">The funcs.</param>
|
/// <param name="funcs">The funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
|||||||
@@ -10,42 +10,58 @@ namespace WireMock.RequestBuilders
|
|||||||
public interface IUrlAndPathRequestBuilder : IMethodRequestBuilder
|
public interface IUrlAndPathRequestBuilder : IMethodRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with path.
|
/// WithPath: add path matching based on IStringMatchers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithPath([NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithPath([NotNull] params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with path.
|
/// WithPath: add path matching based on paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="paths">The paths.</param>
|
/// <param name="paths">The paths.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithPath([NotNull] params string[] paths);
|
IRequestBuilder WithPath([NotNull] params string[] paths);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with path.
|
/// WithPath: add path matching based on paths and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="paths">The paths.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithPath(MatchBehaviour matchBehaviour, [NotNull] params string[] paths);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithPath: add path matching based on functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="funcs">The path funcs.</param>
|
/// <param name="funcs">The path funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithPath([NotNull] params Func<string, bool>[] funcs);
|
IRequestBuilder WithPath([NotNull] params Func<string, bool>[] funcs);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with url.
|
/// WithUrl: add url matching based on IStringMatcher[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchers">The matchers.</param>
|
/// <param name="matchers">The matchers.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithUrl([NotNull] params IStringMatcher[] matchers);
|
IRequestBuilder WithUrl([NotNull] params IStringMatcher[] matchers);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with url.
|
/// WithUrl: add url matching based on urls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="urls">The urls.</param>
|
/// <param name="urls">The urls.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithUrl([NotNull] params string[] urls);
|
IRequestBuilder WithUrl([NotNull] params string[] urls);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with path.
|
/// WithUrl: add url matching based on urls.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="urls">The urls.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithUrl(MatchBehaviour matchBehaviour, [NotNull] params string[] urls);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithUrl: add url matching based on functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">The path func.</param>
|
/// <param name="func">The path func.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
|||||||
@@ -54,11 +54,7 @@ namespace WireMock.RequestBuilders
|
|||||||
return _requestMatchers.Where(rm => rm is T).Cast<T>().FirstOrDefault();
|
return _requestMatchers.Where(rm => rm is T).Cast<T>().FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(IStringMatcher[])"/>
|
||||||
/// The with clientIP.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchers">The matchers.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithClientIP(params IStringMatcher[] matchers)
|
public IRequestBuilder WithClientIP(params IStringMatcher[] matchers)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||||
@@ -67,24 +63,22 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(string[])"/>
|
||||||
/// The with clientIP.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="clientIPs">The ClientIPs.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithClientIP(params string[] clientIPs)
|
public IRequestBuilder WithClientIP(params string[] clientIPs)
|
||||||
|
{
|
||||||
|
return WithClientIP(MatchBehaviour.AcceptOnMatch, clientIPs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(string[])"/>
|
||||||
|
public IRequestBuilder WithClientIP(MatchBehaviour matchBehaviour, params string[] clientIPs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
|
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(clientIPs));
|
_requestMatchers.Add(new RequestMessageClientIPMatcher(matchBehaviour, clientIPs));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(Func{string, bool}[])"/>
|
||||||
/// The with clientIP.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="funcs">The clientIP funcs.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
|
public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||||
@@ -93,11 +87,7 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(IStringMatcher[])"/>
|
||||||
/// The with path.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchers">The matchers.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithPath(params IStringMatcher[] matchers)
|
public IRequestBuilder WithPath(params IStringMatcher[] matchers)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||||
@@ -106,24 +96,22 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(string[])"/>
|
||||||
/// The with path.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="paths">The paths.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithPath(params string[] paths)
|
public IRequestBuilder WithPath(params string[] paths)
|
||||||
|
{
|
||||||
|
return WithPath(MatchBehaviour.AcceptOnMatch, paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(MatchBehaviour, string[])"/>
|
||||||
|
public IRequestBuilder WithPath(MatchBehaviour matchBehaviour, params string[] paths)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(paths, nameof(paths));
|
Check.NotNullOrEmpty(paths, nameof(paths));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessagePathMatcher(paths));
|
_requestMatchers.Add(new RequestMessagePathMatcher(matchBehaviour, paths));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(Func{string, bool}[])"/>
|
||||||
/// The with path.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="funcs">The path func.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
|
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||||
@@ -132,11 +120,7 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(IStringMatcher[])"/>
|
||||||
/// The with url.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchers">The matchers.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithUrl(params IStringMatcher[] matchers)
|
public IRequestBuilder WithUrl(params IStringMatcher[] matchers)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||||
@@ -145,24 +129,22 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(string[])"/>
|
||||||
/// The with url.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="urls">The urls.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithUrl(params string[] urls)
|
public IRequestBuilder WithUrl(params string[] urls)
|
||||||
|
{
|
||||||
|
return WithUrl(MatchBehaviour.AcceptOnMatch, urls);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(MatchBehaviour, string[])"/>
|
||||||
|
public IRequestBuilder WithUrl(MatchBehaviour matchBehaviour, params string[] urls)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageUrlMatcher(urls));
|
_requestMatchers.Add(new RequestMessageUrlMatcher(matchBehaviour, urls));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(Func{string, bool}[])"/>
|
||||||
/// The with url.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="funcs">The url func.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithUrl(params Func<string, bool>[] funcs)
|
public IRequestBuilder WithUrl(params Func<string, bool>[] funcs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||||
@@ -171,50 +153,50 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingDelete"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingDelete(MatchBehaviour)"/>
|
||||||
public IRequestBuilder UsingDelete()
|
public IRequestBuilder UsingDelete(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher("delete"));
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "delete"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingGet"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingGet(MatchBehaviour)"/>
|
||||||
public IRequestBuilder UsingGet()
|
public IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher("get"));
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "get"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingHead"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingHead(MatchBehaviour)"/>
|
||||||
public IRequestBuilder UsingHead()
|
public IRequestBuilder UsingHead(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher("head"));
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "head"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPost"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingPost(MatchBehaviour)"/>
|
||||||
public IRequestBuilder UsingPost()
|
public IRequestBuilder UsingPost(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher("post"));
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "post"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPatch"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingPatch(MatchBehaviour)"/>
|
||||||
public IRequestBuilder UsingPatch()
|
public IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher("patch"));
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "patch"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPut"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingPut(MatchBehaviour)"/>
|
||||||
public IRequestBuilder UsingPut()
|
public IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher("put"));
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "put"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyVerb"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyMethod"/>
|
||||||
public IRequestBuilder UsingAnyVerb()
|
public IRequestBuilder UsingAnyMethod()
|
||||||
{
|
{
|
||||||
var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
|
var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
|
||||||
foreach (var matcher in matchers)
|
foreach (var matcher in matchers)
|
||||||
@@ -225,33 +207,51 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingVerb"/>
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyVerb"/>
|
||||||
|
public IRequestBuilder UsingAnyVerb()
|
||||||
|
{
|
||||||
|
return UsingAnyMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(string[])"/>
|
||||||
|
public IRequestBuilder UsingMethod(params string[] methods)
|
||||||
|
{
|
||||||
|
return UsingMethod(MatchBehaviour.AcceptOnMatch, methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingVerb(string[])"/>
|
||||||
public IRequestBuilder UsingVerb(params string[] verbs)
|
public IRequestBuilder UsingVerb(params string[] verbs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(verbs, nameof(verbs));
|
return UsingMethod(verbs);
|
||||||
|
}
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(verbs));
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(MatchBehaviour, string[])"/>
|
||||||
|
public IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, params string[] methods)
|
||||||
|
{
|
||||||
|
Check.NotNullOrEmpty(methods, nameof(methods));
|
||||||
|
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, methods));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(string)"/>
|
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(string, MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithBody(string body)
|
public IRequestBuilder WithBody(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
|
_requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(byte[])"/>
|
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(byte[], MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithBody(byte[] body)
|
public IRequestBuilder WithBody(byte[] body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
|
_requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(object)"/>
|
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(object, MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithBody(object body)
|
public IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
|
_requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,21 +291,27 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string)"/>
|
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithParam(string key)
|
public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
Check.NotNull(key, nameof(key));
|
Check.NotNull(key, nameof(key));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageParamMatcher(key));
|
_requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, string[])"/>
|
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, string[])"/>
|
||||||
public IRequestBuilder WithParam(string key, params string[] values)
|
public IRequestBuilder WithParam(string key, params string[] values)
|
||||||
|
{
|
||||||
|
return WithParam(key, MatchBehaviour.AcceptOnMatch, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, string[])"/>
|
||||||
|
public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, params string[] values)
|
||||||
{
|
{
|
||||||
Check.NotNull(key, nameof(key));
|
Check.NotNull(key, nameof(key));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageParamMatcher(key, values));
|
_requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, values));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,32 +324,39 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string,string,bool)"/>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string, MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true)
|
public IRequestBuilder WithHeader(string name, string pattern, MatchBehaviour matchBehaviour)
|
||||||
|
{
|
||||||
|
return WithHeader(name, pattern, true, matchBehaviour);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string, bool, MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
Check.NotNull(name, nameof(name));
|
Check.NotNull(name, nameof(name));
|
||||||
Check.NotNull(pattern, nameof(pattern));
|
Check.NotNull(pattern, nameof(pattern));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(name, pattern, ignoreCase));
|
_requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, pattern, ignoreCase));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string,string[],bool)"/>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string[], MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true)
|
public IRequestBuilder WithHeader(string name, string[] patterns, MatchBehaviour matchBehaviour)
|
||||||
|
{
|
||||||
|
return WithHeader(name, patterns, true, matchBehaviour);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string[], bool, MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
Check.NotNull(name, nameof(name));
|
Check.NotNull(name, nameof(name));
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(name, patterns, ignoreCase));
|
_requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, patterns, ignoreCase));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, IStringMatcher[])"/>
|
||||||
/// With header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="matchers">The matchers.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithHeader(string name, params IStringMatcher[] matchers)
|
public IRequestBuilder WithHeader(string name, params IStringMatcher[] matchers)
|
||||||
{
|
{
|
||||||
Check.NotNull(name, nameof(name));
|
Check.NotNull(name, nameof(name));
|
||||||
@@ -353,11 +366,7 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(Func{IDictionary{string, string[]}, bool}[])"/>
|
||||||
/// With header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="funcs">The funcs.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithHeader(params Func<IDictionary<string, string[]>, bool>[] funcs)
|
public IRequestBuilder WithHeader(params Func<IDictionary<string, string[]>, bool>[] funcs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||||
@@ -366,25 +375,14 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithCookie(string, string, bool, MatchBehaviour)"/>
|
||||||
/// With cookie.
|
public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="pattern">The pattern.</param>
|
|
||||||
/// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true)
|
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageCookieMatcher(name, pattern, ignoreCase));
|
_requestMatchers.Add(new RequestMessageCookieMatcher(matchBehaviour, name, pattern, ignoreCase));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithCookie(string, IStringMatcher[])"/>
|
||||||
/// With cookie.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="matchers">The matchers.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithCookie(string name, params IStringMatcher[] matchers)
|
public IRequestBuilder WithCookie(string name, params IStringMatcher[] matchers)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||||
@@ -393,11 +391,7 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithCookie(Func{IDictionary{string, string}, bool}[])"/>
|
||||||
/// With header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="funcs">The funcs.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
public IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs)
|
public IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ namespace WireMock.Serialization
|
|||||||
|
|
||||||
string[] patterns = matcher is IStringMatcher stringMatcher ? stringMatcher.GetPatterns() : new string[0];
|
string[] patterns = matcher is IStringMatcher stringMatcher ? stringMatcher.GetPatterns() : new string[0];
|
||||||
bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)null;
|
bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)null;
|
||||||
|
bool? rejectOnMatch = matcher.MatchBehaviour == MatchBehaviour.RejectOnMatch ? true : (bool?) null;
|
||||||
|
|
||||||
return new MatcherModel
|
return new MatcherModel
|
||||||
{
|
{
|
||||||
|
RejectOnMatch = rejectOnMatch,
|
||||||
IgnoreCase = ignorecase,
|
IgnoreCase = ignorecase,
|
||||||
Name = matcher.GetName(),
|
Name = matcher.Name,
|
||||||
Pattern = patterns.Length == 1 ? patterns.First() : null,
|
Pattern = patterns.Length == 1 ? patterns.First() : null,
|
||||||
Patterns = patterns.Length > 1 ? patterns : null
|
Patterns = patterns.Length > 1 ? patterns : null
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,23 +20,24 @@ namespace WireMock.Serialization
|
|||||||
string matcherType = parts.Length > 1 ? parts[1] : null;
|
string matcherType = parts.Length > 1 ? parts[1] : null;
|
||||||
|
|
||||||
string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
|
string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
|
||||||
|
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
|
||||||
|
|
||||||
switch (matcherName)
|
switch (matcherName)
|
||||||
{
|
{
|
||||||
case "ExactMatcher":
|
case "ExactMatcher":
|
||||||
return new ExactMatcher(patterns);
|
return new ExactMatcher(matchBehaviour, patterns);
|
||||||
|
|
||||||
case "RegexMatcher":
|
case "RegexMatcher":
|
||||||
return new RegexMatcher(patterns, matcher.IgnoreCase == true);
|
return new RegexMatcher(matchBehaviour, patterns, matcher.IgnoreCase == true);
|
||||||
|
|
||||||
case "JsonPathMatcher":
|
case "JsonPathMatcher":
|
||||||
return new JsonPathMatcher(patterns);
|
return new JsonPathMatcher(matchBehaviour, patterns);
|
||||||
|
|
||||||
case "XPathMatcher":
|
case "XPathMatcher":
|
||||||
return new XPathMatcher(matcher.Pattern);
|
return new XPathMatcher(matchBehaviour, matcher.Pattern);
|
||||||
|
|
||||||
case "WildcardMatcher":
|
case "WildcardMatcher":
|
||||||
return new WildcardMatcher(patterns, matcher.IgnoreCase == true);
|
return new WildcardMatcher(matchBehaviour, patterns, matcher.IgnoreCase == true);
|
||||||
|
|
||||||
case "SimMetricsMatcher":
|
case "SimMetricsMatcher":
|
||||||
SimMetricType type = SimMetricType.Levenstein;
|
SimMetricType type = SimMetricType.Levenstein;
|
||||||
@@ -45,7 +46,7 @@ namespace WireMock.Serialization
|
|||||||
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
|
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SimMetricsMatcher(matcher.Pattern, type);
|
return new SimMetricsMatcher(matchBehaviour, matcher.Pattern, type);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
|
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ namespace WireMock.Server
|
|||||||
private const string AdminRequests = "/__admin/requests";
|
private const string AdminRequests = "/__admin/requests";
|
||||||
private const string AdminSettings = "/__admin/settings";
|
private const string AdminSettings = "/__admin/settings";
|
||||||
private const string AdminScenarios = "/__admin/scenarios";
|
private const string AdminScenarios = "/__admin/scenarios";
|
||||||
private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
|
private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
|
||||||
private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(@"^\/__admin\/requests\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
|
private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/requests\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
|
||||||
|
|
||||||
private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
|
private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
// __admin/settings
|
// __admin/settings
|
||||||
Given(Request.Create().WithPath(AdminSettings).UsingGet()).RespondWith(new DynamicResponseProvider(SettingsGet));
|
Given(Request.Create().WithPath(AdminSettings).UsingGet()).RespondWith(new DynamicResponseProvider(SettingsGet));
|
||||||
Given(Request.Create().WithPath(AdminSettings).UsingVerb("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(SettingsUpdate));
|
Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, ContentTypeJson)).RespondWith(new DynamicResponseProvider(SettingsUpdate));
|
||||||
|
|
||||||
|
|
||||||
// __admin/mappings
|
// __admin/mappings
|
||||||
@@ -196,7 +196,7 @@ namespace WireMock.Server
|
|||||||
private void InitProxyAndRecord(IProxyAndRecordSettings settings)
|
private void InitProxyAndRecord(IProxyAndRecordSettings settings)
|
||||||
{
|
{
|
||||||
_httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ClientX509Certificate2ThumbprintOrSubjectName);
|
_httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ClientX509Certificate2ThumbprintOrSubjectName);
|
||||||
Given(Request.Create().WithPath("/*").UsingAnyVerb()).RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
|
Given(Request.Create().WithPath("/*").UsingAnyMethod()).RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, IProxyAndRecordSettings settings)
|
private async Task<ResponseMessage> ProxyAndRecordAsync(RequestMessage requestMessage, IProxyAndRecordSettings settings)
|
||||||
@@ -225,7 +225,7 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
request.WithPath(requestMessage.Path);
|
request.WithPath(requestMessage.Path);
|
||||||
request.UsingVerb(requestMessage.Method);
|
request.UsingMethod(requestMessage.Method);
|
||||||
|
|
||||||
requestMessage.Query.Loop((key, value) => request.WithParam(key, value.ToArray()));
|
requestMessage.Query.Loop((key, value) => request.WithParam(key, value.ToArray()));
|
||||||
requestMessage.Cookies.Loop((key, value) => request.WithCookie(key, value));
|
requestMessage.Cookies.Loop((key, value) => request.WithCookie(key, value));
|
||||||
@@ -241,7 +241,7 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
if (requestMessage.Body != null)
|
if (requestMessage.Body != null)
|
||||||
{
|
{
|
||||||
request.WithBody(new ExactMatcher(requestMessage.Body));
|
request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.Body));
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = Response.Create(responseMessage);
|
var response = Response.Create(responseMessage);
|
||||||
@@ -648,7 +648,7 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
if (requestModel.Methods != null)
|
if (requestModel.Methods != null)
|
||||||
{
|
{
|
||||||
requestBuilder = requestBuilder.UsingVerb(requestModel.Methods);
|
requestBuilder = requestBuilder.UsingMethod(requestModel.Methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestModel.Headers != null)
|
if (requestModel.Headers != null)
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ namespace WireMock.Server
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void AddCatchAllMapping()
|
public void AddCatchAllMapping()
|
||||||
{
|
{
|
||||||
Given(Request.Create().WithPath("/*").UsingAnyVerb())
|
Given(Request.Create().WithPath("/*").UsingAnyMethod())
|
||||||
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
|
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
|
||||||
.AtPriority(1000)
|
.AtPriority(1000)
|
||||||
.RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }));
|
.RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }));
|
||||||
@@ -351,7 +351,7 @@ namespace WireMock.Server
|
|||||||
Check.NotNull(password, nameof(password));
|
Check.NotNull(password, nameof(password));
|
||||||
|
|
||||||
string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
|
string authorization = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
|
||||||
_options.AuthorizationMatcher = new RegexMatcher("^(?i)BASIC " + authorization + "$");
|
_options.AuthorizationMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, "^(?i)BASIC " + authorization + "$");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -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.3.16</Version>
|
<Version>1.0.3.17</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>
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ namespace WireMock.Net.Tests
|
|||||||
// given
|
// given
|
||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server.Given(Request.Create().WithPath("/foo").UsingVerb("patch"))
|
_server.Given(Request.Create().WithPath("/foo").UsingMethod("patch"))
|
||||||
.RespondWith(Response.Create().WithBody("hello patch"));
|
.RespondWith(Response.Create().WithBody("hello patch"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -268,7 +268,7 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request.Create().UsingAnyVerb())
|
.Given(Request.Create().UsingAnyMethod())
|
||||||
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }));
|
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -285,7 +285,7 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request.Create().UsingAnyVerb())
|
.Given(Request.Create().UsingAnyMethod())
|
||||||
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }, true));
|
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }, true));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
25
test/WireMock.Net.Tests/MatchBehaviourHelperTests.cs
Normal file
25
test/WireMock.Net.Tests/MatchBehaviourHelperTests.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using NFluent;
|
||||||
|
using WireMock.Matchers;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests
|
||||||
|
{
|
||||||
|
public class MatchBehaviourHelperTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void MatchBehaviourHelper_Convert_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MatchBehaviourHelper_Convert_RejectOnMatch()
|
||||||
|
{
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.0)).IsEqualTo(1.0);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 0.5)).IsEqualTo(0.0);
|
||||||
|
Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.RejectOnMatch, 1.0)).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new ExactMatcher("X");
|
var matcher = new ExactMatcher("X");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("ExactMatcher");
|
Check.That(name).Equals("ExactMatcher");
|
||||||
@@ -46,7 +46,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Request_WithBodyExactMatcher_false()
|
public void ExactMatcher_IsMatch_SinglePattern()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new ExactMatcher("cat");
|
var matcher = new ExactMatcher("cat");
|
||||||
@@ -55,7 +55,33 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
double result = matcher.IsMatch("caR");
|
double result = matcher.IsMatch("caR");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsStrictlyLessThan(1.0);
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExactMatcher_IsMatch_SinglePattern_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, "cat");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("cat");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExactMatcher_IsMatch_SinglePattern_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new ExactMatcher(MatchBehaviour.RejectOnMatch, "cat");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("cat");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,10 +14,52 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
|
|
||||||
// Act
|
// Act
|
||||||
var matcher = new ExactObjectMatcher(obj);
|
var matcher = new ExactObjectMatcher(obj);
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("ExactObjectMatcher");
|
Check.That(name).Equals("ExactObjectMatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExactObjectMatcher_IsMatch_ByteArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
object checkValue = new byte[] { 1, 2 };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new ExactObjectMatcher(new byte[] { 1, 2 });
|
||||||
|
double result = matcher.IsMatch(checkValue);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExactObjectMatcher_IsMatch_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
object obj = 1;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new ExactObjectMatcher(obj);
|
||||||
|
double result = matcher.IsMatch(1);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ExactObjectMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
object obj = 1;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = new ExactObjectMatcher(MatchBehaviour.RejectOnMatch, obj);
|
||||||
|
double result = matcher.IsMatch(1);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new JsonPathMatcher("X");
|
var matcher = new JsonPathMatcher("X");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("JsonPathMatcher");
|
Check.That(name).Equals("JsonPathMatcher");
|
||||||
@@ -78,10 +78,10 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
public void JsonPathMatcher_IsMatch_Object_Exception_Mismatch()
|
public void JsonPathMatcher_IsMatch_Object_Exception_Mismatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new JsonPathMatcher("xxx");
|
var matcher = new JsonPathMatcher("");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double match = matcher.IsMatch("");
|
double match = matcher.IsMatch("x");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(match).IsEqualTo(0);
|
Check.That(match).IsEqualTo(0);
|
||||||
@@ -131,5 +131,18 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
// Assert
|
// Assert
|
||||||
Check.That(match).IsEqualTo(1);
|
Check.That(match).IsEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonPathMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonPathMatcher(MatchBehaviour.RejectOnMatch, "$..[?(@.Id == 1)]");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new RegexMatcher("");
|
var matcher = new RegexMatcher("");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("RegexMatcher");
|
Check.That(name).Equals("RegexMatcher");
|
||||||
@@ -32,6 +32,18 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
Check.That(patterns).ContainsExactly("X");
|
Check.That(patterns).ContainsExactly("X");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexMatcher_GetIgnoreCase()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
bool case1 = new RegexMatcher("X").IgnoreCase;
|
||||||
|
bool case2 = new RegexMatcher("X", true).IgnoreCase;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(case1).IsFalse();
|
||||||
|
Check.That(case2).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexMatcher_IsMatch()
|
public void RegexMatcher_IsMatch()
|
||||||
{
|
{
|
||||||
@@ -65,10 +77,23 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new RegexMatcher("H.*o", true);
|
var matcher = new RegexMatcher("H.*o", true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("hello world!");
|
double result = matcher.IsMatch("hello");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsEqualTo(1.0d);
|
Check.That(result).IsEqualTo(1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RegexMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("hello");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new SimMetricsMatcher("X");
|
var matcher = new SimMetricsMatcher("X");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
Check.That(name).Equals("SimMetricsMatcher.Levenstein");
|
||||||
@@ -57,5 +57,31 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
Check.That(result).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SimMetricsMatcher_IsMatch_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new SimMetricsMatcher("test");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("test");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SimMetricsMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new SimMetricsMatcher(MatchBehaviour.RejectOnMatch, "test");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("test");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new WildcardMatcher("x");
|
var matcher = new WildcardMatcher("x");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("WildcardMatcher");
|
Check.That(name).Equals("WildcardMatcher");
|
||||||
@@ -83,5 +83,17 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
// Assert
|
// Assert
|
||||||
Check.That(patterns).ContainsExactly("x");
|
Check.That(patterns).ContainsExactly("x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch("m");
|
||||||
|
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
var matcher = new XPathMatcher("X");
|
var matcher = new XPathMatcher("X");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string name = matcher.GetName();
|
string name = matcher.Name;
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(name).Equals("XPathMatcher");
|
Check.That(name).Equals("XPathMatcher");
|
||||||
@@ -31,5 +31,39 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
// Assert
|
// Assert
|
||||||
Check.That(patterns).ContainsExactly("X");
|
Check.That(patterns).ContainsExactly("X");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void XPathMatcher_IsMatch_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string xml = @"
|
||||||
|
<todo-list>
|
||||||
|
<todo-item id='a1'>abc</todo-item>
|
||||||
|
</todo-list>";
|
||||||
|
var matcher = new XPathMatcher("/todo-list[count(todo-item) = 1]");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch(xml);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void XPathMatcher_IsMatch_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
string xml = @"
|
||||||
|
<todo-list>
|
||||||
|
<todo-item id='a1'>abc</todo-item>
|
||||||
|
</todo-list>";
|
||||||
|
var matcher = new XPathMatcher(MatchBehaviour.RejectOnMatch, "/todo-list[count(todo-item) = 1]");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double result = matcher.IsMatch(xml);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(result).IsEqualTo(0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithCookie_OK()
|
public void Request_WithCookie_OK()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithCookie("session", "a*");
|
var spec = Request.Create().UsingAnyMethod().WithCookie("session", "a*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, null, null, new Dictionary<string, string> { { "session", "abc" } });
|
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, null, null, new Dictionary<string, string> { { "session", "abc" } });
|
||||||
|
|||||||
@@ -9,6 +9,99 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
public class RequestMessageCookieMatcherTests
|
public class RequestMessageCookieMatcherTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", "x");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", "x");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotMatchPattern()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var cookies = new Dictionary<string, string> { { "c", "x" } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "no-match", "123");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotMatchPattern()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "no-match", "123");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", "x");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var cookies = new Dictionary<string, string> { { "h", "x" } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
|
||||||
|
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", "x");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageCookieMatcher_GetMatchingScore_IStringMatcher_Match()
|
public void RequestMessageCookieMatcher_GetMatchingScore_IStringMatcher_Match()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,11 +9,104 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
public class RequestMessageHeaderMatcherTests
|
public class RequestMessageHeaderMatcherTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageHeaderMatcher_GetMatchingScore_AcceptOnMatch_HeaderDoesNotExists()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "h", "x", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageHeaderMatcher_GetMatchingScore_RejectOnMatch_HeaderDoesNotExists()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "h", "x", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageHeaderMatcher_GetMatchingScore_AcceptOnMatch_HeaderDoesNotMatchPattern()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
|
||||||
|
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "no-match", "123", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageHeaderMatcher_GetMatchingScore_RejectOnMatch_HeaderDoesNotMatchPattern()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
|
||||||
|
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "no-match", "123", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageHeaderMatcher_GetMatchingScore_AcceptOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
|
||||||
|
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "h", "x", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageHeaderMatcher_GetMatchingScore_RejectOnMatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
|
||||||
|
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "h", "x", true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestMessageHeaderMatcher_GetMatchingScore_IStringMatcher_Match()
|
public void RequestMessageHeaderMatcher_GetMatchingScore_IStringMatcher_Match()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var headers = new Dictionary<string, string[]> { { "h", new [] { "x" } } };
|
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
|
||||||
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
|
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
|
||||||
var matcher = new RequestMessageHeaderMatcher("h", new ExactMatcher("x"));
|
var matcher = new RequestMessageHeaderMatcher("h", new ExactMatcher("x"));
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
|
||||||
var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
@@ -27,7 +28,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
|
||||||
var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
@@ -42,7 +43,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
var matcher = new RequestMessageParamMatcher("key", new[] { "test1", "test2" });
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
@@ -57,7 +58,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
var matcher = new RequestMessageParamMatcher("key");
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
@@ -72,7 +73,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
var matcher = new RequestMessageParamMatcher("key", new string[] { });
|
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new string[] { });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = new RequestMatchResult();
|
var result = new RequestMatchResult();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_headers()
|
public void Should_exclude_requests_not_matching_given_headers()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tatata");
|
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tatata");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -46,7 +46,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "abc", false);
|
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "abc", false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -62,7 +62,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_header_prefix()
|
public void Should_specify_requests_matching_given_header_prefix()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithHeader("X-toto", "tata*");
|
var spec = Request.Create().UsingAnyMethod().WithHeader("X-toto", "tata*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -80,7 +80,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body()
|
public void Should_specify_requests_matching_given_body()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody("Hello world!");
|
var spec = Request.Create().UsingAnyMethod().WithBody("Hello world!");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -97,7 +97,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_body()
|
public void Should_exclude_requests_not_matching_given_body()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(" Hello world! ");
|
var spec = Request.Create().UsingAnyMethod().WithBody(" Hello world! ");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "xxx";
|
string bodyAsString = "xxx";
|
||||||
@@ -127,7 +127,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_param_func()
|
public void Should_specify_requests_matching_given_param_func()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithParam(p => p.ContainsKey("bar"));
|
var spec = Request.Create().UsingAnyMethod().WithParam(p => p.ContainsKey("bar"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
|
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBody_FuncString()
|
public void Request_WithBody_FuncString()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(b => b.Contains("b"));
|
var requestBuilder = Request.Create().UsingAnyMethod().WithBody(b => b.Contains("b"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = new BodyData
|
var body = new BodyData
|
||||||
@@ -37,7 +37,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBody_FuncJson()
|
public void Request_WithBody_FuncJson()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(b => b != null);
|
var requestBuilder = Request.Create().UsingAnyMethod().WithBody(b => b != null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = new BodyData
|
var body = new BodyData
|
||||||
@@ -55,7 +55,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBody_FuncByteArray()
|
public void Request_WithBody_FuncByteArray()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody((byte[] b) => b != null);
|
var requestBuilder = Request.Create().UsingAnyMethod().WithBody((byte[] b) => b != null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = new BodyData
|
var body = new BodyData
|
||||||
@@ -73,7 +73,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyExactMatcher()
|
public void Request_WithBodyExactMatcher()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
|
var requestBuilder = Request.Create().UsingAnyMethod().WithBody(new ExactMatcher("cat"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "cat";
|
string bodyAsString = "cat";
|
||||||
@@ -89,7 +89,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyWildcardMatcher()
|
public void Request_WithBodyWildcardMatcher()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new WildcardMatcher("H*o*"));
|
var spec = Request.Create().WithPath("/foo").UsingAnyMethod().WithBody(new WildcardMatcher("H*o*"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -105,7 +105,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyXPathMatcher_true()
|
public void Request_WithBodyXPathMatcher_true()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string xmlBodyAsString = @"
|
string xmlBodyAsString = @"
|
||||||
@@ -126,7 +126,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyXPathMatcher_false()
|
public void Request_WithBodyXPathMatcher_false()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string xmlBodyAsString = @"
|
string xmlBodyAsString = @"
|
||||||
@@ -147,7 +147,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyJsonPathMatcher_true()
|
public void Request_WithBodyJsonPathMatcher_true()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||||
@@ -163,7 +163,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyJsonPathMatcher_false()
|
public void Request_WithBodyJsonPathMatcher_false()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
|
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
|
||||||
@@ -179,7 +179,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyAsJson_Object_JsonPathMatcher_true()
|
public void Request_WithBodyAsJson_Object_JsonPathMatcher_true()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string jsonString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
string jsonString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||||
@@ -199,7 +199,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyAsJson_Array_JsonPathMatcher_1()
|
public void Request_WithBodyAsJson_Array_JsonPathMatcher_1()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..books[?(@.price < 10)]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..books[?(@.price < 10)]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string jsonString = "{ \"books\": [ { \"category\": \"test1\", \"price\": 8.95 }, { \"category\": \"test2\", \"price\": 20 } ] }";
|
string jsonString = "{ \"books\": [ { \"category\": \"test1\", \"price\": 8.95 }, { \"category\": \"test2\", \"price\": 20 } ] }";
|
||||||
@@ -220,7 +220,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithBodyAsJson_Array_JsonPathMatcher_2()
|
public void Request_WithBodyAsJson_Array_JsonPathMatcher_2()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..[?(@.Id == 1)]"));
|
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..[?(@.Id == 1)]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string jsonString = "{ \"Id\": 1, \"Name\": \"Test\" }";
|
string jsonString = "{ \"Id\": 1, \"Name\": \"Test\" }";
|
||||||
@@ -243,7 +243,7 @@ namespace WireMock.Net.Tests
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
object body = DateTime.MinValue;
|
object body = DateTime.MinValue;
|
||||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(body);
|
var requestBuilder = Request.Create().UsingAnyMethod().WithBody(body);
|
||||||
|
|
||||||
var bodyData = new BodyData
|
var bodyData = new BodyData
|
||||||
{
|
{
|
||||||
@@ -263,7 +263,7 @@ namespace WireMock.Net.Tests
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
byte[] body = { 123 };
|
byte[] body = { 123 };
|
||||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(body);
|
var requestBuilder = Request.Create().UsingAnyMethod().WithBody(body);
|
||||||
|
|
||||||
var bodyData = new BodyData
|
var bodyData = new BodyData
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Request_WithPath_WithHeader_Match()
|
public void Request_WithPath_WithHeader_Match()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
var spec = Request.Create().WithPath("/foo").UsingAnyMethod().WithHeader("X-toto", "tata");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcherMock = new Mock<IStringMatcher>();
|
var matcherMock = new Mock<IStringMatcher>();
|
||||||
matcherMock.Setup(m => m.GetName()).Returns("test");
|
matcherMock.Setup(m => m.Name).Returns("test");
|
||||||
matcherMock.Setup(m => m.GetPatterns()).Returns(new[] { "p1", "p2" });
|
matcherMock.Setup(m => m.GetPatterns()).Returns(new[] { "p1", "p2" });
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
Reference in New Issue
Block a user