Summary

Class:WireMock.Matchers.Request.RequestMessageUrlMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageUrlMatcher.cs
Covered lines:19
Uncovered lines:9
Coverable lines:28
Total lines:81
Line coverage:67.8%
Branch coverage:25%

Metrics

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

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageUrlMatcher.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 url matcher.
 11    /// </summary>
 12    public class RequestMessageUrlMatcher : IRequestMatcher
 13    {
 14        /// <summary>
 15        /// The matcher.
 16        /// </summary>
 217        public IReadOnlyList<IMatcher> Matchers { get; }
 18
 19        /// <summary>
 20        /// The url functions
 21        /// </summary>
 022        public Func<string, bool>[] Funcs { get; }
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
 26        /// </summary>
 27        /// <param name="urls">The urls.</param>
 228        public RequestMessageUrlMatcher([NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(ur
 129        {
 130        }
 31
 32        /// <summary>
 33        /// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
 34        /// </summary>
 35        /// <param name="matchers">The matchers.</param>
 136        public RequestMessageUrlMatcher([NotNull] params IMatcher[] matchers)
 137        {
 138            Check.NotNull(matchers, nameof(matchers));
 139            Matchers = matchers;
 140        }
 41
 42        /// <summary>
 43        /// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
 44        /// </summary>
 45        /// <param name="funcs">The url functions.</param>
 046        public RequestMessageUrlMatcher([NotNull] params Func<string, bool>[] funcs)
 047        {
 048            Check.NotNull(funcs, nameof(funcs));
 049            Funcs = funcs;
 050        }
 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)
 161        {
 162            double score = IsMatch(requestMessage);
 163            requestMatchResult.TotalScore += score;
 64
 165            requestMatchResult.TotalNumber++;
 66
 167            return score;
 168        }
 69
 70        private double IsMatch(RequestMessage requestMessage)
 171        {
 172             if (Matchers != null)
 273                return Matchers.Max(matcher => matcher.IsMatch(requestMessage.Url));
 74
 075             if (Funcs != null)
 076                return MatchScores.ToScore(requestMessage.Url != null && Funcs.Any(func => func(requestMessage.Url)));
 77
 078            return MatchScores.Mismatch;
 179        }
 80    }
 81}