Esempio n. 1
0
        public void Edit_InexistingProductRequested_NullReturnedToView()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);

            var resultProduct = adminController.Edit(10).ViewData.Model as Product;

            Assert.IsNull(resultProduct);
        }
Esempio n. 2
0
        public void Delete_ProductFromDb_ProductDeleted()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);

            adminController.Delete(2);

            productRepo.Verify(m => m.DeleteProduct(2), Times.Once);
        }
Esempio n. 3
0
        public void Edit_OneProductRequested_ProductReturnedToView()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);

            var resultProduct = adminController.Edit(2).ViewData.Model as Product;

            Assert.AreEqual("P2", resultProduct.Name);
        }
Esempio n. 4
0
        public void Index_ManyProducts_ReturnsAll()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);

            var result = (IEnumerable <Product>)adminController.Index().ViewData.Model;

            Assert.AreEqual(3, result.Count(), "Not all the product were rwturned");
        }
Esempio n. 5
0
        public void Edit_ValidProduct_ProductUpdated()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);
            var product         = new Product();

            adminController.Edit(product);

            productRepo.Verify(m => m.SaveProduct(product));
        }
Esempio n. 6
0
        public void Index_ManyProducts_ReturnsCorrectProducts()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);

            var result = ((IEnumerable <Product>)adminController.Index().ViewData.Model).ToArray();

            Assert.AreEqual("P1", result[2].Name);
            Assert.AreEqual("P2", result[1].Name);
            Assert.AreEqual("P3", result[0].Name);
        }
Esempio n. 7
0
        public void Edit_InvValidProduct_ProductNotUpdated()
        {
            var productRepo     = RepositoryHelper.CreateProductsRepoMock();
            var adminController = new AdminController(productRepo.Object);

            adminController.ModelState.AddModelError("errorMessage", "This is an error");
            var product = new Product();

            adminController.Edit(product);

            productRepo.Verify(m => m.SaveProduct(product), Times.Never());
        }
Esempio n. 8
0
        public void List_Pagination_ReturnsProductsPaginated()
        {
            // Arange
            var productsRepoMoack = RepositoryHelper.CreateProductsRepoMock();

            var productController = new ProductController(productsRepoMoack.Object);

            productController.PageSize = 2;

            // Act
            var model = productController.List(null, 2).Model as ProductsListViewModel;

            // Assert
            Assert.IsNotNull(model, "Model is null");
            Assert.AreEqual(1, model.Products.Count());
            Assert.AreEqual("P3", model.Products.First().Name);
        }
Esempio n. 9
0
        public void List_Pagination_ReturnsPagingInfoCorrect()
        {
            // Arange
            var productsRepoMoack = RepositoryHelper.CreateProductsRepoMock();

            var productController = new ProductController(productsRepoMoack.Object);

            productController.PageSize = 2;

            // Act
            var model = productController.List(null, 2).Model as ProductsListViewModel;

            // Assert
            Assert.IsNotNull(model, "Model is null");

            Assert.AreEqual(2, model.PagingInfo.CurrentPage, "CurrentPage is not correct");
            Assert.AreEqual(2, model.PagingInfo.TotalPages, "TotalPages is not correct");
            Assert.AreEqual(3, model.PagingInfo.TotalItems, "TotalItem value is not correct");
            Assert.AreEqual(2, model.PagingInfo.ItemsPerPage, "ItemPerPage value is not correct");
        }