Summary

Class:WireMock.Matchers.XPathMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\XPathMatcher.cs
Covered lines:11
Uncovered lines:10
Coverable lines:21
Total lines:71
Line coverage:52.3%
Branch coverage:50%

Metrics

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

File(s)

C:\Users\Stef\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;
 6using Wmhelp.XPath2;
 7
 8namespace WireMock.Matchers
 9{
 10    /// <summary>
 11    /// XPath2Matcher
 12    /// </summary>
 13    /// <seealso cref="WireMock.Matchers.IMatcher" />
 14    public class XPathMatcher : IMatcher
 15    {
 16        private readonly string[] _patterns;
 17
 18        /// <summary>
 19        /// Initializes a new instance of the <see cref="XPathMatcher"/> class.
 20        /// </summary>
 21        /// <param name="patterns">The patterns.</param>
 222        public XPathMatcher([NotNull] params string[] patterns)
 223        {
 224            Check.NotNull(patterns, nameof(patterns));
 25
 226            _patterns = patterns;
 227        }
 28
 29        /// <summary>
 30        /// Determines whether the specified input is match.
 31        /// </summary>
 32        /// <param name="input">The input string</param>
 33        /// <returns>A value between 0.0 - 1.0 of the similarity.</returns>
 34        public double IsMatch(string input)
 235        {
 236             if (input == null)
 037                return MatchScores.Mismatch;
 38
 39            try
 240            {
 241                var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
 42
 443                return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
 44            }
 045            catch (Exception)
 046            {
 047                return MatchScores.Mismatch;
 48            }
 249        }
 50
 51        /// <summary>
 52        /// Gets the patterns.
 53        /// </summary>
 54        /// <returns>Patterns</returns>
 55        public string[] GetPatterns()
 056        {
 057            return _patterns;
 058        }
 59
 60        /// <summary>
 61        /// Gets the name.
 62        /// </summary>
 63        /// <returns>
 64        /// Name
 65        /// </returns>
 66        public string GetName()
 067        {
 068            return "XPathMatcher";
 069        }
 70    }
 71}