using System; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using WireMock.Util; using WireMock.Validation; namespace WireMock.Matchers.Request { /// /// The request parameters matcher. /// public class RequestMessageParamMatcher : IRequestMatcher { private readonly Func>, bool>[] _funcs; /// /// The key /// public string Key { get; } /// /// The values /// public IEnumerable Values { get; } /// /// Initializes a new instance of the class. /// /// /// The key. /// /// /// The values. /// public RequestMessageParamMatcher([NotNull] string key, [NotNull] IEnumerable values) { Check.NotNull(key, nameof(key)); Check.NotNull(values, nameof(values)); Key = key; Values = values; } /// /// Initializes a new instance of the class. /// /// The funcs. public RequestMessageParamMatcher([NotNull] params Func>, bool>[] funcs) { Check.NotNull(funcs, nameof(funcs)); _funcs = 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 (_funcs != null) return _funcs.Any(f => f(requestMessage.Query)); var values = requestMessage.GetParameter(Key); return values?.Intersect(Values).Count() == Values.Count(); } } }