Summary

Class:WireMock.Matchers.Request.RequestMessageParamMatcher
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageParamMatcher.cs
Covered lines:35
Uncovered lines:0
Coverable lines:35
Total lines:93
Line coverage:100%
Branch coverage:100%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
.ctor(...)10100100
.ctor(...)10100100
GetMatchingScore(...)10100100
IsMatch(...)88100100

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageParamMatcher.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using JetBrains.Annotations;
 5using WireMock.Util;
 6using WireMock.Validation;
 7
 8namespace WireMock.Matchers.Request
 9{
 10    /// <summary>
 11    /// The request parameters matcher.
 12    /// </summary>
 13    public class RequestMessageParamMatcher : IRequestMatcher
 14    {
 15        /// <summary>
 16        /// The funcs
 17        /// </summary>
 918        public Func<IDictionary<string, WireMockList<string>>, bool>[] Funcs { get; }
 19
 20        /// <summary>
 21        /// The key
 22        /// </summary>
 723        public string Key { get; }
 24
 25        /// <summary>
 26        /// The values
 27        /// </summary>
 928        public IEnumerable<string> Values { get; }
 29
 30        /// <summary>
 31        /// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
 32        /// </summary>
 33        /// <param name="key">The key.</param>
 134        public RequestMessageParamMatcher([NotNull] string key) : this(key, null)
 135        {
 136        }
 37
 38        /// <summary>
 39        /// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
 40        /// </summary>
 41        /// <param name="key">The key.</param>
 42        /// <param name="values">The values.</param>
 743        public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable<string> values)
 744        {
 745            Check.NotNull(key, nameof(key));
 46
 747            Key = key;
 748            Values = values;
 749        }
 50
 51        /// <summary>
 52        /// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
 53        /// </summary>
 54        /// <param name="funcs">The funcs.</param>
 155        public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs
 156        {
 157            Check.NotNull(funcs, nameof(funcs));
 58
 159            Funcs = funcs;
 160        }
 61
 62        /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
 63        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 864        {
 865            double score = IsMatch(requestMessage);
 866            return requestMatchResult.AddScore(GetType(), score);
 867        }
 68
 69        private double IsMatch(RequestMessage requestMessage)
 870        {
 871             if (Funcs != null)
 172            {
 273                return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
 74            }
 75
 776            var values = requestMessage.GetParameter(Key);
 777             if (values == null)
 178            {
 79                // Key is not present, just return Mismatch
 180                return MatchScores.Mismatch;
 81            }
 82
 683             if (values.Count == 0 && (Values == null || !Values.Any()))
 284            {
 85                // Key is present, but no values or null, just return Perfect
 286                return MatchScores.Perfect;
 87            }
 88
 1689            var matches = Values.Select(v => values.Contains(v));
 490            return MatchScores.ToScore(matches);
 891        }
 92    }
 93}