I cant seem to find out why I am getting this error as the actual
and expected
are returning the same values at index 0 and have exactly the same properties. what could be the possible cause of this problem? I've looked around but cant find any viable solution as of yet.
[TestMethod()]
public void unSortedLeadsTest()
{
List<CustomerLead> expected = new List<CustomerLead>();
List<CustomerLead> actual = new List<CustomerLead>();
CustomerLeads target = new CustomerLeads(); // TODO: Initialize to an appropriate value
string xml = "C:/Users/Admin/Downloads/potentialcustomers.xml"; // TODO: Initialize to an appropriate value
actual = target.unSortedLeads(xml);
CustomerLead lead = new CustomerLead()
{
FirstName = actual[0].FirstName,
LastName=actual[0].LastName,
EmailAddress=actual[0].EmailAddress
};
CustomerLead lead1 = new CustomerLead()
{
FirstName = actual[1].FirstName,
LastName = actual[1].LastName,
EmailAddress = actual[1].EmailAddress
};
CustomerLead lead2 = new CustomerLead()
{
FirstName = actual[2].FirstName,
LastName = actual[2].LastName,
EmailAddress = actual[2].EmailAddress
};
target.addressList.Add(lead);
target.addressList.Add(lead1);
target.addressList.Add(lead2);
foreach (CustomerLead i in target.addressList) {
expected.Add(lead);
}
// TODO: Initialize to an appropriate value
CollectionAssert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
Edit: Ive attempted to override Equals but am struggling: any Ideas how I might acheive this?
public override bool Equals(Object obj)
{
if (obj == null)
return false;
CustomerLead leadsequal = obj as CustomerLead;
if ((Object)leadsequal == null)
return false;
else
return Equals( leadsequal);
}
I suspect that this:
foreach (CustomerLead i in target.addressList) {
expected.Add(lead);
}
should be:
foreach (CustomerLead i in target.addressList) {
expected.Add(i);
}
Otherwise you're adding the same reference three times.
It's not really clear to me what you're trying to test, mind you... and you may well be fine with just:
List<CustomerLead> expected = target.addressList.ToList();
... along with a using
directive of:
using System.Linq;
EDIT: Additionally, for two objects to be considered equal just because they've got the same properties, you'll need to override object.Equals(object)
and ideally implement IEquatable<CustomerLead>
too. By default, you just get reference equality - any two distinct objects are considered non-equal, even if every property is equal.
See more on this question at Stackoverflow