Ejemplo n.º 1
0
        public void CanPaginate()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new List<Product>
            {
                new Product {ProductId = 1, Name = "P1"},
                new Product {ProductId = 2, Name = "P2"},
                new Product {ProductId = 3, Name = "P3"},
                new Product {ProductId = 4, Name = "P4"},
                new Product {ProductId = 5, Name = "P5"},
                new Product {ProductId = 6, Name = "P6"},
                });

            ProductController prod = new ProductController(mock.Object);
            prod.PageSize = 3;

            //act
            ProductsListViewModel result = (ProductsListViewModel)prod.List(null, 2).Model;
            //IEnumerable<Product> result = prod.List(2).Model as IEnumerable<Product>;

            //assert
            Product[] prodArr = result.Products.ToArray();
            Assert.IsTrue(prodArr.Length == 3);
            Assert.AreEqual(prodArr[0].Name, "P4");
        }
        public void Can_List_Paginate()
        {
            // arrange
            // create mock repository
            var productRepository = new Mock<IProductRepository>();
            productRepository.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"},
                    new Product {ProductId = 4, Name = "P4"},
                    new Product {ProductId = 5, Name = "P5"}
              }.AsQueryable());

            //Arrange: create a controller and make the page size 3 items.
            ProductController controller = new ProductController(productRepository.Object);
            controller.PageSize = 3;

            // act
            var actionResult = controller.List(null, 2);

            // assert
            var productsListViewModel = actionResult.Model as ProductsListViewModel;

            Assert.IsNotNull(productsListViewModel);
            Assert.IsTrue(productsListViewModel.Products.Count() == 2);
            Assert.AreEqual(productsListViewModel.Products.ToArray()[0].Name, "P4");
            Assert.AreEqual(productsListViewModel.Products.ToArray()[1].Name, "P5");
        }
Ejemplo n.º 3
0
        public void CanPaginate()
        {
            // Arrange
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            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"},
                    new Product {ProductID = 4, Name = "p4"},
                    new Product {ProductID = 5, Name = "p5"}
                }.AsQueryable());

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Act
            ProductsListViewModel result = (ProductsListViewModel) controller.List(null,2).Model;

            // Assert
            Product[] prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "p4");
            Assert.AreEqual(prodArray[1].Name, "p5");
        }
Ejemplo n.º 4
0
        public void Can_Paginate()
        {
            // Arrange
            Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
            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"},
                new Product {ProductID = 4, Name = "P4"},
                new Product {ProductID = 5, Name = "P5"}
            });

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Act
            IEnumerable<Product> result = (IEnumerable<Product>) controller.List(2).Model;

            // Assert
            Product[] prodArray = result.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            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"},
                new Product {ProductID = 4, Name = "P4"},
                new Product {ProductID = 5, Name = "P5"}
            });

            // Arrange
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;
            
            // Act
            ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).Model;
            
            // Assert
            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Ejemplo n.º 6
0
        public void Can_paginate()
        {
            // Arrange
            // - Mock 리파지터리를 생성한다.
            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" },
                new Product { ProductID = 4, Name = "P4" },
                new Product { ProductID = 5, Name = "P5" }
            }.AsQueryable());

            // 컨트롤러를 생성하고 페이지 크기를 3개로 지정한다.
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Action
            ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).ViewData.Model;

            // Assert
            Product[] prodArray = result.Products.ToArray();

            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
Ejemplo n.º 7
0
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            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"},
                        new Product {ProductID = 4, Name = "P4"},
                        new Product {ProductID = 5, Name = "P5"}
                    }
                    .AsQueryable()
                );
            var controller = new ProductController(mock.Object) { PageSize = 3 };
            var result = (ProductsListViewModel)controller.List(2).Model;

            //Assert
            Assert.AreEqual(2, result.PagingInfo.CurrentPage);
            Assert.AreEqual(3, result.PagingInfo.ItemsPerPage);
            Assert.AreEqual(5, result.PagingInfo.TotalItems);
            Assert.AreEqual(2, result.PagingInfo.TotalPages);
        }
