Summary

Class:WireMock.Matchers.Request.RequestMessagePathMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessagePathMatcher.cs
Covered lines:27
Uncovered lines:1
Coverable lines:28
Total lines:81
Line coverage:96.4%
Branch coverage:75%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)20100100
.ctor(...)10100100
.ctor(...)10100100
GetMatchingScore(...)10100100
IsMatch(...)4485.7180

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using JetBrains.Annotations;
 5using WireMock.Validation;
 6
 7namespace WireMock.Matchers.Request
 8{
 9    /// <summary>
 10    /// The request path matcher.
 11    /// </summary>
 12    public class RequestMessagePathMatcher : IRequestMatcher
 13    {
 14        /// <summary>
 15        /// The matcher.
 16        /// </summary>
 5317        public IReadOnlyList<IMatcher> Matchers { get; }
 18
 19        /// <summary>
 20        /// The path functions
 21        /// </summary>
 222        public Func<string, bool>[] Funcs { get; }
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
 26        /// </summary>
 27        /// <param name="paths">The paths.</param>
 5128        public RequestMessagePathMatcher([NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatche
 2529        {
 2530        }
 31
 32        /// <summary>
 33        /// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
 34        /// </summary>
 35        /// <param name="matchers">The matchers.</param>
 3136        public RequestMessagePathMatcher([NotNull] params IMatcher[] matchers)
 3137        {
 3138            Check.NotNull(matchers, nameof(matchers));
 3139            Matchers = matchers;
 3140        }
 41
 42        /// <summary>
 43        /// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
 44        /// </summary>
 45        /// <param name="funcs">The path functions.</param>
 146        public RequestMessagePathMatcher([NotNull] params Func<string, bool>[] funcs)
 147        {
 148            Check.NotNull(funcs, nameof(funcs));
 149            Funcs = funcs;
 150        }
 51
 52        /// <summary>
 53        /// Determines whether the specified RequestMessage is match.
 54        /// </summary>
 55        /// <param name="requestMessage">The RequestMessage.</param>
 56        /// <param name="requestMatchResult">The RequestMatchResult.</param>
 57        /// <returns>
 58        /// A value between 0.0 - 1.0 of the similarity.
 59        /// </returns>
 60        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 2761        {
 2762            double score = IsMatch(requestMessage);
 2763            requestMatchResult.TotalScore += score;
 64
 2765            requestMatchResult.TotalNumber++;
 66
 2767            return score;
 2768        }
 69
 70        private double IsMatch(RequestMessage requestMessage)
 2771        {
 2772             if (Matchers != null)
 5473                return Matchers.Max(m => m.IsMatch(requestMessage.Path));
 74
 175             if (Funcs != null)
 276                return MatchScores.ToScore(requestMessage.Path != null && Funcs.Any(func => func(requestMessage.Path)));
 77
 078            return MatchScores.Mismatch;
 2779        }
 80    }
 81}