Summary

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

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
GetMatchingScore(...)0010
IsMatch(...)000.8890.667
.ctor(...)0010
.ctor(...)0010
.ctor(...)0010

File(s)

C:\Users\StefHeyenrath\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 matchers
 16        /// </summary>
 59317        public IReadOnlyList<IStringMatcher> 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="matchBehaviour">The match behaviour.</param>
 28        /// <param name="paths">The paths.</param>
 39229        public RequestMessagePathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] paths) : this(paths.Se
 19630        {
 19631        }
 32
 33        /// <summary>
 34        /// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
 35        /// </summary>
 36        /// <param name="matchers">The matchers.</param>
 26237        public RequestMessagePathMatcher([NotNull] params IStringMatcher[] matchers)
 26238        {
 26239            Check.NotNull(matchers, nameof(matchers));
 40
 26241            Matchers = matchers;
 26242        }
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
 46        /// </summary>
 47        /// <param name="funcs">The path functions.</param>
 148        public RequestMessagePathMatcher([NotNull] params Func<string, bool>[] funcs)
 149        {
 150            Check.NotNull(funcs, nameof(funcs));
 51
 152            Funcs = funcs;
 153        }
 54
 55        /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
 56        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 29657        {
 29658            double score = IsMatch(requestMessage);
 29659            return requestMatchResult.AddScore(GetType(), score);
 29660        }
 61
 62        private double IsMatch(RequestMessage requestMessage)
 29663        {
 29664            if (Matchers != null)
 29565            {
 59266                return Matchers.Max(m => m.IsMatch(requestMessage.Path));
 67            }
 68
 169            if (Funcs != null)
 170            {
 271                return MatchScores.ToScore(requestMessage.Path != null && Funcs.Any(func => func(requestMessage.Path)));
 72            }
 73
 074            return MatchScores.Mismatch;
 29675        }
 76    }
 77}