public async void DeleteProduct_ProductNull_ReturnNotFound(int productId) { _mockRepo.Setup(x => x.GetById(productId)).ReturnsAsync((Product)null); var result = await _apiController.DeleteProduct(productId); var redirect = Assert.IsType <NotFoundResult>(result); }
public async void Should_DeleteProduct_Returns_NotFound_If_IdNotExist(int id) { mockRepo.Setup(x => x.GetEntity(id)).Returns(Task.FromResult <Product>(null)); var result = await apiController.DeleteProduct(id); Assert.IsType <NotFoundResult>(result); }
public async void DeleteProduct_IdInValid_ReturnNotFound(int productId) { Table product = null; _mockRepo.Setup(x => x.GetById(productId)).ReturnsAsync(product); var resultNotFound = await _controller.DeleteProduct(productId); Assert.IsType <NotFoundResult>(resultNotFound.Result); }
public async void Delete_IdInValid_ReturnNotFoundResult(int productId) { Product product = null; _mockRepo.Setup(repo => repo.GetByIdAsync(productId)).ReturnsAsync(product); var result = await _controller.DeleteProduct(productId); Assert.IsType <NotFoundResult>(result.Result); }
public async void DeleteProduct_NotEqualProductForId_ReturnBadRequest(int Id) { _mock.Setup(x => x.GetById(Id)); var product = await _productApiController.DeleteProduct(Id); _mock.Verify(x => x.GetById(Id), Times.Once); var requestObjectResult = Assert.IsType <BadRequestObjectResult>(product); Assert.Equal("Product not find", requestObjectResult.Value); }
public async void DeleteProduct_ProductIsNull_ReturnNotFound(int Id) { Product product = null; _mockRepository.Setup(x => x.GetById(Id)).ReturnsAsync(product); var result = await _controller.DeleteProduct(Id); Assert.IsAssignableFrom <NotFoundResult>(result.Result); }
public void DeleteProduct_ShouldReturn204StatusCode() { _mockHelper.Mock.Setup(x => x.Delete(5)).Returns(new ResultModel <Product>(null, 204)); var result = _apiController.DeleteProduct(5); Assert.IsType <StatusCodeResult>(result); var resultContent = (StatusCodeResult)result; Assert.Equal(204, resultContent.StatusCode); }
public void DeleteProductNotFound() { // Arrange const int testId = 10; var mockRepository = new Mock<IStoreAppRepository>(); var mockSet = new Mock<DbSet<Product>>(); mockRepository.Setup(x => x.Products).Returns(mockSet.Object); var controller = new ProductsApiController(mockRepository.Object); // Act IHttpActionResult actionResult = controller.DeleteProduct(testId).Result; // Assert Assert.IsInstanceOfType(actionResult, typeof (NotFoundResult)); }
public void DeleteProductOkResult() { // Arrange const int testId = 10; var data = new List<Product> {new Product {ProductID = testId}, new Product {ProductID = testId + 1}}.AsQueryable(); var mockSet = new Mock<DbSet<Product>>(); mockSet.As<IQueryable<Product>>().Setup(m => m.Provider).Returns(data.Provider); mockSet.As<IQueryable<Product>>().Setup(m => m.Expression).Returns(data.Expression); mockSet.As<IQueryable<Product>>().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As<IQueryable<Product>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockRepository = new Mock<IStoreAppRepository>(); mockRepository.Setup(x => x.Products).Returns(mockSet.Object); var controller = new ProductsApiController(mockRepository.Object); // Act IHttpActionResult actionResult = controller.DeleteProduct(testId).Result; // Assert Assert.IsInstanceOfType(actionResult, typeof (OkResult)); }