I asked a question on here earlier and Laiv shared the following link.
In the article; it is stated that Eric Evans avoids .equals
methods on Entities.
In this question; the accepted answerer talks about using Custom Assertions for Unit Testing rather than .equals
Therefore I am looking at custom assertions. I have created the following class, which compares two products:
public static bool IsSameDescription(Product product1, Product product2)
{
// Check for null values and compare run-time types.
if (product1 == null || product2==null)
return false;
return (product1.description == product2.description);
}
Therefore I can do this in the Unit Test:
Assert.AreEqual(expectedProduct, actualProduct);
What is I wanted to compare two lists of products? I could use a .equals method and then do this:
CollectionAssert.AreEqual(expectedProductList, actualProductList);
How would I implement this? I could implement a static function that accepts two lists and compares them. However, CollectionAssert would not use it? Would it? (because it uses .equals behind the scenes) How can I do this?
Assert.isTrue()
? For instanceAssert.isTrue(IsSameDescription(productA, productB))
– Laiv Aug 17 '17 at 14:04