public void GetAll_WhenValid_ShouldReturnBugsCollection() { // Arrange var repo = new RepositoryMock<Bug>(); var bugs = new List<Bug>() { new Bug() { Text = "Test bug #1" }, new Bug() { Text = "Test bug #2" }, new Bug() { Text = "Test bug #3" } }; repo.Entities = bugs; var controller = new BugsController(repo); // Act var result = controller.GetAll(); // Assert CollectionAssert.AreEquivalent(bugs, result.ToList<Bug>()); }
public void GetAll_WhenValid_ShouldReturnBugsCollection_WithMoq() { // Arrange var repoMock = new Mock<IRepository<Bug>>(); Bug[] bugs = { new Bug() { Text = "Test bug #1" }, new Bug() { Text = "Test bug #2" } }; repoMock.Setup(repo => repo.All()) .Returns(bugs.AsQueryable()); var controller = new BugsController(repoMock.Object); // Act var result = controller.GetAll(); // Assert CollectionAssert.AreEquivalent(bugs, result.ToArray<Bug>()); }