public void Can_Delete_Valid_Products() { // Arrange - create a Product Product prod = new Product { ProductID = 2, Name = "Test" }; // 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"}, } ); // Arrange - create the controller AdminController target = new AdminController(mock.Object); // Act - delete the product target.Delete(prod.ProductID); // Assert - ensure that the repository delete method was // called with the correct Product mock.Verify(m => m.DeleteProduct(prod.ProductID)); }
public void Delete_product_called_with_right_parameters() { var mock = CreateRepositoryMock(); var controller = new AdminController(mock.Object); controller.Delete(2); mock.Verify(m => m.Delete(2)); }
public void Can_Delete_Product() { var mockRepository = new Mock<IProductsRepository>(); var product = new Product {ProductId = 24, Name = "P24"}; mockRepository.Setup(x => x.Products).Returns(new[] {product}.AsQueryable()); var controller = new AdminController(mockRepository.Object); var result = controller.Delete(24); mockRepository.Verify(x=>x.DeleteProduct(product)); result.ShouldBeRedirectionTo(new {action = "Index"}); controller.TempData["message"].ShouldEqual("P24 was deleted"); }
public void Cant_Delete_InValid_Products() { // Arrange - create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(products.AsQueryable()); // Arrange - create the controller AdminController target = new AdminController(mock.Object); // Act - delete the product target.Delete(100); // Assert - ensure that the repository delete method was // called with the correct Product mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never()); }
public void Can_Delete_Valid_Products() { Product prod = new Product {ProductID = 2, Name = "Test"}; 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"} }); AdminController target = new AdminController(mock.Object); target.Delete(prod.ProductID); mock.Verify(m => m.DeleteProduct(prod.ProductID)); }
public void Cannot_Delete_Invalid_Products() { 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()); AdminController target = new AdminController(mock.Object); target.Delete(100); mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never()); }
public void CanDeleteValidProducts() { Product prod = new Product(){Id = 2, Name = "Test"}; Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product(){Id = 1, Name = "P1"}, prod, new Product(){Id = 3, Name = "P3"} }); AdminController controller = new AdminController(mock.Object); controller.Delete(prod.Id); mock.Verify(m => m.DeleteProduct(prod.Id)); }
public void Cannot_Delete_Invalid_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()); // Arrange - create the controller AdminController target = new AdminController(mock.Object); // Act - delete using an ID that doesn't exist target.Delete(100); // Assert - ensure that the repository delete method was // called with the correct Product mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never()); }
public void Cannot_Delete_InValid_Products() { Product product = new Product() { Name = "Test", ProductID = 1 }; Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(x => x.Products).Returns(new Product[] { new Product{ ProductID = 1, Name = "Test"} }.AsQueryable()); AdminController controller = new AdminController(mock.Object); controller.Delete(33); mock.Verify(x => x.DeleteProduct(It.IsAny<Product>()),Times.Never()); }
public void Can_Delete_Valid_Products() { var prod = new Product() {ProductID = 2, Name = "Test"}; Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(repo => repo.Products).Returns(new Product[] { new Product() {ProductID = 1, Name = "p1"}, prod, new Product() {ProductID = 2, Name = "p2"} }); AdminController target = new AdminController(mock.Object); target.Delete(prod.ProductID); //assert - ensure that the repository delete method was called with the correct product mock.Verify(repo => repo.DelteProduct(prod.ProductID)); }
public void Cannot_Delete_Invalid_Products() { // Arrange // - Create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); AdminController target = new AdminController(mock.Object); 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()); // Act ActionResult result = target.Delete(100); // Assert mock.Verify(m => m.DeleteProduct(It.IsAny<Product>()), Times.Never()); Assert.IsNotInstanceOfType(result, typeof(ViewResult)); }
public void Can_Delete_Valid_Products() { // arrange - create a product Product prod = new Product { ProductID = 2, Name = "Test" }; // arrange - create the mock repo Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product{ProductID = 1, Name = "P1"}, new Product {ProductID = 3, Name = "P3"} }); // Arrange - Set up what i'm going to work with AdminController target = new AdminController(mock.Object); // act - delete the product target.Delete(prod.ProductID); // assert - ensure the repo delete was called with the correct product mock.Verify(m => m.DeleteProduct(prod.ProductID)); }
public void Can_Delete_Valid_Products() { // przygotowanie - tworzenie produktu Product prod = new Product { ProductID = 2, Name = "Test" }; // przygotowanie - tworzenie imitacji repozytorium 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"}, }); // przygotowanie - utworzenie kontrolera AdminController target = new AdminController(mock.Object); // działanie - usunięcie produktu target.Delete(prod.ProductID); // asercje - upewnienie się, że metoda repozytorium // została wywołana z właściwym produktem mock.Verify(m => m.DeleteProduct(prod.ProductID)); }
public void Can_Delete_Valid_Product() { // Arrange // - Create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); AdminController target = new AdminController(mock.Object); Product product = new Product { ProductID = 2, Name = "Test" }; mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1" }, product, new Product { ProductID = 3, Name = "P3" } }.AsQueryable()); // Act ActionResult result = target.Delete(product.ProductID); // Assert mock.Verify(m => m.DeleteProduct(product)); Assert.IsNotInstanceOfType(result, typeof(ViewResult)); }
public void Can_Delete_Valid_Products() { // Arrange - 상품을 생성한다. Product prod = new Product { ProductID = 2, Name = "TesT" }; // Arrange - Mock 리파지토리를 생성한다. 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" } }); // Arrange - 컨트롤러를 생성한다. AdminController target = new AdminController(mock.Object); // Act - 상품ㅇ르 삭제한다. target.Delete(prod.ProductID); // Assert - 리파지토리의 DeleteProduct 메서드가 // 올바른 상품과 함께 호출되었는지 확인한다. mock.Verify(m => m.DeleteProduct(prod.ProductID)); }
public void Can_Delete_Valid_Products() { //arrange create a product Product product = new Product { ProductID = 2, Name = "Test" }; //Arrange create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(p => p.Products).Returns(new Product[] { new Product{ProductID = 1, Name = "P1"}, new Product{ProductID = 3, Name = "P3"} }); //Arrange create the controller AdminController controller = new AdminController(mock.Object); //Act delete the product controller.Delete(product.ProductID); //Assert ensure that the repository delete method was called // was called with the correct product mock.Verify(m => m.DeleteProduct(product.ProductID)); }
public void Can_Delete_Valid_Products() { Product product = new Product() { Name = "Test", ProductID = 1 }; Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(x => x.Products).Returns(new Product[] { new Product{ ProductID = 1, Name = "Test"} }.AsQueryable()); AdminController controller = new AdminController(mock.Object); controller.Delete(product.ProductID); mock.Verify(x => x.DeleteProduct(product)); }
public void Can_Delete_Valid_Products() { var prod = new Product {ProductId = 2, Name = "test"}; var mock = new Mock<IProductRepository>(); mock.Setup(x => x.Products).Returns(new List<Product> { new Product {Name = "P1", ProductId = 1, Category = "Apples"}, prod, new Product {Name = "P3", ProductId = 3, Category = "Plum"}, }); var target = new AdminController(mock.Object); target.Delete(prod.ProductId); mock.Verify(m => m.DeleteProduct(prod.ProductId)); }
public void Can_Delete_Valid_Products() { //arrange - create a Product Product prod = new Product {ProductID = 2, Name = "Test"}; //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 AdminController target = new AdminController(mock.Object); //act - delete the product target.Delete(prod.ProductID); //assert mock.Verify(m=>m.DeleteProduct(prod.ProductID)); }