Why does Assert.AreEqual(T obj1, Tobj2) fail with identical objects
The call Assert.AreEqual(expected, expected) should not fail. If you made a mistake in your question and you meant Assert.AreEqual(expected, actual) and your HomeControllerHelper.GetNavigationMenuByUserRole returns a new instance of NavigationMenu, then will the call to Assert.AreEqual always fail, cause your type NavigationMenu is a class and therefore a reference type, even if you set the properties of the instances to the same values.
Assert.AreEqual performs an equality check if the two variables point to the same reference (aka. ReferenceEqual) and not if the two references contain the same (property) values.
You could override the Equals method of your NavigationMenu class to provide a custom implementation if two instances of your class are equal.
Assuming that it should be Assert.AreEqual(expected, actual);
, like it was stated in comments above:
You have to define how to compare NavigationMenuItem
objects. Atm its only cheking if its the same instance and obviosly they aren't so asserty have to fail.
Because you are (probably) comparing two different instances of an object, but with the same parameters. In order for the objects to be "equal", you need to override the Equals method on the object and implement a comparison there.