0

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

1
  • There are 3 parameters. You you explained 2. What does model.ToList().Count mean in that line? Commented Jul 23, 2012 at 9:49

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1
Assert.AreEqual(model.ToList().Count, 2);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.