public NewAnswerTest() { _handler = new PostHandler(_questionRepository.Object, _answerRepository.Object); _validCommand = new NewAnswerCommand { Text = "Go tem crescido bastante.", User = "******", QuestionId = Guid.NewGuid() }; }
public async Task <ActionResult> AnswerPost( [FromBody] NewAnswerCommand command) { var result = await _bus.SendCommand(command); if (!result.Sucess) { return(BadRequest(result)); } return(Ok(result)); }
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); }
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); }
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)); }