PartialMapping : SimMetrics.Net

This commit is contained in:
Stef Heyenrath
2017-02-04 21:32:45 +01:00
parent ec2d105db2
commit 44f00cb9fa
22 changed files with 349 additions and 176 deletions

View File

@@ -8,7 +8,7 @@ namespace WireMock.Matchers
/// <summary>
/// JSONPathMatcher
/// </summary>
/// <seealso cref="WireMock.Matchers.IMatcher" />
/// <seealso cref="IMatcher" />
public class JsonPathMatcher : IMatcher
{
private readonly string _pattern;
@@ -27,25 +27,23 @@ namespace WireMock.Matchers
/// <summary>
/// Determines whether the specified input is match.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>
/// <c>true</c> if the specified input is match; otherwise, <c>false</c>.
/// </returns>
public bool IsMatch(string input)
/// <param name="input">The input string</param>
/// <returns>A value between 0.0 - 1.0 of the similarity.</returns>
public double IsMatch(string input)
{
if (input == null)
return false;
return MatchScores.Mismatch;
try
{
JObject o = JObject.Parse(input);
JToken token = o.SelectToken(_pattern);
return token != null;
return MatchScores.ToScore(token != null);
}
catch (Exception)
{
return false;
return MatchScores.Mismatch;
}
}
@@ -57,5 +55,14 @@ namespace WireMock.Matchers
{
return _pattern;
}
/// <summary>
/// Gets the name.
/// </summary>
/// <returns>Name</returns>
public string GetName()
{
return "JsonPathMatcher";
}
}
}