public ActionResult <WholesalerBeer> UpdateStock(UpdateStockCommand command, [FromRoute] int stock) { command.Stock = stock; _wholesalerService.UpdateWholesalerBeer(command); return(Ok()); }
public void UpdateStock_Stock_IsOk() { UpdateStockCommand command = new UpdateStockCommand() { BeerId = 1, WholesalerId = 1, Stock = 9 }; using (var context = new BrasserieContext(ContextOptions)) { var wholesalerService = new WholesalerService(context); var actual = wholesalerService.UpdateWholesalerBeer(command); actual.Stock.Should().Be(9); } }
public void UpdateStock_StockIsNegative_ThrowException() { UpdateStockCommand command = new UpdateStockCommand() { BeerId = 1, WholesalerId = 1, Stock = -10 }; using (var context = new BrasserieContext(ContextOptions)) { var wholesalerService = new WholesalerService(context); Action action = () => wholesalerService.UpdateWholesalerBeer(command); action.Should().ThrowExactly <HttpBodyException>().WithMessage(ExceptionMessage.NEGATIVE_STOCK); } }
public WholesalerBeer UpdateWholesalerBeer(UpdateStockCommand command) { if (command == null) { throw new HttpBodyException(ExceptionMessage.COMMAND_IS_NULL); } var wholesalerBeer = _brasserieContext.WholesalerBeers .Find(command.BeerId, command.WholesalerId); if (command.Stock < 0) { throw new HttpBodyException(ExceptionMessage.NEGATIVE_STOCK); } wholesalerBeer.Stock = command.Stock; _brasserieContext.WholesalerBeers.Update(wholesalerBeer); return(wholesalerBeer); }
public Task <bool> Handle(UpdateStockCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } var stock = new Stock(message.Id, message.Name, message.Price); _stockRepository.Update(stock); if (Commit()) { _bus.RaiseEvent(new StockUpdatedEvent(stock.Id, stock.Name, stock.Price)); } return(Task.FromResult(true)); }