public async Task <IActionResult> Delete(Guid id) { var request = new DeleteBasketRequest(); await _mediator.Send(request); return(NoContent()); }
public async Task <BaseResponseDto <bool> > Handle(DeleteBasketRequest request, CancellationToken cancellationToken) { BaseResponseDto <Boolean> response = new BaseResponseDto <Boolean>(); try { var basket = await _repository.Where(p => p.Id == request.Id) .FirstOrDefaultAsync(cancellationToken: cancellationToken); if (basket != null) { var result = await _repository.Delete(basket); response.Data = result; if (!result) { response.Errors.Add("An error occurred while deleting data in database."); } } else { response.Errors.Add("No Basket for this Id was found."); } } catch (Exception exception) { Console.WriteLine(exception); response.Data = false; response.Errors.Add(exception.Message); } return(response); }
public async Task <IActionResult> DeleteBasket(string basketId) { if (string.IsNullOrEmpty(basketId)) { return(this.BadRequest()); } await this.deleteBasket .Execute(DeleteBasketRequest.Create(basketId)); return(Ok()); }
public async Task DeleteBasket_NullRequest_ThrowsException() { //Arrange var mock = DeleteBasketMock.Create(); var target = mock.Target; DeleteBasketRequest request = null; //Act async Task execute() => await target.Execute(request); //Assert await Assert.ThrowsAsync <ArgumentNullException>(execute); }
public async Task DeleteBasket_NullBasketId_ThrowsException() { //Arrange string basketId = null; var mock = DeleteBasketMock.Create(); var target = mock.Target; var request = DeleteBasketRequest.Create(basketId); //Act async Task execute() => await target.Execute(request); //Assert await Assert.ThrowsAsync <ArgumentException>(execute); }
public async Task GetAllBasketsTests_ValidRequest_RepositoryCalledOnce() { //Arrange var basketId = Guid.NewGuid().ToString(); var mock = DeleteBasketMock.Create(); var target = mock.Target; var request = DeleteBasketRequest.Create(basketId); //Act await target.Execute(request); //Assert mock.BasketsRepositoryMock.Verify(rep => rep.Delete(basketId), Times.Once()); }
public async Task Handle_ShouldNotCallDelete_WhenBasketDoesntExist() { var id = Guid.NewGuid(); var store = new Mock <IBasketStore>(); var handler = new DeleteBasketRequestHandler(store.Object); var request = new DeleteBasketRequest() { Id = Guid.NewGuid() }; await handler.Handle(request); store.Verify(v => v.Delete(id), Times.Never); }
/// <summary> /// Executes the delete basket use case. /// This execution triggers a domain event BasketDeleted in order to be consumed by the interested parties. /// </summary> /// <param name="request">The request with the basket data to delete.</param> public async Task Execute(DeleteBasketRequest request) { Ensure.IsNotNull(request); Ensure.IsNotNullOrEmpty(request.BasketId); try { await this.basketsRepository.Delete(request.BasketId); await this.ProduceBasketDeleted(request.BasketId); } catch (Exception ex) { this.logger.Error( $"{nameof(InsertBasket)}.{nameof(Execute)}", ex); throw; } }
public async Task Handle_ShouldCallDelete_WhenValid() { var id = Guid.NewGuid(); var store = new Mock <IBasketStore>(); store .Setup(s => s.GetById(It.IsAny <Guid>())) .Returns(new Models.Domain.Basket()); var handler = new DeleteBasketRequestHandler(store.Object); var request = new DeleteBasketRequest() { Id = id }; await handler.Handle(request); store.Verify(v => v.Delete(id), Times.Once); }
public async Task <BaseResponseDto <Boolean> > DeleteBasketAsync(DeleteBasketRequest request) { return(await _mediator.Send(request)); }