using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using WireMock.Validation; namespace WireMock.Matchers.Request { /// /// The composite request matcher. /// public abstract class RequestMessageCompositeMatcher : IRequestMatcher { private readonly CompositeMatcherType _type; /// /// Gets the request matchers. /// /// /// The request matchers. /// private IEnumerable RequestMatchers { get; } /// /// Initializes a new instance of the class. /// /// The request matchers. /// The CompositeMatcherType type (Defaults to 'And') protected RequestMessageCompositeMatcher([NotNull] IEnumerable requestMatchers, CompositeMatcherType type = CompositeMatcherType.And) { Check.NotNull(requestMatchers, nameof(requestMatchers)); _type = type; RequestMatchers = requestMatchers; } /// public double GetMatchingScore(IRequestMessage requestMessage, RequestMatchResult requestMatchResult) { if (!RequestMatchers.Any()) { return MatchScores.Mismatch; } if (_type == CompositeMatcherType.And) { return RequestMatchers.Average(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, requestMatchResult)); } return RequestMatchers.Max(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, requestMatchResult)); } } }