mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
UrlModel + Funcs
This commit is contained in:
@@ -22,17 +22,17 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// The body function
|
||||
/// </summary>
|
||||
private readonly Func<string, bool> _bodyFunc;
|
||||
public Func<string, bool> Func { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body data function
|
||||
/// </summary>
|
||||
private readonly Func<byte[], bool> _bodyDataFunc;
|
||||
public Func<byte[], bool> DataFunc { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The matcher.
|
||||
/// </summary>
|
||||
public readonly IMatcher Matcher;
|
||||
public IMatcher Matcher { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
||||
@@ -67,7 +67,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageBodyMatcher([NotNull] Func<string, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
_bodyFunc = func;
|
||||
Func = func;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,7 +79,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageBodyMatcher([NotNull] Func<byte[], bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
_bodyDataFunc = func;
|
||||
DataFunc = func;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,11 +112,11 @@ namespace WireMock.Matchers.Request
|
||||
if (_bodyData != null)
|
||||
return requestMessage.BodyAsBytes == _bodyData;
|
||||
|
||||
if (_bodyFunc != null)
|
||||
return _bodyFunc(requestMessage.Body);
|
||||
if (Func != null)
|
||||
return Func(requestMessage.Body);
|
||||
|
||||
if (_bodyDataFunc != null)
|
||||
return _bodyDataFunc(requestMessage.BodyAsBytes);
|
||||
if (DataFunc != null)
|
||||
return DataFunc(requestMessage.BodyAsBytes);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@ namespace WireMock.Matchers.Request
|
||||
/// </summary>
|
||||
public class RequestMessageCookieMatcher : IRequestMatcher
|
||||
{
|
||||
private readonly Func<IDictionary<string, string>, bool>[] _cookieFuncs;
|
||||
/// <value>
|
||||
/// The funcs.
|
||||
/// </value>
|
||||
public Func<IDictionary<string, string>, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
@@ -63,7 +63,7 @@ namespace WireMock.Matchers.Request
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
|
||||
_cookieFuncs = funcs;
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,8 +75,8 @@ namespace WireMock.Matchers.Request
|
||||
/// </returns>
|
||||
public bool IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (_cookieFuncs != null)
|
||||
return _cookieFuncs.Any(cf => cf(requestMessage.Cookies));
|
||||
if (Funcs != null)
|
||||
return Funcs.Any(cf => cf(requestMessage.Cookies));
|
||||
|
||||
if (requestMessage.Cookies == null)
|
||||
return false;
|
||||
|
||||
@@ -11,16 +11,16 @@ namespace WireMock.Matchers.Request
|
||||
/// </summary>
|
||||
public class RequestMessageHeaderMatcher : IRequestMatcher
|
||||
{
|
||||
private readonly Func<IDictionary<string, string>, bool>[] _headerFuncs;
|
||||
/// <summary>
|
||||
/// The functions
|
||||
/// </summary>
|
||||
public Func<IDictionary<string, string>, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
@@ -63,7 +63,7 @@ namespace WireMock.Matchers.Request
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
|
||||
_headerFuncs = funcs;
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,8 +75,8 @@ namespace WireMock.Matchers.Request
|
||||
/// </returns>
|
||||
public bool IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (_headerFuncs != null)
|
||||
return _headerFuncs.Any(hf => hf(requestMessage.Headers));
|
||||
if (Funcs != null)
|
||||
return Funcs.Any(hf => hf(requestMessage.Headers));
|
||||
|
||||
if (requestMessage.Headers == null)
|
||||
return false;
|
||||
|
||||
@@ -12,7 +12,10 @@ namespace WireMock.Matchers.Request
|
||||
/// </summary>
|
||||
public class RequestMessageParamMatcher : IRequestMatcher
|
||||
{
|
||||
private readonly Func<IDictionary<string, WireMockList<string>>, bool>[] _funcs;
|
||||
/// <summary>
|
||||
/// The funcs
|
||||
/// </summary>
|
||||
public Func<IDictionary<string, WireMockList<string>>, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The key
|
||||
@@ -49,7 +52,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
_funcs = funcs;
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,8 +64,8 @@ namespace WireMock.Matchers.Request
|
||||
/// </returns>
|
||||
public bool IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (_funcs != null)
|
||||
return _funcs.Any(f => f(requestMessage.Query));
|
||||
if (Funcs != null)
|
||||
return Funcs.Any(f => f(requestMessage.Query));
|
||||
|
||||
var values = requestMessage.GetParameter(Key);
|
||||
return values?.Intersect(Values).Count() == Values.Count();
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// The path functions
|
||||
/// </summary>
|
||||
private readonly Func<string, bool>[] _pathFuncs;
|
||||
public Func<string, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
|
||||
@@ -46,7 +46,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessagePathMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
_pathFuncs = funcs;
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,8 +61,8 @@ namespace WireMock.Matchers.Request
|
||||
if (Matchers != null)
|
||||
return Matchers.Any(matcher => matcher.IsMatch(requestMessage.Path));
|
||||
|
||||
if (_pathFuncs != null)
|
||||
return _pathFuncs.Any(func => func(requestMessage.Path));
|
||||
if (Funcs != null)
|
||||
return Funcs.Any(func => func(requestMessage.Path));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// The matcher.
|
||||
/// </summary>
|
||||
public readonly IReadOnlyList<IMatcher> Matchers;
|
||||
public IReadOnlyList<IMatcher> Matchers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The url functions
|
||||
/// </summary>
|
||||
private readonly Func<string, bool>[] _urlFuncs;
|
||||
public Func<string, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
|
||||
@@ -46,7 +46,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageUrlMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
_urlFuncs = funcs;
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,8 +61,8 @@ namespace WireMock.Matchers.Request
|
||||
if (Matchers != null)
|
||||
return Matchers.Any(matcher => matcher.IsMatch(requestMessage.Url));
|
||||
|
||||
if (_urlFuncs != null)
|
||||
return _urlFuncs.Any(func => func(requestMessage.Url));
|
||||
if (Funcs != null)
|
||||
return Funcs.Any(func => func(requestMessage.Url));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user