using System.Collections.Generic; using System.Linq; using Stef.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(IEnumerable requestMatchers, CompositeMatcherType type = CompositeMatcherType.And) { Guard.NotNull(requestMatchers); _type = type; RequestMatchers = requestMatchers; } /// public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult 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)); } }