public async void DeleteProduct_IdInValid_ReturnNotFound(int productId) { Product product = null; _mockRepository.Setup(x => x.GetById(productId)).ReturnsAsync(product); var resultNotFound = await _productApiController.DeleteProduct(productId); Assert.IsType <NotFoundResult>(resultNotFound.Result); }
public void DeleteProduct_ShouldDeleteProduct() { MockRequest(); CreateProductController(); CreateProduct(); productController.DeleteProduct(product); mockRequest.Verify(m => m.DeleteEntity(product), Times.Once()); }
public void DeleteProductNoContentTest() { // Arrange Product product = new Product(); product.ProductId = 1; ProductApiController controller = new ProductApiController(); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); // Act var response = controller.DeleteProduct(product); // Assert Assert.IsNotNull(response); Assert.AreEqual(System.Net.HttpStatusCode.NoContent, response.StatusCode); }
public void DeleteProduct_RemovesExistingProductFromDatabase_Ok() { // arrange var mock = new Mock <EFProductRepository>(); var productCategoryMock = new Mock <ProductCategory>(); var products = new Product[] { new Product { ProductId = 1, Name = "N1", Description = "D1", Price = 10, ProductCategory = productCategoryMock.Object, ProductCategoryId = 1 }, new Product { ProductId = 2, Name = "N2", Description = "D1", Price = 10, ProductCategory = productCategoryMock.Object, ProductCategoryId = 1 }, new Product { ProductId = 3, Name = "N3", Description = "D1", Price = 10, ProductCategory = productCategoryMock.Object, ProductCategoryId = 3 }, new Product { ProductId = 4, Name = "N4", Description = "D1", Price = 10, ProductCategory = productCategoryMock.Object, ProductCategoryId = 4 }, new Product { ProductId = 5, Name = "N5", Description = "D1", Price = 10, ProductCategory = productCategoryMock.Object, ProductCategoryId = 1 } }; Product productToRemove = new Product { ProductId = 3, Name = "N3", Description = "D1", Price = 10, ProductCategory = productCategoryMock.Object, ProductCategoryId = 3 }; mock.Setup(repo => repo.DeleteProduct(It.IsAny <int>())).Returns(productToRemove); productCategoryMock.Setup(repo => repo.Name).Returns("CG3"); productCategoryMock.Setup(repo => repo.ProductCategoryId).Returns(3); var controller = new ProductApiController(mock.Object); // act var result = controller.DeleteProduct(3); // assert Assert.Equal("N3", result.Value.Name); Assert.Equal(3, result.Value.ProductId); Assert.Equal("CG3", result.Value.ProductCategory.Name); Assert.Equal(3, result.Value.ProductCategory.ProductCategoryId); Assert.Equal(3, result.Value.ProductCategoryId); }