Summary

Class:WireMock.Matchers.JsonPathMatcher
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Matchers\JSONPathMatcher.cs
Covered lines:11
Uncovered lines:10
Coverable lines:21
Total lines:68
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\JSONPathMatcher.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using JetBrains.Annotations;
 4using Newtonsoft.Json.Linq;
 5using WireMock.Validation;
 6
 7namespace WireMock.Matchers
 8{
 9    /// <summary>
 10    /// JSONPathMatcher
 11    /// </summary>
 12    /// <seealso cref="IMatcher" />
 13    public class JsonPathMatcher : IMatcher
 14    {
 15        private readonly string[] _patterns;
 16
 17        /// <summary>
 18        /// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
 19        /// </summary>
 20        /// <param name="patterns">The patterns.</param>
 221        public JsonPathMatcher([NotNull] params string[] patterns)
 222        {
 223            Check.NotNull(patterns, nameof(patterns));
 24
 225            _patterns = patterns;
 226        }
 27
 28        /// <summary>
 29        /// Determines whether the specified input is match.
 30        /// </summary>
 31        /// <param name="input">The input string</param>
 32        /// <returns>A value between 0.0 - 1.0 of the similarity.</returns>
 33        public double IsMatch(string input)
 234        {
 235             if (input == null)
 036                return MatchScores.Mismatch;
 37
 38            try
 239            {
 240                JObject o = JObject.Parse(input);
 41
 442                return MatchScores.ToScore(_patterns.Select(p => o.SelectToken(p) != null));
 43            }
 044            catch (Exception)
 045            {
 046                return MatchScores.Mismatch;
 47            }
 248        }
 49
 50        /// <summary>
 51        /// Gets the patterns.
 52        /// </summary>
 53        /// <returns>Pattern</returns>
 54        public string[] GetPatterns()
 055        {
 056            return _patterns;
 057        }
 58
 59        /// <summary>
 60        /// Gets the name.
 61        /// </summary>
 62        /// <returns>Name</returns>
 63        public string GetName()
 064        {
 065            return "JsonPathMatcher";
 066        }
 67    }
 68}