Ejemplo n.º 8
0
        public void Cannot_Retrieve_Image_Data_For_Invalid_Id()
        {
            // Arrange
            Product prod = new Product
            {
                ProductId = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            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" }
            }.AsQueryable());

            ProductController target = new ProductController(mock.Object);

            // Act
            ActionResult result = target.GetImage(100);

            // Assert
            Assert.IsNull(result);
        }
Ejemplo n.º 9
0
        public void Can_Paginate()
        {
            //Arrange
            // - create the mock repository
            var 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" },
                new Product {ProductID = 4, Name = "P4" },
                new Product {ProductID = 5, Name = "P5" },
            }.AsQueryable());

            // create a controller and make the page size 3 items
            var controller = new ProductController(mock.Object) { PageSize = 3 };

            // Action
            var result = (ProductsListViewModel)controller.List(2).Model;

            // Assert
            var prodArray = result.Products.ToArray();
            Assert.AreEqual(2, prodArray.Length);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
Ejemplo n.º 10
0
        public void Cant_Retrieve_NonExistint_Image_Data()
        {
            // Arrange - create a Product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            // 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"},
                prod,
                new Product {ProductID = 3, Name = "P3"}
            }.AsQueryable());

            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(3);

            // Assert
            Assert.IsNull(result);
        }
Ejemplo n.º 11
0
        public void CanGeneratePageLinks()
        {
            Mock<IProductRepository> mock = new Mock<IProductRepository>();

            mock.Setup(m => m.Products).Returns(new List<Product> {   new Product {Category = "Football", Description = "Ball", Price = 49, Name = "Adidas Euro 2012 Match Football - Tango 12"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 38, Name = "Mitre Tensile Football"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 25, Name = "Adidas Tango Football : Pasadena"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 25, Name = "Adidas Uefa Europa League Match Ball : 2011/12"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 25, Name = "Mitre Ciero Match Football"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 14.95M, Name = "Mitre Football Ball : Astro Division"},
                                                                      new Product {Category = "Football", Description = "Ball", Price = 12.95M, Name = "Mitre Match Football : Campeon"},

                                                                      new Product {Category = "Football", Name = "Nike T90 Laser IV", Price = 49, Description = "Lighter, deadlier, more powerful. The T90 Laser IV really is the Perfect Strike"},
                                                                      new Product {Category = "Football", Name = "Nike Mercurial Vapor III", Price = 38, Description = "A Blast from the past - one of our most popular ever articles is all about the classic MVIII!"},

                                                                      new Product {Category = "Tennis", Name = "Wilson BLX Six.One 95 18x20", Price = 86, Description = "New A tighter, more control oriented stringbed plus improved feel separates this one from the pack. A confidence inspiring racquet for advanced players. 18/20 string pattern, standard length, 95 sq. inch headsize, traditional head light balance."},
                                                                      new Product {Category = "Tennis", Name = "Wilson BLX Six.One Team", Price = 155, Description = "New This update features a more open 16x18 string pattern than its predecessor for added pop and topspin. Great feel and a clean response will impress intermediate to advanced level players. Headsize: 95 sq. in. Length: 27. Strung weight: 10.7 oz."},
                                                                      new Product {Category = "Tennis", Name = "Wilson BLX Six.One 95 16x18", Price = 79, Description = "New An updated look with excellent maneuverability and access to spin, this easy to swing racket is great for 4.0+ level players. Strung weight: 10.4 ounces. Swingweight: 313. Headsize: 100 square inches."},
                                                                      new Product {Category = "Tennis", Name = "Boris Becker Delta Core London", Price = 79, Description = "Feel, comfort, control, maneuverability, power and stability, this one has it all. A truly impressive option for the 4.0+ level player this one comes with a standard length, 98sq.in headsize and 16x19 string pattern."},
                                                                    }.AsQueryable());

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;
            controller.List("Football", 1);

            int actual = controller.pagingInfo.TotalPages;
            int expected = 3;
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void Generate_Category_Specific_Product_Count() {
            // 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", Category = "Cat1"},
                new Product {ProductID = 2, Name = "P2", Category = "Cat2"},
                new Product {ProductID = 3, Name = "P3", Category = "Cat1"},
                new Product {ProductID = 4, Name = "P4", Category = "Cat2"},
                new Product {ProductID = 5, Name = "P5", Category = "Cat3"}
            }.AsQueryable());

            // Arrange - create a controller and make the page size 3 items
            ProductController target = new ProductController(mock.Object);
            target.PageSize = 3;

            // Action - test the product counts for different categories
            int res1 = ((ProductsListViewModel)target.List("Cat1").Model).PagingInfo.TotalItems;
            int res2 = ((ProductsListViewModel)target.List("Cat2").Model).PagingInfo.TotalItems;
            int res3 = ((ProductsListViewModel)target.List("Cat3").Model).PagingInfo.TotalItems;
            int resAll = ((ProductsListViewModel)target.List(null).Model).PagingInfo.TotalItems;

            // Assert
            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 2);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }
