Summary

Class:WireMock.Matchers.Request.RequestMessageClientIPMatcher
Assembly:WireMock.Net
File(s):C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageClientIPMatcher.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\RequestMessageClientIPMatcher.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 ClientIP matcher.
 11    /// </summary>
 12    public class RequestMessageClientIPMatcher : IRequestMatcher
 13    {
 14        /// <summary>
 15        /// The matchers.
 16        /// </summary>
 717        public IReadOnlyList<IStringMatcher> Matchers { get; }
 18
 19        /// <summary>
 20        /// The ClientIP functions.
 21        /// </summary>
 222        public Func<string, bool>[] Funcs { get; }
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
 26        /// </summary>
 27        /// <param name="clientIPs">The clientIPs.</param>
 28        /// <param name="matchBehaviour">The match behaviour.</param>
 529        public RequestMessageClientIPMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] clientIPs) : this(
 230        {
 231        }
 32
 33        /// <summary>
 34        /// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
 35        /// </summary>
 36        /// <param name="matchers">The matchers.</param>
 337        public RequestMessageClientIPMatcher([NotNull] params IStringMatcher[] matchers)
 338        {
 339            Check.NotNull(matchers, nameof(matchers));
 340            Matchers = matchers;
 341        }
 42
 43        /// <summary>
 44        /// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
 45        /// </summary>
 46        /// <param name="funcs">The clientIP functions.</param>
 147        public RequestMessageClientIPMatcher([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)
 455        {
 456            double score = IsMatch(requestMessage);
 457            return requestMatchResult.AddScore(GetType(), score);
 458        }
 59
 60        private double IsMatch(RequestMessage requestMessage)
 461        {
 462            if (Matchers != null)
 363            {
 764                return Matchers.Max(matcher => matcher.IsMatch(requestMessage.ClientIP));
 65            }
 66
 167            if (Funcs != null)
 168            {
 269                return MatchScores.ToScore(requestMessage.ClientIP != null && Funcs.Any(func => func(requestMessage.Clie
 70            }
 71
 072            return MatchScores.Mismatch;
 473        }
 74    }
 75}