public void Can_Filter_Products() { //Arrange Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); 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"}, }); ProductController controller = new ProductController(mock.Object); controller.pageSize = 3; //Action 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"); }
public void List_WhenPassedAPageNumber_ShouldPaginate() { // Arrange var controller = new ProductController(productRepo.Object) {PageSize = 3}; // Act var result = (ProductListViewModel) controller.List(page: 2).Model; // Assert Product[] prodArray = result.Products.ToArray(); Assert.IsTrue(prodArray.Length == 2); Assert.AreEqual(expected: prodArray[0].Name, actual: "P4"); Assert.AreEqual(expected: prodArray[1].Name, actual: "P5"); }
public void List_WhenPassedAPageNumber_ShouldSendTheCorrectPagingInfoToTheView() { // Arrange var controller = new ProductController(productRepo.Object) { PageSize = 3 }; // Act var result = (ProductListViewModel)controller.List(page: 2).Model; // Assert PagingInfo pagingInfo = result.PagingInfo; Assert.AreEqual(expected: 2, actual: pagingInfo.CurrentPage); Assert.AreEqual(expected: 3, actual: pagingInfo.ItemsPerPage); Assert.AreEqual(expected: 5, actual: pagingInfo.TotalItems); Assert.AreEqual(expected: 2, actual: pagingInfo.TotalPages); }
public void ListTest_CanFilterProducts() { 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()); var controller = new ProductController(mock.Object) { 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 ListTest_CanPaginate() { 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(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"); }
public void ListTest_CanSendPaginationViewModel() { 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(null, 2).Model; PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(pageInfo.CurrentPage, 2); Assert.AreEqual(pageInfo.ItemsPerPage, 3); Assert.AreEqual(pageInfo.TotalItems, 5); Assert.AreEqual(pageInfo.TotalPages, 2); }
public void Paginator_ok() { // 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()); 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_Paginate() { 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" } }); ProductController controller = new ProductController(mock.Object); controller.PageSize = 3; //zmiana IEnumerable //IEnumerable<Product> result = (IEnumerable<Product>)controller.List(2).Model; ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).Model; Product[] prodArray = result.Products.ToArray(); //add Products Assert.IsTrue(prodArray.Length == 2); Assert.AreEqual(prodArray[0].Name, "P4"); Assert.AreEqual(prodArray[1].Name, "P5"); }
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 ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).Model; //assert Product[] prodArray = result.Products.ToArray(); Assert.IsTrue(prodArray.Length == 2); Assert.AreEqual(prodArray[0], "P4"); Assert.AreEqual(prodArray[1], "P5"); }
public void Generate_Category_Specific_Product_Count() { Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); 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"}, }); ProductController target = new ProductController(mock.Object); target.pageSize = 3; 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); }
public void Can_Send_Paginaton_View_Model() { //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 ProductsListViewModel result = (ProductsListViewModel)controller.List(null, 2).Model; //assert PagingInfo pageInfo = new PagingInfo(); Assert.AreEqual(pageInfo.CurrentPage, 2); Assert.AreEqual(pageInfo.ItemsPerPage, 3); Assert.AreEqual(pageInfo.TotalItems, 5); Assert.AreEqual(pageInfo.TotalItems, 2); }
public void ListTest_GenerateCategorySpecificProductCount() { 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()); var target = new ProductController(mock.Object) { PageSize = 3 }; 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.AreEqual(res1, 2); Assert.AreEqual(res2, 2); Assert.AreEqual(res3, 1); Assert.AreEqual(resAll, 5); }
public void Generate_Category_Specific_Product_Count() { // Arrange // - create the mock repository Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); 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 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); }