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; } /// /// Determines whether the specified RequestMessage is match. /// /// The RequestMessage. /// The RequestMatchResult. /// /// A value between 0.0 - 1.0 of the similarity. /// public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) { if (_type == CompositeMatcherType.And) { return RequestMatchers.Average(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, requestMatchResult)); } return RequestMatchers.Max(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, requestMatchResult)); } } }