Reputation: 23
I'm implementing the following tests:
[TestMethod]
public void Index_Get_RetrievesAllContributionsFromRepository()
{
// Arrange
Contributions Contribution1 = GetContributionNamed("Council", 2003);
Contributions Contribution2 = GetContributionNamed("Council", 2004);
InMemoryContributionRepository repository = new InMemoryContributionRepository();
repository.Add(Contribution1);
repository.Add(Contribution2);
var controller = GetHomeController(repository);
// Act
var result = controller.Index();
// Assert
var model = (IEnumerable<Contributions>)result.ViewData.Model;
CollectionAssert.Contains(model.ToList(), Contribution1);
CollectionAssert.Contains(model.ToList(), Contribution2);
CollectionAssert.xxxxxx(model.ToList().Count, Contribution1, 2);
}
The last test there with the xxxxxx is trying to check if Contribution1
has 2 values, which it does. What line of code performs that test please?
c# novice
Upvotes: 0
Views: 130
Reputation: 1499770
It sounds like you just want:
Assert.AreEqual(2, model.Count());
But it sounds like you'd be better using:
CollectionAssert.AreEquivalent(new[] { Contribution1, Contribution2 },
model.ToList());
... That can replace all three of your lines.
In both cases note that the expected value should be the first argument, and the actual value should be the second.
Upvotes: 5