Exemplo n.º 1
0
        public ClienteController(IClienteRepository clienteRepository,
                                 ICommandHandler <Command> commandHandler,
                                 IClienteMongoDbRepository mongoRepository
                                 )
        {
            _clienteRepository = clienteRepository;
            _commandHandler    = commandHandler;
            _mongoRepository   = mongoRepository;
            if (_mongoRepository.GetCustomers().Count == 0)
            {
                var customerCmd = new CriarClienteCommand
                {
                    Nome      = "George Michaels",
                    Email     = "*****@*****.**",
                    Idade     = 23,
                    Telefones = new List <CriarTelefoneCommand>
                    {
                        new CriarTelefoneCommand {
                            Type = Model.Enums.TipoTelefone.CELLPHONE, AreaCode = 123, Number = 7543010
                        }
                    }
                };

                _commandHandler.Execute(customerCmd);
            }
        }
        public async Task DeveRetornarErroSeNomeJaExisteNoBanco()
        {
            var handler = new ClienteCommandHandler(_clienteRepository, _mediator);
            var command = new CriarClienteCommand(_helperEntitiesTest.Nome.Nome);

            var retorno = await handler.Handle(command, new CancellationToken());

            Assert.Equal(Guid.Empty, retorno);
        }
Exemplo n.º 3
0
 private Cliente(CriarClienteCommand command) : base(command.ID)
 {
     Endereco     = command.Endereco;
     Cidade       = command.Cidade;
     CpfCnpj      = command.CpfCnpj;
     Email        = command.Email;
     PrimeiroNome = command.PrimeiroNome;
     UltimoNome   = command.UltimoNome;
 }
Exemplo n.º 4
0
        public Cliente(CriarClienteCommand command)
        {
            ValidarParametros(command.Cpf, command.Nome);

            Cpf   = command.Cpf;
            Nome  = command.Nome;
            Email = command.Email;

            AdicionarTelefones(command);
            Endereco = new Endereco(command.Endereco);
        }
Exemplo n.º 5
0
        public void CriarCliente(CriarClienteCommand criarClienteCommand)
        {
            ValidacaoLogica.IsTrue <ValidacaoException>(criarClienteCommand is null, "Comando de criar cliente não pode ser nulo.");

            var cliente = clientesRepository.ObterUm(x => x.Cpf == criarClienteCommand.Cpf);

            ValidacaoLogica.IsFalse <ValidacaoException>(cliente is null, "Já existe um cliente para esse CPF.");

            cliente = new Domain.Entities.Cliente(criarClienteCommand);

            clientesRepository.Adicionar(cliente);

            unitOfWork.SaveChanges();
        }
Exemplo n.º 6
0
 public Task <IActionResult> Post([FromBody] CriarClienteCommand customer)
 {
     customer.Id = Guid.NewGuid();
     return(Task.Run(async() =>
     {
         IActionResult result = NotFound();
         bool created = await _customerService.IssueCommandAsync(customer);
         if (created)
         {
             result = CreatedAtRoute("GetCustomer", new { id = customer.Id }, customer);
         }
         return result;
     }));
 }
Exemplo n.º 7
0
        public void DeveRetornarSucesso()
        {
            //arrange
            var notificacao = new NotificationList();
            var command     = new CriarClienteCommand("Nome", "*****@*****.**", "62347448005", Enums.TipoDocumento.Cpf,
                                                      Enums.Sexo.Masculino, DateTime.Now, "Rua", "Bairro", "127-A", "Cidade", Enums.TipoEndereco.Comercial);

            this.emailService.Setup(service => service.Send(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));

            //act
            var handler = new ClienteHandler(this.clienteRepositoryMock.Object, this.emailService.Object, notificacao);
            var result  = handler.Handle(command);

            //assert
            result.Sucess.Should().BeTrue();
        }
Exemplo n.º 8
0
        private void AdicionarTelefones(CriarClienteCommand command)
        {
            var telefones = new List <Telefone>();

            if (command.Telefones is null)
            {
                Telefones = telefones;
                return;
            }

            foreach (var telefone in command.Telefones)
            {
                telefones.Add(new Telefone(telefone));
            }

            Telefones = telefones;
        }
