예제 #1
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var request = new DeleteBasketRequest();
            await _mediator.Send(request);

            return(NoContent());
        }
예제 #2
0
        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);
        }
예제 #3
0
        public async Task <IActionResult> DeleteBasket(string basketId)
        {
            if (string.IsNullOrEmpty(basketId))
            {
                return(this.BadRequest());
            }

            await this.deleteBasket
            .Execute(DeleteBasketRequest.Create(basketId));

            return(Ok());
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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());
        }
예제 #7
0
        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);
        }
예제 #8
0
        /// <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;
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
 public async Task <BaseResponseDto <Boolean> > DeleteBasketAsync(DeleteBasketRequest request)
 {
     return(await _mediator.Send(request));
 }