Allan
asked on
Unit Test Comparing Results of List
Hi Experts!
Thanks for reading this.
For MS Test project how would you compare that the two List of SomeModel have the same contents?
In the Test Method we have this:
List<SomeModel> expected = CreateExpectedSomeModel();
List<SomeModel> actual;
//If this was an array would use SequenceEqual
Assert.IsTrue(expected.Seq uenceEqual (actual));
TIA!
Thanks for reading this.
For MS Test project how would you compare that the two List of SomeModel have the same contents?
In the Test Method we have this:
List<SomeModel> expected = CreateExpectedSomeModel();
List<SomeModel> actual;
//If this was an array would use SequenceEqual
Assert.IsTrue(expected.Seq
TIA!
Use the CollectionAssert class. You can use the AreEqual method to check for the same elements, in the same order; you can use the AreEquivalent method to check for the same elements, but in any order.
ASKER
Thanks kaufmed; I'll try it later .. I'm really heading out now ....
ASKER
Tried AreEqual and this came up:
CollectionAssert.AreEqual failed. (Element at index 0 do not match.
Tried AreEquivalent failed and this came up:
CollectionAssert.AreEquiva lent failed. The expected collection contains 1 occurrence(s) of <Blah.DomainClasses.SomeMo del>. The actual collection contains 0 occurrence(s).
Manually inspected the contents of expected and actual (setting breakpoint) and the contents are the same.
Dumped contents of expected and actual to separate db tables and the contents are the same.
If it's any help here are the contents from the Intermediate windows during debugging:
Any ideas?
CollectionAssert.AreEqual failed. (Element at index 0 do not match.
Tried AreEquivalent failed and this came up:
CollectionAssert.AreEquiva
Manually inspected the contents of expected and actual (setting breakpoint) and the contents are the same.
Dumped contents of expected and actual to separate db tables and the contents are the same.
If it's any help here are the contents from the Intermediate windows during debugging:
?actual[0]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "0002-0800"
SDATE: "19990201"
?expected[0]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "0002-0800"
SDATE: "19990201"
?actual[1]
{Blah.DomainClasses.SomeModel}
_Edate: "20221231"
EDATE: "20221231"
NEKEY: "52533-001"
SDATE: "20100802"
?expected[1]
{Blah.DomainClasses.SomeModel}
_Edate: "20221231"
EDATE: "20221231"
NEKEY: "52533-001"
SDATE: "20100802"
?actual[2]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "24488-003"
SDATE: "20110523"
?expected[2]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "24488-003"
SDATE: "20110523"
?actual[3]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "24488-005"
SDATE: "20100406"
?expected[3]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "24488-005"
SDATE: "20100406"
?actual[4]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "54365-400"
SDATE: "20000714"
?expected[4]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "54365-400"
SDATE: "20000714"
?actual[5]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "52533-024"
SDATE: "20110726"
?expected[5]
{Blah.DomainClasses.SomeModel}
_Edate: "20781231"
EDATE: "20781231"
NEKEY: "52533-024"
SDATE: "20110726"
?actual[6]
{Blah.DomainClasses.SomeModel}
_Edate: "20170601"
EDATE: "20170601"
NEKEY: "0002-1200"
SDATE: "20120601"
?expected[6]
{Blah.DomainClasses.SomeModel}
_Edate: "20170601"
EDATE: "20170601"
NEKEY: "0002-1200"
SDATE: "20120601"
Any ideas?
ASKER
Even if we do this:
List<SomeModel> expected = CreateExpectedSomeModel();
List<SomeModel> actual = CreateExpectedSomeModel();
And try to compare with either:
CollectionAssert.AreEquiva lent(expec ted, actual);
CollectionAssert.AreEqual( expected, actual);
we still get the same errors.
List<SomeModel> expected = CreateExpectedSomeModel();
List<SomeModel> actual = CreateExpectedSomeModel();
And try to compare with either:
CollectionAssert.AreEquiva
CollectionAssert.AreEqual(
we still get the same errors.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks kaufmed; I'll try it when i get in..
ASKER
Thanks again kaufmed; really appreciate your help!!!!