Пример #1
0
    public async Task GivenWeAreUpdatingAnOrder_WhenOrderDoesNotExist_ThenShouldReturnNotFound()
    {
        _commandBrokerMoq.Setup(x => x.SendAsync(It.IsAny <UpdateOrder>()))
        .ReturnsAsync(new CommandResult <Order>(CommandOutcome.NotFound));
        var controller = new OrderCommandController(_commandBrokerMoq.Object, _mapper);

        var actionResult = await controller.Update(Orders.Order1);

        var notFoundResult = actionResult as NotFoundResult;

        Assert.NotNull(actionResult);
        Assert.NotNull(notFoundResult);
    }
Пример #2
0
    public async Task GivenWeAreUpdatingAnOrder_WhenWeEncounterAConcurrencyIssue_ThenShouldReturnConflict()
    {
        _commandBrokerMoq.Setup(x => x.SendAsync(It.IsAny <UpdateOrder>()))
        .ReturnsAsync(new CommandResult <Order>(CommandOutcome.Conflict));
        var controller = new OrderCommandController(_commandBrokerMoq.Object, _mapper);

        var actionResult = await controller.Update(Orders.Order1);

        var conflictResult = actionResult as ConflictResult;

        Assert.NotNull(actionResult);
        Assert.NotNull(conflictResult);
    }
Пример #3
0
    public async Task GivenWeAreUpdatingAnOrder_WhenSuccessful_ThenUpdatedEntityShouldBeReturned()
    {
        var orderIn    = Orders.Order1;
        var orderOut   = _mapper.Map <Order>(orderIn);
        var controller = new OrderCommandController(_commandBrokerMoq.Object, _mapper);

        _commandBrokerMoq.Setup(x => x.SendAsync(It.IsAny <UpdateOrder>()))
        .ReturnsAsync(new CommandResult <Order>(CommandOutcome.Accepted, orderOut));

        var actionResult = await controller.Update(orderIn);

        var okResult = Assert.IsType <OkObjectResult>(actionResult);

        Assert.NotNull(actionResult);
        Assert.NotNull(okResult);
        Assert.Equal(orderIn.Id, ((DTO.Write.Order)okResult.Value !).Id);
    }