Is there an assertion built into Nunit that checks all properties between 2 objects are the same, without me having to override Equals?
I'm currently using reflection to Assert each individual property for a pair of objects.
Tests whether the specified objects are equal and throws an exception if the two objects are not equal. Different numeric types are treated as unequal even if the logical values are equal.
Testing Object Equivalence These methods test whether the same objects are referenced by the two arguments. Assert. AreSame( object expected, object actual ); Assert. AreSame( object expected, object actual, string message ); Assert.
Asserts that a condition is true. If the condition is false the method throws an AssertionException. That(Boolean, String) Asserts that a condition is true. If the condition is false the method throws an AssertionException.
NUnit is able to compare single-dimensioned arrays, multi-dimensioned arrays, nested arrays (arrays of arrays) and collections. Two arrays or collections are considered equal if they have the same dimensions and if each pair of corresponding elements is equal.
I don't believe there is.
Assert.AreEqual compares non-numeric types by Equals.
Assert.AreSame checks if they refer to the same object
You can write framework agnostic asserts using a library called Should. It also has a very nice fluent syntax which can be used if you like fluent interfaces. I had a blog post related to the same.
http://nileshgule.blogspot.com/2010/11/use-should-assertion-library-to-write.html
You can two objects and there properties with ShouldBeEquivalentTo
dto.ShouldBeEquivalentTo(customer);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With