Ejemplo n.º 13
0
        public void Can_Retrieve_Image_Data()
        {
            Product product = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] {},
                ImageMimeType = "image/png"
            };

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1"},
                product,
                new Product {ProductID = 1, Name = "P3"}
            }.AsQueryable());

            ProductController target = new ProductController(mock.Object);

            ActionResult result = target.GetImage(2);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(product.ImageMimeType,((FileResult)result).ContentType);
        }
Ejemplo n.º 14
0
        public void Can_Retreive_Image_Data()
        {
            //Arrange - create a product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "test",
                ImageData = new Byte[] { },
                ImageMimeType = "image/png"

            };

            //Arrange -create a mock repository

            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(p => p.Products).Returns(new Product[] { 
                new Product{ProductID=1,Name="P1"},
                prod,
                new Product{ProductID=3,Name="P3"}           
            
            }.AsQueryable());

            ProductController controller = new ProductController(mock.Object);

            ActionResult result = controller.GetImage(2);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);

        }
Ejemplo n.º 15
0
        public void Can_Filter_Products()
        {
            //Arrange
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product{ProductID = 1, Name = "P1", Category = "Cat1"},
                new Product{ProductID = 2, Name = "P2", Category = "Cat2"},
                new Product{ProductID = 3, Name = "P3", Category = "Cat1"},
                new Product{ProductID = 4, Name = "P4", Category = "Cat2"},
                new Product{ProductID = 5, Name = "P5", Category = "Cat3"}
            }.AsQueryable());

            //Arrange
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            //Act
            Product[] res = ((ProductListViewModel)controller.List("Cat2",1).Model).Products.ToArray();

            //Assert
            Assert.AreEqual(res.Length,2);
            Assert.IsTrue(res[0].Name == "P2" && res[0].Category == "Cat2");
            Assert.IsTrue(res[1].Name == "P4" && res[1].Category == "Cat2");
        }
        public void Can_Paginate()
        {
            // Arrange
            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"},
                new Product {ProductID = 4, Name = "P4"},
                new Product {ProductID = 5, Name = "P5"}
            });

            // create a controller and make the page size 3 items
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;
            
            // Act
            ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).Model;
            
            // Assert
            Product[] prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");
        }
