示例#1
0
        public void UpdateOrder_ReturnNoContent()
        {
            _updateCommandLogger = new Mock <ILogger <UpdateOrderCommandHandler> >();
            _orderRepoMock.Setup(p => p.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_order);

            //GET QueryHandler
            _updateOrderCommandHandler = new UpdateOrderCommandHandler(_orderRepoMock.Object, _mapper, _updateCommandLogger.Object);
            _mockMediatr.Setup(m => m.Send(It.IsAny <UpdateOrderCommand>(), It.IsAny <CancellationToken>()))
            .Returns(async() =>
                     await _updateOrderCommandHandler.Handle(new UpdateOrderCommand(),
                                                             new CancellationToken()));


            _orderRepoMock.Setup(p => p.UpdateAsync(It.IsAny <Order>()));
            var orders = _controller.UpdateOrder(_updateOrderCommand);

            if (orders.Result is NoContentResult okObject)
            {
                Assert.Pass();
            }
            else
            {
                Assert.Fail();
            }
        }
示例#2
0
        public async Task Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new UpdateOrderCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
示例#3
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new UpdateOrderCommand
            {
                Id          = 500,
                Description = "NewDesc",
                Quantity    = "321",
                Price       = "123",
                Status      = "Tested",
            };

            var sut = new UpdateOrderCommandHandler(this.deletableEntityRepository);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
示例#4
0
        public async Task Handle_GivenValidRequest_ShouldReturnOrderId()
        {
            // Arrange
            var command = new UpdateOrderCommand
            {
                Id          = 1,
                Description = "NewDesc",
                Quantity    = "321",
                Status      = "Tested",
            };

            var sut = new UpdateOrderCommandHandler(this.deletableEntityRepository);

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

            // Assert
            var order = await this.dbContext.Orders.SingleOrDefaultAsync(x => x.Id == id);

            order.ShouldNotBeNull();
            order.Description.ShouldBe("NewDesc");
            order.Quantity.ShouldBe(321);
            order.Status.ShouldBe("Tested");
        }
示例#5
0
 public UpdateOrderCommandHandlerTests()
 {
     _repository = A.Fake <IRepository <Order> >();
     _testee     = new UpdateOrderCommandHandler(_repository);
 }
示例#6
0
 public UpdateOrderCommandHandlerTests()
 {
     _orderRepository = A.Fake <IOrderRepository>();
     _testee          = new UpdateOrderCommandHandler(_orderRepository);
 }