public void IndexContainsAllGames() { Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game { GameId = 1, Name = "Game 1"}, new Game { GameId = 2, Name = "Game 2"}, new Game { GameId = 3, Name = "Game 3"}, new Game { GameId = 4, Name = "Game 4"}, new Game { GameId = 5, Name = "Game 5"} }); AdminController controller = new AdminController(mock.Object); List<Game> res = ((IEnumerable<Game>)controller.Index() .ViewData.Model).ToList(); Assert.AreEqual(res.Count(), 5); Assert.AreEqual("Game 1", res[0].Name); Assert.AreEqual("Game 2", res[1].Name); Assert.AreEqual("Game 3", res[2].Name); }
public void Index_Contains_All_Games() { // Организация - создание имитированного хранилища данных Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game { GameId = 1, Name = "Игра1"}, new Game { GameId = 2, Name = "Игра2"}, new Game { GameId = 3, Name = "Игра3"}, new Game { GameId = 4, Name = "Игра4"}, new Game { GameId = 5, Name = "Игра5"} }); // Организация - создание контроллера AdminController controller = new AdminController(mock.Object); // Действие List<Game> result = ((IEnumerable<Game>)controller.Index(). ViewData.Model).ToList(); // Утверждение Assert.AreEqual(result.Count(), 5); Assert.AreEqual("Игра1", result[0].Name); Assert.AreEqual("Игра2", result[1].Name); Assert.AreEqual("Игра3", result[2].Name); }