Summary

Class:WireMock.Matchers.Request.RequestMessageClientIPMatcher
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageClientIPMatcher.cs
Covered lines:27
Uncovered lines:1
Coverable lines:28
Total lines:74
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(...)4488.8980

File(s)

C:\Users\azureuser\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>
 528        public RequestMessageClientIPMatcher([NotNull] params string[] clientIPs) : this(clientIPs.Select(ip => new Wild
 229        {
 230        }
 31
 32        /// <summary>
 33        /// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
 34        /// </summary>
 35        /// <param name="matchers">The matchers.</param>
 336        public RequestMessageClientIPMatcher([NotNull] params IStringMatcher[] matchers)
 337        {
 338            Check.NotNull(matchers, nameof(matchers));
 339            Matchers = matchers;
 340        }
 41
 42        /// <summary>
 43        /// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
 44        /// </summary>
 45        /// <param name="funcs">The clientIP functions.</param>
 146        public RequestMessageClientIPMatcher([NotNull] params Func<string, bool>[] funcs)
 147        {
 148            Check.NotNull(funcs, nameof(funcs));
 149            Funcs = funcs;
 150        }
 51
 52        /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
 53        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 454        {
 455            double score = IsMatch(requestMessage);
 456            return requestMatchResult.AddScore(GetType(), score);
 457        }
 58
 59        private double IsMatch(RequestMessage requestMessage)
 460        {
 461             if (Matchers != null)
 362            {
 763                return Matchers.Max(matcher => matcher.IsMatch(requestMessage.ClientIP));
 64            }
 65
 166             if (Funcs != null)
 167            {
 268                return MatchScores.ToScore(requestMessage.ClientIP != null && Funcs.Any(func => func(requestMessage.Clie
 69            }
 70
 071            return MatchScores.Mismatch;
 472        }
 73    }
 74}