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:76
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;
 6#if NET45
 7using Wmhelp.XPath2;
 8#endif
 9
 10namespace WireMock.Matchers
 11{
 12    /// <summary>
 13    /// XPath2Matcher
 14    /// </summary>
 15    /// <seealso cref="WireMock.Matchers.IMatcher" />
 16    public class XPathMatcher : IMatcher
 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>
 224        public XPathMatcher([NotNull] params string[] patterns)
 225        {
 226            Check.NotNull(patterns, nameof(patterns));
 27
 228            _patterns = patterns;
 229        }
 30
 31        /// <summary>
 32        /// Determines whether the specified input is match.
 33        /// </summary>
 34        /// <param name="input">The input string</param>
 35        /// <returns>A value between 0.0 - 1.0 of the similarity.</returns>
 36        public double IsMatch(string input)
 237        {
 238             if (input == null)
 039                return MatchScores.Mismatch;
 40
 41            try
 242            {
 243                var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
 44#if NET45
 445                return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
 46#else
 47                return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
 48#endif
 49            }
 050            catch (Exception)
 051            {
 052                return MatchScores.Mismatch;
 53            }
 254        }
 55
 56        /// <summary>
 57        /// Gets the patterns.
 58        /// </summary>
 59        /// <returns>Patterns</returns>
 60        public string[] GetPatterns()
 061        {
 062            return _patterns;
 063        }
 64
 65        /// <summary>
 66        /// Gets the name.
 67        /// </summary>
 68        /// <returns>
 69        /// Name
 70        /// </returns>
 71        public string GetName()
 072        {
 073            return "XPathMatcher";
 074        }
 75    }
 76}