Exemple #1
0
        public void DeleteOrder_ReturnNoContent(int id)
        {
            _deleteCommandLogger = new Mock <ILogger <DeleteOrderCommandHandler> >();
            _orderRepoMock.Setup(p => p.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_order);
            //GET QueryHandler
            _deleteOrderCommandHandler = new DeleteOrderCommandHandler(_orderRepoMock.Object, _mapper, _deleteCommandLogger.Object);
            _mockMediatr.Setup(m => m.Send(It.IsAny <DeleteOrderCommand>(), It.IsAny <CancellationToken>()))
            .Returns(async() =>
                     await _deleteOrderCommandHandler.Handle(new DeleteOrderCommand(),
                                                             new CancellationToken()));


            _orderRepoMock.Setup(p => p.DeleteAsync(It.IsAny <Order>()));

            var orders = _controller.DeleteOrder(id);

            if (orders.Result is NoContentResult okObject)
            {
                Assert.AreEqual(okObject.StatusCode, (int)HttpStatusCode.NoContent);
            }
            else
            {
                Assert.Fail();
            }
        }
Exemple #2
0
        public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new DeleteOrderCommandHandler(It.IsAny <IDeletableEntityRepository <Order> >());

            // Act & Assert
            await Should.ThrowAsync <ArgumentException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
 public DeleteOrderCommandHandlerTest()
 {
     orderRepository = new Mock <IOrderRepository>();
     bus             = new Mock <IBus>();
     command         = new DeleteOrderCommand(orderId);
     commandHandler  = new DeleteOrderCommandHandler(orderRepository.Object, bus.Object);
     orderItems      = new List <OrderItem> {
         new OrderItem(), new OrderItem()
     };
 }
Exemple #4
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new DeleteOrderCommand {
                Id = 133
            };
            var sut = new DeleteOrderCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Exemple #5
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowFailedEntityAlreadyDeletedException()
        {
            // Arrange
            var command = new DeleteOrderCommand {
                Id = 2
            };
            var sut = new DeleteOrderCommandHandler(this.deletableEntityRepository);

            var order = await this.deletableEntityRepository
                        .GetByIdWithDeletedAsync(1);

            this.deletableEntityRepository.Delete(order);
            await this.deletableEntityRepository.SaveChangesAsync();

            // Act & Assert
            await Should.ThrowAsync <EntityAlreadyDeletedException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Exemple #6
0
        public async Task Handle_GivenValidRequest_ShouldDeleteOrder()
        {
            // Arrange
            var command = new DeleteOrderCommand {
                Id = 1
            };
            var sut = new DeleteOrderCommandHandler(this.deletableEntityRepository);

            // Act
            var orderId = await sut.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            orderId.ShouldBe(1);

            var modifiedOrder = await this.dbContext.Orders
                                .SingleOrDefaultAsync(x => x.Id == orderId);

            modifiedOrder.IsDeleted.ShouldBe(true);
        }
Exemple #7
0
        public async Task DeleteAsync()
        {
            var dataAccess = new OrderDataAccess(this.Context);
            //Act
            var sutCreate    = new CreateOrderCommandHandler(dataAccess);
            var resultCreate = await sutCreate.Handle(new CreateOrderCommand
            {
                Data = OrderTestData.OrderDataDTO
            }, CancellationToken.None);


            //Act
            var sutDelete     = new DeleteOrderCommandHandler(dataAccess);
            var outcomeDelete = await sutDelete.Handle(new DeleteOrderCommand
            {
                Id = resultCreate.Data.Id
            }, CancellationToken.None);

            //Assert
            Assert.IsTrue(outcomeDelete.Succeeded);
        }
        public async void Deletes_Order_Successfully()
        {
            //Arrange
            var order = Context.Orders.First();

            OperationsRepository.Setup(x => x.Delete(It.IsAny<DateTime>(), order.UserId)).ReturnsAsync(true).Verifiable();
            Mediator.Setup(x => x.Send(It.IsAny<DeleteOrderCommand>(), new CancellationToken()))
                .ReturnsAsync(Unit.Value);

            //Act
            var deleteOrderCommand = new DeleteOrderCommand(order.Client, order);
            var handler = new DeleteOrderCommandHandler(Context, OperationsRepository.Object);
            var result = await handler.Handle(deleteOrderCommand, new CancellationToken());

            //Assert
            result.Should()
                .BeOfType<Unit>()
                .Equals(Unit.Value);
            OperationsRepository.Verify();

            DbContextFactory.Destroy(Context);
        }