mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-24 10:22:13 +01:00
More fixes for #106
This commit is contained in:
@@ -27,6 +27,14 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<string> Values { get; }
|
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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -66,13 +74,19 @@ namespace WireMock.Matchers.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
var values = requestMessage.GetParameter(Key);
|
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;
|
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);
|
return MatchScores.ToScore(matches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,19 @@ using WireMock.Util;
|
|||||||
namespace WireMock.RequestBuilders
|
namespace WireMock.RequestBuilders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ParametersRequestBuilder interface.
|
/// The ParamsRequestBuilder interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IParamsRequestBuilder
|
public interface IParamsRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with parameters.
|
/// WithParam (key only)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithParam([NotNull] string key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithParam (values)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
@@ -19,7 +26,7 @@ namespace WireMock.RequestBuilders
|
|||||||
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params string[] values);
|
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params string[] values);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with parameters.
|
/// WithParam (funcs)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="funcs">The funcs.</param>
|
/// <param name="funcs">The funcs.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
|||||||
@@ -291,6 +291,15 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string)"/>
|
||||||
|
public IRequestBuilder WithParam(string key)
|
||||||
|
{
|
||||||
|
Check.NotNull(key, nameof(key));
|
||||||
|
|
||||||
|
_requestMatchers.Add(new RequestMessageParamMatcher(key));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, string[])"/>
|
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, string[])"/>
|
||||||
public IRequestBuilder WithParam(string key, params string[] values)
|
public IRequestBuilder WithParam(string key, params string[] values)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ namespace WireMock
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
/// <returns>The query parameter.</returns>
|
/// <returns>The query parameter.</returns>
|
||||||
public List<string> GetParameter(string key)
|
public WireMockList<string> GetParameter(string key)
|
||||||
{
|
{
|
||||||
if (Query == null)
|
if (Query == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,5 +51,35 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
// Assert
|
// Assert
|
||||||
Check.That(score).IsEqualTo(0.0d);
|
Check.That(score).IsEqualTo(0.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresent_WithNull()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher("key");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresent_WithEmptyArray()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
|
||||||
|
var matcher = new RequestMessageParamMatcher("key", new string[] { });
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = new RequestMatchResult();
|
||||||
|
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(score).IsEqualTo(1.0d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user