Exemplo n.º 1
0
        public void DadoUmaContainvalida_IsInvalid()
        {
            var command = new CreateContaCommand("");

            command.Validate();

            Assert.AreEqual(command.Invalid, true);
        }
Exemplo n.º 2
0
        public void DadoUmaContaValida_IsValid()
        {
            var command = new CreateContaCommand("123456");

            command.Validate();

            Assert.AreEqual(command.Valid, true);
        }
Exemplo n.º 3
0
        public void DadoUmaContaVazia_IsInvalid()
        {
            var command = new CreateContaCommand("");

            var handler = new CreateContaHandler(new FakeRepositoryConta());
            var result  = handler.Handle(command).Result;

            Assert.AreNotEqual(0, result.Notifications.Count);
            Assert.AreEqual(true, result.Invalid);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateConta([FromBody] CreateContaCommand command)
        {
            var result = await _createContaHandler.Handle(command);

            if (result.Notifications.Any())
            {
                return(BadRequest(result.Notifications));
            }

            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Post(CreateContaCommand command)
        {
            try
            {
                await contaApplicationService.Add(command);

                return(Ok(new { message = "Conta cadastrada com sucesso!" }));
            }
            catch (ValidationException e)
            {
                return(BadRequest(ValidationAdapter.Parse(e.Errors)));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
 public async Task Add(CreateContaCommand command)
 {
     await mediator.Send(command);
 }