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" }, }.AsQueryable <Product>()); // Arrange - create a controller ProductController target = new ProductController(mock.Object); // Action Product[] result = GetViewModel <IEnumerable <Product> >(target.AdminList())?.ToArray(); // Assert Assert.Equal(3, result.Length); Assert.Equal("P1", result[0].Name); Assert.Equal("P2", result[1].Name); Assert.Equal("P3", result[2].Name); }