public async Task <IActionResult> UpdateSale([FromBody] SaleDTO sale) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (sale.Id <= 0) { return(BadRequest(sale.Id)); } var updateSaleCommand = new UpdateSaleCommand { Model = sale }; try { await _mediator.Send(updateSaleCommand); } catch (Exception) { _logger.LogWarning($"{sale.Id} {SalesConstants.UPDATE_SALE_CONFLICT}"); return(Conflict()); } _logger.LogInformation($"{sale.Id} {SalesConstants.UPDATE_SALE_SUCCESS}"); return(Ok(sale)); }
public async Task Handler_GivenValidData_ShouldUpdateSale() { // Arrange var sale = new SaleDTO { Id = 2, Date = new DateTime(2019, 01, 01), Amount = 600, }; var command = new UpdateSaleCommand { Model = sale }; // Act var handler = new UpdateSaleCommand.UpdateSaleCommandHandler(Context); await handler.Handle(command, CancellationToken.None); var entity = Context.Sales.Find(sale.Id); // Assert entity.ShouldNotBeNull(); entity.Date.ShouldBe(command.Model.Date); entity.Amount.ShouldBe(command.Model.Amount); }
public UpdateSaleCommandHandlerTest() { request = new UpdateSaleCommand(new SaleResource() { CityName = "Update", Price = 120, ProductId = "1", ProductName = "Update", UserName = "******", Id = 2 }); }
public async Task Handle_GivenInvalidSaleData_ThrowsException() { // Arrange var sale = new SaleDTO { Id = 99, Date = new DateTime(2019, 01, 01), Amount = 200, }; var command = new UpdateSaleCommand { Model = sale }; // Act var handler = new UpdateSaleCommand.UpdateSaleCommandHandler(Context); // Assert await Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None)); }
public Task UpdateSale(UpdateSaleCommand command, CancellationToken token) { throw new NotImplementedException(); }
//PUT : /api/Users/Update public async Task <ActionResult <IEnumerable <object> > > Update([FromBody] UpdateSaleRequestModel request) { var update = new UpdateSaleCommand(_context); return(Ok(await Task.Run(() => update.UpdateSale(request)))); }
public Task <Response <SaleDetailApiModel> > Handle(UpdateSaleCommand request, CancellationToken cancellationToken) { throw new NotImplementedException(); }