| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | using WireMock.Validation; |
| | | 5 | | |
| | | 6 | | namespace WireMock.Matchers.Request |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The composite request matcher. |
| | | 10 | | /// </summary> |
| | | 11 | | public abstract class RequestMessageCompositeMatcher : IRequestMatcher |
| | | 12 | | { |
| | | 13 | | private readonly CompositeMatcherType _type; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Gets the request matchers. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <value> |
| | | 19 | | /// The request matchers. |
| | | 20 | | /// </value> |
| | 657 | 21 | | private IEnumerable<IRequestMatcher> RequestMatchers { get; } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new instance of the <see cref="RequestMessageCompositeMatcher"/> class. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="requestMatchers">The request matchers.</param> |
| | | 27 | | /// <param name="type">The CompositeMatcherType type (Defaults to 'And')</param> |
| | 314 | 28 | | protected RequestMessageCompositeMatcher([NotNull] IEnumerable<IRequestMatcher> requestMatchers, CompositeMatche |
| | 314 | 29 | | { |
| | 314 | 30 | | Check.NotNull(requestMatchers, nameof(requestMatchers)); |
| | | 31 | | |
| | 315 | 32 | | _type = type; |
| | 315 | 33 | | RequestMatchers = requestMatchers; |
| | 315 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/> |
| | | 37 | | public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) |
| | 329 | 38 | | { |
| | 329 | 39 | | if (!RequestMatchers.Any()) |
| | 1 | 40 | | { |
| | 1 | 41 | | return MatchScores.Mismatch; |
| | | 42 | | } |
| | | 43 | | |
| | 328 | 44 | | if (_type == CompositeMatcherType.And) |
| | 327 | 45 | | { |
| | 978 | 46 | | return RequestMatchers.Average(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, request |
| | | 47 | | } |
| | | 48 | | |
| | 3 | 49 | | return RequestMatchers.Max(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, requestMatchRes |
| | 329 | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |