mardi 1 décembre 2015

[Solved]'AsQueryable' and 'ToArray' do not recognized

There is a unit test written in Apress MVC 4:

    [TestClass]
    public class AdminTests
    {
        [TestMethod]
        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, ProductName = "P1"},
        new Product {ProductId = 2, ProductName = "P2"},
        new Product {ProductId = 3, ProductName = "P3"},
        }.AsQueryable()); //error point1
            // Arrange - create a controller
            AdminController target = new AdminController(mock.Object);
            // Action
            Product[] result = ((IEnumerable<Product>)target.Index().
            ViewData.Model).ToArray(); //error point2
            // Assert
            Assert.AreEqual(result.Length, 3);
            Assert.AreEqual("P1", result[0].ProductName);
            Assert.AreEqual("P2", result[1].ProductName);
            Assert.AreEqual("P3", result[2].ProductName);
        }
    }

I received the error below. How can I overcome this? Thanks in advance.

Error 1 'System.Array' does not contain a definition for 'AsQueryable' and no extension method 'AsQueryable' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) D:\benim_yazilimlarim\mvc\SportsStore\SportsStore.UnitTest\UnitTest1.cs 119 15 SportsStore.UnitTest

Error 2 'System.Collections.Generic.IEnumerable' does not contain a definition for 'ToArray' and no extension method 'ToArray' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?) D:\benim_yazilimlarim\mvc\SportsStore\SportsStore.UnitTest\UnitTest1.cs 124 33 SportsStore.UnitTest

Aucun commentaire:

Enregistrer un commentaire