using System; using System.Text.RegularExpressions; using JetBrains.Annotations; using WireMock.Validation; namespace WireMock.Matchers.Request { /// /// The request url matcher. /// public class RequestMessageUrlMatcher : IRequestMatcher { /// /// The urlRegex. /// private readonly Regex _urlRegex; /// /// The url function /// private readonly Func _urlFunc; /// /// Initializes a new instance of the class. /// /// /// The url Regex pattern. /// public RequestMessageUrlMatcher([NotNull, RegexPattern] string url) { Check.NotNull(url, nameof(url)); _urlRegex = new Regex(url); } /// /// Initializes a new instance of the class. /// /// /// The url func. /// public RequestMessageUrlMatcher(Func func) { Check.NotNull(func, nameof(func)); _urlFunc = func; } /// /// Determines whether the specified RequestMessage is match. /// /// The RequestMessage. /// /// true if the specified RequestMessage is match; otherwise, false. /// public bool IsMatch(RequestMessage requestMessage) { return _urlRegex?.IsMatch(requestMessage.Url) ?? _urlFunc(requestMessage.Url); } } }