Ejemplo n.º 17
0
        public void Can_paginate()
        {
            ProductController target = new ProductController(repository);
            target.PageSize = 3;

            ProductListViewModel result = (ProductListViewModel)((ViewResult)target.List(null,null,2)).Model;
            Product[] prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "P4");
            Assert.AreEqual(prodArray[1].Name, "P5");

            result = (ProductListViewModel)((ViewResult)target.List(null, null)).Model;
            prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 3);
            Assert.AreEqual(prodArray[0].Name, "P1");
            Assert.AreEqual(prodArray[1].Name, "P2");
            Assert.AreEqual(prodArray[2].Name, "P3");

            result = (ProductListViewModel)((ViewResult)target.List(null, null, -1)).Model;
            prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 3);
            Assert.AreEqual(prodArray[0].Name, "P1");
            Assert.AreEqual(prodArray[1].Name, "P2");
            Assert.AreEqual(prodArray[2].Name, "P3");
        }
Ejemplo n.º 18
0
        public void Can_Retrieve_Image_Data()
        {
            // Arrange - create a Product with image data
            Product prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };

            // 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"},
                prod,
                new Product {ProductID = 3, Name = "P3"}
            }.AsQueryable());

            // Arrange - create the controller
            ProductController target = new ProductController(mock.Object);

            // Act - call the GetImage action method
            ActionResult result = target.GetImage(2);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);
        }
Ejemplo n.º 19
0
        public void CanPaginate()
        {
            //arrange
            var target = new Mock<IProductRepository>();

            target.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"},
                new Product{ProductID = 4, Name = "p4"},
                new Product{ProductID = 5, Name = "p5"},
            }.AsQueryable());

            //arrange
            var productController = new ProductController(target.Object);
            productController.PageSize = 3;

            //act
            var result = (ProductsListViewModel)productController.List(null, 2).Model;

            //assert
            var prodArray = result.Products.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "p4");
            Assert.AreEqual(prodArray[1].Name, "p5");
        }
        public void Can_Filter_Products()
        {
            // arrange - mock repo
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {ProductID = 1, Name = "P1", Category = "Cat1"},
                new Product {ProductID = 2, Name = "P2", Category = "Cat2"},
                new Product {ProductID = 3, Name = "P3", Category = "Cat1"},
                new Product {ProductID = 4, Name = "P4", Category = "Cat2"},
                new Product {ProductID = 5, Name = "P5", Category = "Cat3"},
            });

            // arrange - create a controller and make the page size 3 items
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // action (act)
            Product[] result = ((ProductsListViewModel)controller.List("Cat2", 1).Model).Products.ToArray();

            // Assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[1].Category == "Cat2");
        }
Ejemplo n.º 21
0
        public void CanSendPaginationViewModel()
        {
            //arrange
            var target = new Mock<IProductRepository>();

            target.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"},
                new Product{ProductID = 4, Name = "p4"},
                new Product{ProductID = 5, Name = "p5"},
            }.AsQueryable());

            //arrange
            var productController = new ProductController(target.Object);
            productController.PageSize = 3;

            //act
            var result = (ProductsListViewModel) productController.List(null, 2).Model;

            //assert
            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Ejemplo n.º 22
0
        public void Can_Filter_Products()
        {
            //arrange
            var mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new[]
                {
                    new Product {ProductID = 1, Name = "P1", Category = "Cat1"},
                    new Product {ProductID = 2, Name = "P2", Category = "Cat2"},
                    new Product {ProductID = 3, Name = "P3", Category = "Cat1"},
                    new Product {ProductID = 4, Name = "P4", Category = "Cat2"},
                    new Product {ProductID = 5, Name = "P5", Category = "Cat3"}
                }.AsQueryable());
               //arrange
            var controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            //action
            //controller.List() have default second parameter = 1
            Product[] result = ((ProductsListViewModel) controller.List("Cat2").Model).Products.ToArray();

            //assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[0].Category == "Cat2");
        }
Ejemplo n.º 23
0
        public void Can_Send_Pagination_View_Model()
        {
            // 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"},
            new Product {ProductID = 4, Name = "P4"},
            new Product {ProductID = 5, Name = "P5"}
            }.AsQueryable());

            // Arrange - create a controller and make the page size 3 items

            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            // Action

            ProductsListViewModel result = (ProductsListViewModel)controller.List("Soccer", 2).Model;

            // Assert

            PagingInfo pageInfo = result.PagingInfo;
            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Ejemplo n.º 24
