You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to test collections for equality using a predicate that compares items fails with an exception.
The following example tests:
[Test]
public void UsesProvidedPredicateForItemComparison()
{
var expected = new[] { "yeti", "łysy", "rysiu" };
var actual = new[] { "YETI", "Łysy", "RySiU" };
Assert.That(actual, Is.EqualTo(expected).Using<string>((x, y) => StringUtil.StringsEqual(x, y, true)));
}
[Test]
public void UsesProvidedPredicateForItemComparisonDifferentTypes()
{
var expected = new[] { 1, 2, 3 };
var actual = new[] { "1", "2", "3" };
Assert.That(actual, Is.EqualTo(expected).Using<string, int>((s, i) => i.ToString() == s));
}
both throw an exception:
System.InvalidCastException : Unable to cast object of type 'System.String[]' to type 'System.String'.
w NUnit.Framework.Constraints.EqualityAdapter.PredicateEqualityAdapter`2.AreEqual(Object x, Object y)
w NUnit.Framework.Constraints.NUnitEqualityComparer.AreEqual(Object x, Object y, Tolerance& tolerance, Boolean topLevelComparison)
w NUnit.Framework.Constraints.EqualConstraint.ApplyTo[TActual](TActual actual)
w NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, String message, Object[] args)
w NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression)
Similar comparisons performed using a dedicated IComparer or IEqualityComparer pass correctly.
The text was updated successfully, but these errors were encountered:
Attempting to test collections for equality using a predicate that compares items fails with an exception.
The following example tests:
both throw an exception:
System.InvalidCastException : Unable to cast object of type 'System.String[]' to type 'System.String'.
w NUnit.Framework.Constraints.EqualityAdapter.PredicateEqualityAdapter`2.AreEqual(Object x, Object y)
w NUnit.Framework.Constraints.NUnitEqualityComparer.AreEqual(Object x, Object y, Tolerance& tolerance, Boolean topLevelComparison)
w NUnit.Framework.Constraints.EqualConstraint.ApplyTo[TActual](TActual actual)
w NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, String message, Object[] args)
w NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression)
Similar comparisons performed using a dedicated IComparer or IEqualityComparer pass correctly.
The text was updated successfully, but these errors were encountered: