I'm doing a unit test on a simple controller checking that when a null ID is passed in that it returns a 400 code. However when I test this the result does not come back as being equal to a 400 error code.
My code:
int? nullID = null;
var edit = controller.Edit(nullID) as ActionResult;
var result = new HttpStatusCodeResult(400, null);
Assert.AreEqual(edit, result);
When I debug the test I get the expected result seen here:
Edit Result:

Expected Result:

Where am I going wrong on this?
Assert.AreEqual(a,b) is the same as Assert.IsTrue(Object.Equals(a,b))
HttpStatusCodeResult does not implement Equals so the call goes to the default Object.Equals() which in turn defaults to Object.RefrenceEquals(a,b))
If the current instance is a reference type, the Equals(Object) method tests for reference equality, and a call to the Equals(Object) method is equivalent to a call to the ReferenceEquals method. Reference equality means that the object variables that are compared refer to the same object.
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