public void When_Product_NotFound() { UpdateProductStockInput input = new UpdateProductStockInput { ProductCode = "P1", Quantity = 10 }; Assert.Throws <ProductNotFoundException>(() => productService.UpdateProductStock(input)); }
public void When_Quantity_IsLessThanZero() { UpdateProductStockInput input = new UpdateProductStockInput { ProductCode = "P1", Quantity = -10 }; Assert.Throws <InvalidQuantityException>(() => productService.UpdateProductStock(input)); }
public void When_UpdateProductStock_IsSuccessful() { Product product = new Product("P1", 100, 1000); mockProductRepository.Setup(x => x.GetProduct("P1")).Returns(product); UpdateProductStockInput input = new UpdateProductStockInput { ProductCode = "P1", Quantity = 10 }; Assert.DoesNotThrow(() => productService.UpdateProductStock(input)); mockProductRepository.Verify(x => x.UpdateProductStock(It.IsAny <UpdateProductStockRequest>()), Times.Once()); }
public async Task <IServiceResult <int> > UpdateStock(UpdateProductStockInput input) { var product = await _databaseContext.Products.FindAsync(input.Id); if (product is null) { return(ServiceResult <int> .NotFound()); } product.UpdateStock(input.Value); await _databaseContext.SaveChangesAsync(); return(ServiceResult <int> .Ok(product.Id)); }
public void UpdateProductStock(UpdateProductStockInput updateProductStockInput) { if (updateProductStockInput.Quantity <= 0) { throw new InvalidQuantityException(); } var product = _productRepository.GetProduct(updateProductStockInput.ProductCode); if (product == null) { throw new ProductNotFoundException(); } _productRepository.UpdateProductStock(new UpdateProductStockRequest(updateProductStockInput.ProductCode, product.Stock - updateProductStockInput.Quantity)); }
public async Task <IServiceResult <int> > Put(UpdateProductStockInput input) => await _updateProductService.UpdateStock(input);