Summary

Class:WireMock.Matchers.Request.RequestMessageUrlMatcher
Assembly:WireMock.Net
File(s):C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageUrlMatcher.cs
Covered lines:27
Uncovered lines:1
Coverable lines:28
Total lines:75
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\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 matchers.
 16        /// </summary>
 517        public IReadOnlyList<IStringMatcher> Matchers { get; }
 18
 19        /// <summary>
 20        /// The url functions.
 21        /// </summary>
 222        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="matchBehaviour">The match behaviour.</param>
 28        /// <param name="urls">The urls.</param>
 229        public RequestMessageUrlMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] urls) : this(urls.Selec
 130        {
 131        }
 32
 33        /// <summary>
 34        /// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
 35        /// </summary>
 36        /// <param name="matchers">The matchers.</param>
 237        public RequestMessageUrlMatcher([NotNull] params IStringMatcher[] matchers)
 238        {
 239            Check.NotNull(matchers, nameof(matchers));
 240            Matchers = matchers;
 241        }
 42
 43        /// <summary>
 44        /// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
 45        /// </summary>
 46        /// <param name="funcs">The url functions.</param>
 147        public RequestMessageUrlMatcher([NotNull] params Func<string, bool>[] funcs)
 148        {
 149            Check.NotNull(funcs, nameof(funcs));
 150            Funcs = funcs;
 151        }
 52
 53        /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
 54        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 355        {
 356            double score = IsMatch(requestMessage);
 357            return requestMatchResult.AddScore(GetType(), score);
 358        }
 59
 60        private double IsMatch(RequestMessage requestMessage)
 361        {
 362            if (Matchers != null)
 263            {
 464                return Matchers.Max(matcher => matcher.IsMatch(requestMessage.Url));
 65            }
 66
 167            if (Funcs != null)
 168            {
 269                return MatchScores.ToScore(requestMessage.Url != null && Funcs.Any(func => func(requestMessage.Url)));
 70            }
 71
 072            return MatchScores.Mismatch;
 373        }
 74    }
 75}