nunit-core team mailing list archive
-
nunit-core team
-
Mailing list archive
-
Message #01963
[Bug 709062] Re: "System.ArgumentException : Cannot compare" when the element is a list
** Changed in: nunitv2
Assignee: (unassigned) => Charlie Poole (charlie.poole)
** Changed in: nunitv2
Status: Triaged => In Progress
--
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/709062
Title:
"System.ArgumentException : Cannot compare" when the element is a list
Status in NUnit V2 Test Framework:
In Progress
Bug description:
Relevant discussion can be found here.
https://groups.google.com/forum/?pli=1#!topic/nunit-
discuss/IgGiVyo3fKw
This code throws me a System.ArgumentException : Cannot compare 2 exception.
public class IntListEqualComparer: IEqualityComparer<List<int>>
{
public bool Equals(List<int> x, List<int> y)
{
return x.Count == y.Count;
}
public int GetHashCode(List<int> obj)
{
return obj.Count.GetHashCode();
}
}
[Test]
public void IntListListTest()
{
var list1 = new List<int>() {2, 3};
var list2 = new List<int>() {2, 3};
var list11 = new List<List<int>>() {list1};
var list22 = new List<List<int>>() { list2 };
var comparer = new IntListEqualComparer();
Assert.That(list11, new CollectionEquivalentConstraint(list22).Using(comparer));
}
It seems that Nunit can't compare if the elements are of the type
List?
Here's the complete stack trace:
failed: System.ArgumentException : Cannot compare 2
at NUnit.Framework.Constraints.EqualityAdapter.EqualityComparerAdapter`1.ObjectsEqual(Object x, Object y)
at NUnit.Framework.Constraints.NUnitEqualityComparer.ObjectsEqual(Object x, Object y)
at NUnit.Framework.Constraints.NUnitEqualityComparer.CollectionsEqual(ICollection x, ICollection y)
at NUnit.Framework.Constraints.NUnitEqualityComparer.ObjectsEqual(Object x, Object y)
at NUnit.Framework.Constraints.CollectionItemsEqualConstraint.CollectionTally.ItemsEqual(Object expected, Object actual)
at NUnit.Framework.Constraints.CollectionItemsEqualConstraint.CollectionTally.TryRemove(Object o)
at NUnit.Framework.Constraints.CollectionItemsEqualConstraint.CollectionTally.TryRemove(IEnumerable c)
at NUnit.Framework.Constraints.CollectionEquivalentConstraint.doMatch(IEnumerable actual)
at NUnit.Framework.Constraints.CollectionConstraint.Matches(Object actual)
To manage notifications about this bug go to:
https://bugs.launchpad.net/nunitv2/+bug/709062/+subscriptions
References