More fixes for #106

This commit is contained in:
Stef Heyenrath
2018-03-11 12:18:27 +01:00
parent ff012be173
commit 83d71bb24e
5 changed files with 67 additions and 7 deletions

View File

@@ -27,6 +27,14 @@ namespace WireMock.Matchers.Request
/// </summary>
public IEnumerable<string> Values { get; }
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary>
/// <param name="key">The key.</param>
public RequestMessageParamMatcher([NotNull] string key) : this(key, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary>
@@ -66,13 +74,19 @@ namespace WireMock.Matchers.Request
}
var values = requestMessage.GetParameter(Key);
if (values == null && !Values.Any())
if (values == null)
{
// Key is present, but no values, just return match
// Key is not present, just return Mismatch
return MatchScores.Mismatch;
}
if (values.Count == 0 && (Values == null || !Values.Any()))
{
// Key is present, but no values or null, just return Perfect
return MatchScores.Perfect;
}
var matches = Values.Select(v => values != null && values.Contains(v));
var matches = Values.Select(v => values.Contains(v));
return MatchScores.ToScore(matches);
}
}