using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Validation;
namespace WireMock.Matchers.Request
{
///
/// The request url matcher.
///
public class RequestMessageUrlMatcher : IRequestMatcher
{
///
/// The matcher.
///
public readonly IReadOnlyList Matchers;
///
/// The url functions
///
private readonly Func[] _urlFuncs;
///
/// Initializes a new instance of the class.
///
/// The urls.
public RequestMessageUrlMatcher([NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(url)).ToArray())
{
}
///
/// Initializes a new instance of the class.
///
/// The matchers.
public RequestMessageUrlMatcher([NotNull] params IMatcher[] matchers)
{
Check.NotNull(matchers, nameof(matchers));
Matchers = matchers;
}
///
/// Initializes a new instance of the class.
///
/// The url functions.
public RequestMessageUrlMatcher([NotNull] params Func[] funcs)
{
Check.NotNull(funcs, nameof(funcs));
_urlFuncs = funcs;
}
///
/// Determines whether the specified RequestMessage is match.
///
/// The RequestMessage.
///
/// true if the specified RequestMessage is match; otherwise, false.
///
public bool IsMatch(RequestMessage requestMessage)
{
if (Matchers != null)
return Matchers.Any(matcher => matcher.IsMatch(requestMessage.Path));
if (_urlFuncs != null)
return _urlFuncs.Any(func => func(requestMessage.Url));
return false;
}
}
}