Summary

Class:WireMock.Matchers.Request.RequestMessageCookieMatcher
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageCookieMatcher.cs
Covered lines:36
Uncovered lines:6
Coverable lines:42
Total lines:102
Line coverage:85.7%
Branch coverage:62.5%

Metrics

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

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageCookieMatcher.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 cookie matcher.
 11    /// </summary>
 12    public class RequestMessageCookieMatcher : IRequestMatcher
 13    {
 14        /// <value>
 15        /// The funcs.
 16        /// </value>
 417        public Func<IDictionary<string, string>, bool>[] Funcs { get; }
 18
 19        /// <summary>
 20        /// The name
 21        /// </summary>
 422        public string Name { get; }
 23
 24        /// <value>
 25        /// The matchers.
 26        /// </value>
 427        public IStringMatcher[] Matchers { get; }
 28
 29        /// <summary>
 30        /// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class.
 31        /// </summary>
 32        /// <param name="name">The name.</param>
 33        /// <param name="pattern">The pattern.</param>
 34        /// <param name="ignoreCase">The ignoreCase.</param>
 135        public RequestMessageCookieMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
 136        {
 137            Check.NotNull(name, nameof(name));
 138            Check.NotNull(pattern, nameof(pattern));
 39
 140            Name = name;
 141            Matchers = new IStringMatcher[] { new WildcardMatcher(pattern, ignoreCase) };
 142        }
 43
 44        /// <summary>
 45        /// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class.
 46        /// </summary>
 47        /// <param name="name">The name.</param>
 48        /// <param name="matchers">The matchers.</param>
 149        public RequestMessageCookieMatcher([NotNull] string name, [NotNull] params IStringMatcher[] matchers)
 150        {
 151            Check.NotNull(name, nameof(name));
 152            Check.NotNull(matchers, nameof(matchers));
 53
 154            Name = name;
 155            Matchers = matchers;
 156        }
 57
 58        /// <summary>
 59        /// Initializes a new instance of the <see cref="RequestMessageCookieMatcher"/> class.
 60        /// </summary>
 61        /// <param name="funcs">The funcs.</param>
 162        public RequestMessageCookieMatcher([NotNull] params Func<IDictionary<string, string>, bool>[] funcs)
 163        {
 164            Check.NotNull(funcs, nameof(funcs));
 65
 166            Funcs = funcs;
 167        }
 68
 69        /// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
 70        public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
 371        {
 372            double score = IsMatch(requestMessage);
 373            return requestMatchResult.AddScore(GetType(), score);
 374        }
 75
 76        private double IsMatch(RequestMessage requestMessage)
 377        {
 378             if (requestMessage.Cookies == null)
 079            {
 080                return MatchScores.Mismatch;
 81            }
 82
 383             if (Funcs != null)
 184            {
 285                return MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Cookies)));
 86            }
 87
 288             if (Matchers == null)
 089            {
 090                return MatchScores.Mismatch;
 91            }
 92
 293             if (!requestMessage.Cookies.ContainsKey(Name))
 094            {
 095                return MatchScores.Mismatch;
 96            }
 97
 298            string value = requestMessage.Cookies[Name];
 499            return Matchers.Max(m => m.IsMatch(value));
 3100        }
 101    }
 102}