-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
208 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/WireMock/Matchers/Request/RequestMessageCookieMatcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using WireMock.Validation; | ||
|
||
namespace WireMock.Matchers.Request | ||
{ | ||
/// <summary> | ||
/// The request cookie matcher. | ||
/// </summary> | ||
public class RequestMessageCookieMatcher : IRequestMatcher | ||
{ | ||
private readonly string _name; | ||
|
||
private readonly IMatcher _matcher; | ||
|
||
private readonly Func<IDictionary<string, string>, bool> _cookieFunc; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class. | ||
/// </summary> | ||
/// <param name="name">The name.</param> | ||
/// <param name="pattern">The pattern.</param> | ||
/// <param name="ignoreCase">The ignoreCase.</param> | ||
public RequestMessageCookieMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true) | ||
{ | ||
Check.NotNull(name, nameof(name)); | ||
Check.NotNull(pattern, nameof(pattern)); | ||
|
||
_name = name; | ||
_matcher = new WildcardMatcher(pattern, ignoreCase); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class. | ||
/// </summary> | ||
/// <param name="func"> | ||
/// The func. | ||
/// </param> | ||
public RequestMessageCookieMatcher([NotNull] Func<IDictionary<string, string>, bool> func) | ||
{ | ||
Check.NotNull(func, nameof(func)); | ||
_cookieFunc = func; | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether the specified RequestMessage is match. | ||
/// </summary> | ||
/// <param name="requestMessage">The RequestMessage.</param> | ||
/// <returns> | ||
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>. | ||
/// </returns> | ||
public bool IsMatch(RequestMessage requestMessage) | ||
{ | ||
if (_cookieFunc != null) | ||
return _cookieFunc(requestMessage.Cookies); | ||
|
||
if (requestMessage.Cookies == null) | ||
return false; | ||
|
||
string headerValue = requestMessage.Cookies[_name]; | ||
return _matcher.IsMatch(headerValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/WireMock/RequestBuilders/IHeadersAndCookiesRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using WireMock.Matchers.Request; | ||
|
||
namespace WireMock.RequestBuilders | ||
{ | ||
/// <summary> | ||
/// The HeadersAndCookieRequestBuilder interface. | ||
/// </summary> | ||
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder | ||
{ | ||
/// <summary> | ||
/// The with header. | ||
/// </summary> | ||
/// <param name="name">The name.</param> | ||
/// <param name="pattern">The pattern.</param> | ||
/// <param name="ignoreCase">ignore Case</param> | ||
/// <returns>The <see cref="IHeadersAndCookiesRequestBuilder"/>.</returns> | ||
IHeadersAndCookiesRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true); | ||
|
||
/// <summary> | ||
/// The with header. | ||
/// </summary> | ||
/// <param name="func">The headers func.</param> | ||
/// <returns>The <see cref="IHeadersAndCookiesRequestBuilder"/>.</returns> | ||
IHeadersAndCookiesRequestBuilder WithHeader([NotNull] params Func<IDictionary<string, string>, bool>[] func); | ||
|
||
/// <summary> | ||
/// The with header. | ||
/// </summary> | ||
/// <param name="name">The name.</param> | ||
/// <param name="pattern">The pattern.</param> | ||
/// <param name="ignoreCase">ignore Case</param> | ||
/// <returns>The <see cref="IHeadersAndCookiesRequestBuilder"/>.</returns> | ||
IHeadersAndCookiesRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true); | ||
|
||
/// <summary> | ||
/// The with header. | ||
/// </summary> | ||
/// <param name="cookieFunc">The func.</param> | ||
/// <returns>The <see cref="IHeadersAndCookiesRequestBuilder"/>.</returns> | ||
IHeadersAndCookiesRequestBuilder WithCookie([NotNull] params Func<IDictionary<string, string>, bool>[] cookieFunc); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.