Exemplo n.º 1
0
        public PhoneAddOperationTest()
        {
            _fixture = new Fixture();
            _fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            _fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            _store     = Substitute.For <IUserAggregateStore>();
            _logger    = Substitute.For <ILogger <PhoneAddOperation> >();
            _mapper    = Substitute.For <IMapper <Domain.Common.Phone, Phone> >();
            _operation = new PhoneAddOperation(_store, _logger, _mapper);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddPhone([FromRoute] Guid id, [FromBody] PhoneResponse phone, [FromServices] PhoneAddOperation operation)
        {
            var result = await operation.ExecuteAsync(new PhoneAdd
            {
                UserId = id,
                Number = phone.Number
            });

            if (result is OkResult <PhoneResponse> ok)
            {
                return(Ok(new Phone
                {
                    Number = ok.Value.Number
                }));
            }

            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));
        }