Summary

Class:WireMock.Matchers.XPathMatcher
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\XPathMatcher.cs
Covered lines:17
Uncovered lines:5
Coverable lines:22
Total lines:66
Line coverage:77.2%
Branch coverage:50%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
IsMatch(...)2254.5566.67
GetPatterns()10100100
GetName()10100100

File(s)

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

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Xml;
 4using JetBrains.Annotations;
 5using WireMock.Validation;
 6#if !NETSTANDARD1_3
 7using Wmhelp.XPath2;
 8#endif
 9
 10namespace WireMock.Matchers
 11{
 12    /// <summary>
 13    /// XPath2Matcher
 14    /// </summary>
 15    /// <seealso cref="IStringMatcher" />
 16    public class XPathMatcher : IStringMatcher
 17    {
 18        private readonly string[] _patterns;
 19
 20        /// <summary>
 21        /// Initializes a new instance of the <see cref="XPathMatcher"/> class.
 22        /// </summary>
 23        /// <param name="patterns">The patterns.</param>
 424        public XPathMatcher([NotNull] params string[] patterns)
 425        {
 426            Check.NotNull(patterns, nameof(patterns));
 27
 428            _patterns = patterns;
 429        }
 30
 31        /// <inheritdoc cref="IStringMatcher.IsMatch"/>
 32        public double IsMatch(string input)
 233        {
 234             if (input == null)
 035            {
 036                return MatchScores.Mismatch;
 37            }
 38
 39            try
 240            {
 241                var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
 42#if NETSTANDARD1_3
 43                return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
 44#else
 645                return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
 46#endif
 47            }
 048            catch (Exception)
 049            {
 050                return MatchScores.Mismatch;
 51            }
 252        }
 53
 54        /// <inheritdoc cref="IStringMatcher.GetPatterns"/>
 55        public string[] GetPatterns()
 156        {
 157            return _patterns;
 158        }
 59
 60        /// <inheritdoc cref="IMatcher.GetName"/>
 61        public string GetName()
 162        {
 163            return "XPathMatcher";
 164        }
 65    }
 66}