Beispiel #1
0
        public async Task <IActionResult> DeleteAddress([FromRoute] Guid id, [FromBody] Guid addressId, [FromServices] AddressRemoveOperation operation)
        {
            var result = await operation.ExecuteAsync(new AddressRemove
            {
                UserId = id,
                Id     = addressId
            });

            if (result is Domain.OkResult)
            {
                return(NoContent());
            }

            if (result is ErrorResult error && error.ErrorCode.StartsWith("USR"))
            {
                if (error.ErrorCode == DomainError.UserError.UserNotFound.ErrorCode)
                {
                    return(NotFound(error));
                }

                return(UnprocessableEntity(error));
            }

            return(BadRequest(result));
        }
        public async Task Execute_Should_ReturnUserNotFound()
        {
            var address = _fixture.Create <AddressRemove>();

            _store.GetAsync(address.UserId, Arg.Any <CancellationToken>())
            .Returns(Task.FromResult((IUserAggregationRoot)null));

            var result = await _operation.ExecuteAsync(address, CancellationToken.None);

            result.IsSuccess.Should().BeFalse();
            result.Value.Should().BeNull();
            result.ErrorCode.Should().NotBeNullOrEmpty();
            result.Description.Should().NotBeNullOrEmpty();
            result.Should().Be(DomainError.UserError.UserNotFound);

            await _store
            .Received(1)
            .GetAsync(address.UserId, Arg.Any <CancellationToken>());

            await _store
            .DidNotReceive()
            .SaveAsync(Arg.Any <IUserAggregationRoot>(), Arg.Any <CancellationToken>());
        }