Exemplo n.º 9
0
        public CommandResult Criar(CriarClienteCommand command)
        {
            try
            {
                command.Validate();
                if (command.Invalid)
                {
                    return(CommandResult.Invalid(command.Notifications.ToNotificationsString()));
                }


                Cliente cliente = Cliente.Criar(
                    DataString.FromString(command.CPF_CNPJ),
                    DataString.FromString(command.NomeCompleto_RazaoSocial),
                    DataString.FromString(command.Fantasia),
                    DataString.FromNullableString(command.Insc_Estadual),
                    DataString.FromNullableString(command.Logradouro),
                    DataString.FromNullableString(command.Endereco),
                    DataString.FromNullableString(command.Bairro),
                    DataString.FromNullableString(command.Complemento),
                    DataString.FromNullableString(command.Cidade),
                    DataString.FromNullableString(command.CEP),
                    DataString.FromNullableString(command.UF),
                    DataString.FromNullableString(command.Telefones),
                    DataString.FromNullableString(command.Funcao),
                    command.Flag_Ativo,
                    command.Email,
                    DataString.FromNullableString(command.Observacao),
                    DataString.FromNullableString(command.Referencia));


                dataContext.Add(cliente);
                dataContext.SaveChanges();


                return(CommandResult.Valid());
            }
            catch (Exception ex)
            {
                return(CommandResult.Invalid(ex.Message));
            }
        }
        public async Task Quando_Cliente_Nao_Existe_Gravar_E_Retornar_Novo_Cliente()
        {
            //Arrange

            var cliente = new Cliente
            {
                Documento            = "40671663895",
                Nome                 = "Carlos Eduardo",
                Senha                = "123456",
                IdentificadorCliente = Guid.NewGuid()
            };

            var clienteCommand = new CriarClienteCommand
            {
                Documento = "40671663895",
                Nome      = "Carlos Eduardo",
                Senha     = "123456",
            };

            var cancellationToken = CancellationToken.None;

            var clienteRepositorioMock = new Mock <IClienteRepositorio>(MockBehavior.Strict);
            var mapperMock             = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <Cliente>(clienteCommand)).Returns(cliente);
            clienteRepositorioMock.Setup(x => x.ObterClientePorDocumentoAsync("40671663895", cancellationToken)).ReturnsAsync((Cliente)null);
            clienteRepositorioMock.Setup(x => x.CriarClienteAsync(cliente, cancellationToken)).ReturnsAsync(cliente);

            var handler = new CriarClienteCommandHandler(clienteRepositorioMock.Object, mapperMock.Object);

            // ACT

            var result = await handler.Handle(clienteCommand, cancellationToken);

            // Assert

            Assert.NotNull(result);
            Assert.Equal(cliente.Documento, result.Documento);
            Assert.Equal(cliente.Nome, result.Nome);
            Assert.IsType <CriarClienteCommandResult>(result);
        }
 public void CriarCliente(CriarClienteCommand criarClienteCommand)
 {
     clientesAppService.CriarCliente(criarClienteCommand);
 }
Exemplo n.º 12
0
 public IActionResult Criar(
     [FromServices] IClienteService service,
     [FromBody] CriarClienteCommand command)
 {
     return(Result(service.Criar(command)));
 }
Exemplo n.º 13
0
 public async Task <IActionResult> CadastrarCliente([FromBody] CriarClienteCommand command)
 {
     return(Ok(await _mediator.Send(command)));
 }
Exemplo n.º 14
0
 public GenericoClienteCommandResult Criar([FromBody] CriarClienteCommand command, [FromServices] ClienteHandler handler)
 {
     return((GenericoClienteCommandResult)handler.Handle(command));
 }
Exemplo n.º 15
0
 public CriarClienteTests()
 {
     _command   = new CriarClienteCommand();
     _validator = new CriarClienteValidation();
 }
Exemplo n.º 16
0
 public static Cliente Criar(CriarClienteCommand command,
                             IValidator <CriarClienteCommand> validator)
 {
     validator.ValidateCommand(command);
     return(new Cliente(command));
 }
Exemplo n.º 17
0
        public IActionResult Post([FromBody] CriarClienteCommand customer)
        {
            _commandHandler.Execute(customer);

            return(CreatedAtRoute("GetCliente", new { id = customer.Id }, customer));
        }