# Summary

Class: | WireMock.Matchers.JsonPathMatcher
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\JSONPathMatcher.cs
Covered lines: | 43
Uncovered lines: | 3
Coverable lines: | 46
Total lines: | 102
Line coverage: | 93.4%
Branch coverage: | 90%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
IsMatch(...) | 0 | 0 | 1 | 1
IsMatch(...) | 0 | 0 | 0.786 | 1
GetPatterns() | 0 | 0 | 1 | 0
IsMatch(...) | 0 | 0 | 1 | 0.5
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0

# File(s)

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System.Linq;`
|  | `2` |  | `using JetBrains.Annotations;`
|  | `3` |  | `using Newtonsoft.Json;`
|  | `4` |  | `using Newtonsoft.Json.Linq;`
|  | `5` |  | `using WireMock.Validation;`
|  | `6` |  | ``
|  | `7` |  | `namespace WireMock.Matchers`
|  | `8` |  | `{`
|  | `9` |  | `/// <summary>`
|  | `10` |  | `/// JsonPathMatcher`
|  | `11` |  | `/// </summary>`
|  | `12` |  | `/// <seealso cref="IMatcher" />`
|  | `13` |  | `/// <seealso cref="IObjectMatcher" />`
|  | `14` |  | `public class JsonPathMatcher : IStringMatcher, IObjectMatcher`
|  | `15` |  | `{`
|  | `16` |  | `private readonly string[] _patterns;`
|  | `17` |  | ``
|  | `18` |  | `/// <inheritdoc cref="IMatcher.MatchBehaviour"/>`
| 16 | `19` |  | `public MatchBehaviour MatchBehaviour { get; }`
|  | `20` |  | ``
|  | `21` |  | `/// <summary>`
|  | `22` |  | `/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.`
|  | `23` |  | `/// </summary>`
|  | `24` |  | `/// <param name="patterns">The patterns.</param>`
| 17 | `25` |  | `public JsonPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)`
| 17 | `26` |  | `{`
| 17 | `27` |  | `}`
|  | `28` |  | ``
|  | `29` |  | `/// <summary>`
|  | `30` |  | `/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.`
|  | `31` |  | `/// </summary>`
|  | `32` |  | `/// <param name="matchBehaviour">The match behaviour.</param>`
|  | `33` |  | `/// <param name="patterns">The patterns.</param>`
| 18 | `34` |  | `public JsonPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)`
| 18 | `35` |  | `{`
| 18 | `36` |  | `Check.NotNull(patterns, nameof(patterns));`
|  | `37` |  | ``
| 18 | `38` |  | `MatchBehaviour = matchBehaviour;`
| 18 | `39` |  | `_patterns = patterns;`
| 18 | `40` |  | `}`
|  | `41` |  | ``
|  | `42` |  | `/// <inheritdoc cref="IStringMatcher.IsMatch"/>`
|  | `43` |  | `public double IsMatch(string input)`
| 6 | `44` |  | `{`
| 6 | `45` |  | `double match = MatchScores.Mismatch;`
| 6 | `46` |  | `if (input != null)`
| 5 | `47` |  | `{`
|  | `48` |  | `try`
| 5 | `49` |  | `{`
| 5 | `50` |  | `var jtoken = JToken.Parse(input);`
| 3 | `51` |  | `match = IsMatch(jtoken);`
| 3 | `52` |  | `}`
| 2 | `53` |  | `catch (JsonException)`
| 2 | `54` |  | `{`
|  | `55` |  | `// just ignore JsonException`
| 2 | `56` |  | `}`
| 5 | `57` |  | `}`
|  | `58` |  | ``
| 6 | `59` |  | `return MatchBehaviourHelper.Convert(MatchBehaviour, match);`
| 6 | `60` |  | `}`
|  | `61` |  | ``
|  | `62` |  | `/// <inheritdoc cref="IObjectMatcher.IsMatch"/>`
|  | `63` |  | `public double IsMatch(object input)`
| 10 | `64` |  | `{`
| 10 | `65` |  | `double match = MatchScores.Mismatch;`
|  | `66` |  | ``
|  | `67` |  | `// When input is null or byte[], return Mismatch.`
| 10 | `68` |  | `if (input != null && !(input is byte[]))`
| 8 | `69` |  | `{`
|  | `70` |  | `try`
| 8 | `71` |  | `{`
|  | `72` |  | `// Check if JToken or object`
| 8 | `73` |  | `JToken jtoken = input is JToken token ? token : JObject.FromObject(input);`
| 8 | `74` |  | `match = IsMatch(jtoken);`
| 8 | `75` |  | `}`
| 0 | `76` |  | `catch (JsonException)`
| 0 | `77` |  | `{`
|  | `78` |  | `// just ignore JsonException`
| 0 | `79` |  | `}`
| 8 | `80` |  | `}`
|  | `81` |  | ``
| 10 | `82` |  | `return MatchBehaviourHelper.Convert(MatchBehaviour, match);`
| 10 | `83` |  | `}`
|  | `84` |  | ``
|  | `85` |  | `/// <inheritdoc cref="IStringMatcher.GetPatterns"/>`
|  | `86` |  | `public string[] GetPatterns()`
| 1 | `87` |  | `{`
| 1 | `88` |  | `return _patterns;`
| 1 | `89` |  | `}`
|  | `90` |  | ``
|  | `91` |  | `/// <inheritdoc cref="IMatcher.Name"/>`
| 1 | `92` |  | `public string Name => "JsonPathMatcher";`
|  | `93` |  | ``
|  | `94` |  | `private double IsMatch(JToken jtoken)`
| 11 | `95` |  | `{`
|  | `96` |  | `// Wrap in array if needed`
| 11 | `97` |  | `JToken tokenOrArray = jtoken is JArray ? jtoken : new JArray(jtoken);`
|  | `98` |  | ``
| 33 | `99` |  | `return MatchScores.ToScore(_patterns.Select(pattern => tokenOrArray.SelectToken(pattern) != null));`
| 11 | `100` |  | `}`
|  | `101` |  | `}`
|  | `102` |  | `}`

# Methods/Properties

MatchBehaviour()
.ctor(System.String[])
.ctor(WireMock.Matchers.MatchBehaviour,System.String[])
IsMatch(System.String)
IsMatch(System.Object)
GetPatterns()
Name()
IsMatch(Newtonsoft.Json.Linq.JToken)