Exemple #1
0
 public NewAnswerTest()
 {
     _handler      = new PostHandler(_questionRepository.Object, _answerRepository.Object);
     _validCommand = new NewAnswerCommand {
         Text = "Go tem crescido bastante.", User = "******", QuestionId = Guid.NewGuid()
     };
 }
Exemple #2
0
        public async Task <ActionResult> AnswerPost(
            [FromBody] NewAnswerCommand command)
        {
            var result = await _bus.SendCommand(command);

            if (!result.Sucess)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Exemple #3
0
        public async Task Notify_When_User_Invalid()
        {
            var invalidCommand = new NewAnswerCommand {
                Text = "Go tem crescido bastante.", User = "******"
            };

            var result = await _handler.Handle(invalidCommand);

            var notifications = (List <string>)result.Data;
            var notificationWithUserMinChar = notifications.Where(n => n == Message.PostUserMinChar).Any();

            Assert.True(notificationWithUserMinChar);
        }
Exemple #4
0
        public async Task Notify_When_Text_Invalid()
        {
            var invalidCommand = new NewAnswerCommand {
                Text = "Oi?", User = "******"
            };

            var result = await _handler.Handle(invalidCommand);

            var notifications = (List <string>)result.Data;
            var notificationWithTextMinChar = notifications.Where(n => n == Message.PostTextMinChar).Any();

            Assert.True(notificationWithTextMinChar);
        }
Exemple #5
0
        public async Task <CommandResult> Handle(NewAnswerCommand command, CancellationToken ct = default(CancellationToken))
        {
            // Validar comando (Fail Fast Validation)
            command.Validate();
            if (command.Invalid)
            {
                return(new CommandResult(Message.NewAnswerInvalidCommand, command.Notifications));
            }

            // Verifica se a pergunta existe
            var question = await _questionRepository.GetById(command.QuestionId.Value);

            if (question == null)
            {
                return(new CommandResult(Message.QuestionNotFound));
            }

            // Criação da resposta
            var answer = new Answer(command.Text, command.User, command.QuestionId.Value);
            await _answerRepository.Insert(answer);

            // Retornar o resultado
            return(new CommandResult(Message.NewAnswerInsertedSucess, answer));
        }