Exemplo n.º 1
0
        public void Validar_NomeAluno_Caracteres(int?qtdCaracteres)
        {
            string nomeAluno = "";

            if (qtdCaracteres != null)
            {
                nomeAluno = new string('a', Convert.ToInt32(qtdCaracteres));
            }

            var aluno = new AlunoRequestModel()
            {
                NomeAluno = nomeAluno,
                Id        = 0,
                CPF       = "099.536.159-26",
                Email     = "*****@*****.**",
                Telefone  = "47991085345"
            };

            var ex = Assert.ThrowsAsync <ValidationException>(async() => await _alunoService.Create(aluno));

            if (qtdCaracteres == null)
            {
                ex.Result.Message.Should().Contain("Nome de aluno está nulo.");
            }
            else if (qtdCaracteres == 51)
            {
                ex.Result.Message.Should().Contain("Nome do aluno deve conter no máximo 50 caracteres.");
            }
            else if (qtdCaracteres == 2)
            {
                ex.Result.Message.Should().Contain("Nome do aluno precisa no minimo 3 caracteres.");
            }
        }
        public async Task Salvar_Create()
        {
            var alunoRequest = new AlunoRequestModel()
            {
                NomeAluno = "Mario",
                Email     = "*****@*****.**",
                CPF       = "099.536.159-26",
                Telefone  = "47991085945",
                Id        = 1
            };

            await _alunoService.Create(alunoRequest);

            await _alunoRepository.Received(1).Create(Arg.Any <AlunoEntity>());
        }
Exemplo n.º 3
0
        public async Task <ActionResult <CreateAlunoCommand> > Create(CreateAlunoCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            await _alunoService.Create(_mapper.Map <Aluno>(command));

            return(CustomResponse(command));
        }
        public async Task <IActionResult> Create([FromBody] AlunoRequestModel alunoRequest)
        {
            try
            {
                int id = await _alunoService.Create(alunoRequest);

                return(CreatedAtRoute(alunoRequest, id));
            }
            catch (AlunoException ex)
            {
                return(BadRequest(ex.Errors));
            }
            catch (DbUpdateException ex)
            {
                return(StatusCode(500, ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(400, ex.Message));
            }
        }