0
        public void Can_Filter_Products()
        {
            //Организация - создание имитации хранилища
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m=>m.Products).Returns(new Product[]{
                new Product {ProductID = 1, Name="P1", Category = "Cat1"},
                new Product {ProductID = 2, Name="P2", Category = "Cat2"},
                new Product {ProductID = 3, Name="P3", Category = "Cat1"},
                new Product {ProductID = 4, Name="P4", Category = "Cat2"},
                new Product {ProductID = 5, Name="P5", Category = "Cat3"}
            }.AsQueryable());

            //Организация - создание контроллера и установка
            //размера страницы равным трем элементам
            ProductController controller = new ProductController(mock.Object);
            controller.PageSize = 3;

            //Действие
            Product[] result =
                ((ProductsListViewModel)controller.List("Cat2", 1).Model).Products.ToArray();

            //Утверждение
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[1].Category == "Cat2");
        }
        public void ProductController_GetImage_CanRetrieveImageData()
        {
            // Arrange
            var prod = new Product
            {
                ProductID = 2,
                Name = "Test",
                ImageData = new byte[] { },
                ImageMimeType = "image/png"
            };
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product {ProductID = 1, Name = "P1", Category = "Cat1" },
                prod,
                new Product {ProductID = 3, Name = "P3", Category = "Cat1" },

            }.AsQueryable());
            var target = new ProductController(mock.Object);

            // Act
            var result = target.GetImage(2);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(FileResult));
            Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType);
        }
Ejemplo n.º 26
0
        public void Can_Filter_Products()
        {
            controller = new ProductController(mock.Object);
            controller.pageSize = 3;

            Product[] result = ((ProductListViewModel)controller.List("Cat2", 1).Model).Products.ToArray();

            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "P2" && result[0].Category == "Cat2");
            Assert.IsTrue(result[1].Name == "P4" && result[0].Category == "Cat2");
        }
Ejemplo n.º 27
0
 public void Can_Filter_Products()
 {
     ProductController target = new ProductController(repository);
     target.PageSize = 1;
     ProductListViewModel result = (ProductListViewModel)((ViewResult)target.List("Soccer", null, 2)).Model;
     Product[] prodArray = result.Products.ToArray();
     Assert.AreEqual(prodArray[0].Name, "P2");
     Assert.AreEqual(result.PagingInfo.ItemsPerPage, 1);
     Assert.AreEqual(result.PagingInfo.TotalItems, 3);
     Assert.AreEqual(result.PagingInfo.TotalPages, 3);
 }
Ejemplo n.º 28
0
        public void Setup()
        {
            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"},
            new Product {ProductID = 4, Name = "P4"},
            new Product {ProductID = 5, Name = "P5"}
            }.AsQueryable());

            controller = new ProductController(mock.Object);
        }
Ejemplo n.º 29
0
        public void Cannot_Retrieve_Image_Data_For_Invalid_ID()
        {
            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"}
            }.AsQueryable());
            ProductController target = new ProductController(mock.Object);

            ActionResult result = target.GetImage(100);

            Assert.IsNull(result);
        }
 public void List_WhenListingTheSecondPageOfASeriesOfProducts_ShouldPaginateThemAndShowOnlyTheOnesInTheSecondPage()
 {
     // Arrange
      ProductController controller = new ProductController(repo.Object);
      controller.PageSize = 4;
      // Act
      ProductsListViewModel viewModel = (ProductsListViewModel)controller.List(page: 2).Model;
      // Assert
      List<Product> products = viewModel.Products.ToList();
      Assert.IsTrue(products.Count == 2);
      Assert.AreEqual(expected: "P5", actual: products[0].Name);
      Assert.AreEqual(expected: "P6", actual: products[1].Name);
 }