mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 02:08:29 +02:00
Partial matching
This commit is contained in:
@@ -25,7 +25,7 @@ namespace WireMock.Matchers.Request
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public IMatcher[] Matchers { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class.
|
||||
/// </summary>
|
||||
@@ -70,17 +70,32 @@ namespace WireMock.Matchers.Request
|
||||
/// Determines whether the specified RequestMessage is match.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The RequestMessage.</param>
|
||||
/// <param name="requestMatchResult">The RequestMatchResult.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool IsMatch(RequestMessage requestMessage)
|
||||
public bool IsMatch(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
bool isMatch = IsMatch(requestMessage);
|
||||
if (isMatch)
|
||||
requestMatchResult.Matched++;
|
||||
|
||||
requestMatchResult.Total++;
|
||||
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
private bool IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (Funcs != null)
|
||||
return Funcs.Any(cf => cf(requestMessage.Cookies));
|
||||
return requestMessage.Cookies != null && Funcs.Any(cf => cf(requestMessage.Cookies));
|
||||
|
||||
if (requestMessage.Cookies == null)
|
||||
return false;
|
||||
|
||||
if (!requestMessage.Cookies.ContainsKey(Name))
|
||||
return false;
|
||||
|
||||
string headerValue = requestMessage.Cookies[Name];
|
||||
return Matchers.Any(m => m.IsMatch(headerValue));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user