public void Index_Contains_All_Products() { // Arrange - create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product {ProductID = 1, Name = "P1"}, new Product {ProductID = 2, Name = "P2"}, new Product {ProductID = 3, Name = "P3"}, }); // Arrange - create a controller AdminController target = new AdminController(mock.Object); // Action Product[] result = ((IEnumerable<Product>)target.Index(). ViewData.Model).ToArray(); // Assert Assert.AreEqual(result.Length, 3); Assert.AreEqual("P1", result[0].Name); Assert.AreEqual("P2", result[1].Name); Assert.AreEqual("P3", result[2].Name); }
public void Index_Contains_All_Games() { // Arrange - Create the mock repository Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new Game[] { new Game {GameID = 1, Name = "P1"}, new Game {GameID = 2, Name = "P2"}, new Game {GameID = 3, Name = "P3"}, }.AsQueryable()); // Arrange - Create a controller AdminController target = new AdminController(mock.Object); // Action Game[] result = ((IEnumerable<Game>)target.Index(). ViewData.Model).ToArray(); // Assert Assert.AreEqual(result.Length, 3); Assert.AreEqual("P1", result[0].Name); Assert.AreEqual("P2", result[1].Name); Assert.AreEqual("P3", result[2].Name); }