示例#1
0
        public void InvalidCommand()
        {
            var command = new CreateAlunoCommand("Antonio Fracisco da Silva", "00000000000", DateTime.Now, "*****@*****.**", "0124");

            command.Validate();
            Assert.AreEqual(command.Valid, true);
        }
示例#2
0
        public void ValidCommand()
        {
            var command = new CreateAlunoCommand("", "", DateTime.Now, "", "");

            command.Validate();
            Assert.AreEqual(command.Valid, false);
        }
示例#3
0
        public void ValidHandler()
        {
            var command = new CreateAlunoCommand("Antonio Fracisco da Silva", "00000000000", DateTime.Now, "*****@*****.**", "0124");
            var handler = new AlunoHandler(new FakeAlunoRepository());
            var result  = (CommandResult)handler.Handle(command);

            Assert.AreEqual(result.Sucess, true);
        }
示例#4
0
        public void InvalidHandler()
        {
            var command = new CreateAlunoCommand("", "", DateTime.Now, "", "");
            var handler = new AlunoHandler(new FakeAlunoRepository());
            var result  = (CommandResult)handler.Handle(command);

            Assert.AreEqual(result.Sucess, false);
        }
示例#5
0
 public CommandResult Create(
     [FromBody] CreateAlunoCommand command,
     [FromServices] AlunoHandler handler
     )
 {
     //Gravando o usuário token da google
     command.RefUser = User.Claims.FirstOrDefault(x => x.Type == "user_id")?.Value;
     return((CommandResult)handler.Handle(command));
 }
示例#6
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));
        }
示例#7
0
        public async Task <IActionResult> Post(CreateAlunoCommand command)
        {
            try
            {
                await _alunoApplicationService.Add(command);

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