I've got an injected interface I'm unit testing. The method in question is working, but I'm trying to write a unit test that confirms the returned sample data is complete and accurate. My test looks correct to me, and even the results look identical, yet the test fails with "CollectionAssert.AreEquivalent failed. The expected collection contains 1 occurrence(s) of . The actual collection contains 0 occurrence(s)."
[TestMethod]
public void Should_Get_All_Amenities()
{
var amenitiesRep = _ninjectKernel.Get<IAmenityRepository>();
var amenities = amenitiesRep.GetAmenities();
var expected = new List<Amenity>
{
new Amenity() {Id = 1, Name = "Pool", Category = "resort"},
new Amenity() {Id = 2, Name = "Hottub", Category = "resort"},
new Amenity() {Id = 3, Name = "Steamroom", Category = "unit"}
};
Assert.IsNotNull(amenities);
Assert.IsTrue(amenities.Count() == 3);
CollectionAssert.AreEquivalent(expected, amenities);
}
(Relevant code from my TestRepository)
var amenities = new List<Amenity>
{
new Amenity() {Id = 1, Name = "Pool", Category = "resort"},
new Amenity() {Id = 2, Name = "Hottub", Category = "resort"},
new Amenity() {Id = 3, Name = "Steamroom", Category = "unit"}
};
var mockAmenitiesRep = new Mock<IAmenityRepository>();
mockAmenitiesRep.Setup(_m => _m.GetAmenities()).Returns(amenities);
Kernel.Bind<IAmenityRepository>().ToConstant(mockAmenitiesRep.Object);
I can confirm at all the data is populated correctly at the CollectionAssert, every field appears to match 1 to 1, same number of objects, same object types, so I'm just lost why the test is failing.
(Edit: Line the code fails on is the CollectionAssert)