I'm trying to assert that one object is "equal" to another object.
The objects are just instances of a class with a bunch of public properties. Is there an easy way to have NUnit assert equality based on the properties?
This is my current solution but I think there may be something better:
Assert.AreEqual(LeftObject.Property1, RightObject.Property1)
Assert.AreEqual(LeftObject.Property2, RightObject.Property2)
Assert.AreEqual(LeftObject.Property3, RightObject.Property3)
...
Assert.AreEqual(LeftObject.PropertyN, RightObject.PropertyN)
What I'm going for would be in the same spirit as the CollectionEquivalentConstraint wherein NUnit verifies that the contents of two collections are identical.
Override .Equals for your object and in the unit test you can then simply do this:
Assert.AreEqual(LeftObject, RightObject);
Of course, this might mean you just move all the individual comparisons to the .Equals method, but it would allow you to reuse that implementation for multiple tests, and probably makes sense to have if objects should be able to compare themselves with siblings anyway.