Summary

Class:WireMock.Matchers.Request.RequestMessageCompositeMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageCompositeMatcher.cs
Covered lines:18
Uncovered lines:6
Coverable lines:24
Total lines:67
Line coverage:75%
Branch coverage:50%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
GetMatchingScore(...)6260.8766.67

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageCompositeMatcher.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using JetBrains.Annotations;
 4using WireMock.Validation;
 5
 6namespace 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>
 4821        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>
 5328        protected RequestMessageCompositeMatcher([NotNull] IEnumerable<IRequestMatcher> requestMatchers, CompositeMatche
 5329        {
 5330            Check.NotNull(requestMatchers, nameof(requestMatchers));
 31
 5332            _type = type;
 5333            RequestMatchers = requestMatchers;
 5334        }
 35
 36        /// <summary>
 37        /// Determines whether the specified RequestMessage is match.
 38        /// </summary>
 39        /// <param name="requestMessage">The RequestMessage.</param>
 40        /// <param name="requestMatchResult">The RequestMatchResult.</param>
 41        /// <returns>
 42        /// A value between 0.0 - 1.0 of the similarity.
 43        /// </returns>
 44        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 4845        {
 4846            var list = new List<double>();
 4847             if (_type == CompositeMatcherType.And)
 4848            {
 27449                foreach (var requestMatcher in RequestMatchers)
 6550                {
 6551                    double score = requestMatcher.GetMatchingScore(requestMessage, requestMatchResult);
 6552                    list.Add(score);
 6553                }
 54
 4855                return list.Sum() / list.Count;
 56            }
 57
 058            foreach (var requestMatcher in RequestMatchers)
 059            {
 060                double score = requestMatcher.GetMatchingScore(requestMessage, requestMatchResult);
 061                list.Add(score);
 062            }
 63
 064            return list.Max();
 4865        }
 66    }
 67}