mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-08-25 12:53:59 +02:00
Fix FormUrlEncodedMatcher (+ refactor values / matchers logic) (#1503)
* Fix FormUrlEncodedMatcher * tests * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix comments --------- Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Copilot Autofix powered by AI
parent
2b165eb6a1
commit
ee0f890795
@@ -46,7 +46,7 @@ public interface IBodyData
|
||||
/// <summary>
|
||||
/// The body as Form UrlEncoded dictionary.
|
||||
/// </summary>
|
||||
IDictionary<string, string>? BodyAsFormUrlEncoded { get; set; }
|
||||
IDictionary<string, WireMockList<string>>? BodyAsFormUrlEncoded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The detected body type (detection based on body content).
|
||||
|
||||
@@ -46,6 +46,98 @@ public class WireMockList<T> : List<T>
|
||||
/// <param name="values">The values to set.</param>
|
||||
public static implicit operator WireMockList<T>(T[] values) => new(values);
|
||||
|
||||
/// <summary>
|
||||
/// Operator for equality comparison from WireMockList to T
|
||||
/// </summary>
|
||||
public static bool operator ==(WireMockList<T>? left, T? right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (left?.Count == 1 && Equals(left[0], right))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Operator for equality comparison from T to WireMockList
|
||||
/// </summary>
|
||||
public static bool operator ==(T? left, WireMockList<T>? right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (right?.Count == 1 && Equals(left, right[0]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Operator for inequality comparison from WireMockList to T
|
||||
/// </summary>
|
||||
public static bool operator !=(WireMockList<T>? left, T? right) => !(left == right);
|
||||
|
||||
/// <summary>
|
||||
/// Operator for inequality comparison from T to WireMockList
|
||||
/// </summary>
|
||||
public static bool operator !=(T? left, WireMockList<T>? right) => !(left == right);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified object is equal to the current instance.
|
||||
/// Two <see cref="WireMockList{T}"/> instances are equal if they contain the same elements in the same order.
|
||||
/// </summary>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (ReferenceEquals(this, obj))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj is WireMockList<T> other)
|
||||
{
|
||||
if (Count != other.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
if (!Equals(this[i], other[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash code for this instance based on its elements.
|
||||
/// </summary>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashCode = 17;
|
||||
foreach (var item in this)
|
||||
{
|
||||
hashCode = hashCode * 31 + (item?.GetHashCode() ?? 0);
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="string" /> that represents this instance.
|
||||
/// </summary>
|
||||
@@ -61,7 +153,7 @@ public class WireMockList<T> : List<T>
|
||||
{
|
||||
return strValue;
|
||||
}
|
||||
|
||||
|
||||
return this[0]?.ToString() ?? string.Empty;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user