using System;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using System.Text.RegularExpressions;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
{
///
/// The request url spec.
///
public class RequestUrlSpec : ISpecifyRequests
{
///
/// 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 RequestUrlSpec([NotNull, RegexPattern] string url)
{
Check.NotNull(url, nameof(url));
urlRegex = new Regex(url);
}
///
/// Initializes a new instance of the class.
///
///
/// The url func.
///
public RequestUrlSpec(Func func)
{
Check.NotNull(func, nameof(func));
urlFunc = func;
}
///
/// The is satisfied by.
///
///
/// The request.
///
///
/// The .
///
public bool IsSatisfiedBy(RequestMessage requestMessage)
{
return urlRegex?.IsMatch(requestMessage.Url) ?? urlFunc(requestMessage.Url);
}
}
}