public async Task AddReply_ShouldReturnNotFoundIfQuestionNotExists() { var questionRepository = new QuestionRepositoryBuilder().Build(); var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository) .Build(); var okResult = await questionController.AddReply(_replyModel, 1); Assert.IsInstanceOfType(okResult, typeof(NotFoundResult)); }
public async Task AddReply_ShouldReturnBadRequestIfReplyModelIsNotSend() { var questionRepository = new QuestionRepositoryBuilder().Build(); var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository) .Build(); var badRequestResult = await questionController.AddReply(null, 1); Assert.IsInstanceOfType(badRequestResult, typeof(BadRequestResult)); }
public async Task AddReply_ShouldAddReplyToQuestion() { var questionRepository = new QuestionRepositoryBuilder().Build(); var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository) .Build(); var savedQuestion = (await questionController.Add(_questionModel)).Cast <CreatedAtRouteResult, Question>(); var okResult = await questionController.AddReply(_replyModel, savedQuestion.Id); Assert.IsInstanceOfType(okResult, typeof(CreatedAtRouteResult)); }
public async Task GetUnanswered_ShouldReturnUnanswered() { var questionRepository = new QuestionRepositoryBuilder().Build(); var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository) .Build(); var savedQuestion = (await questionController.Add(_questionModel)).Cast <CreatedAtRouteResult, Question>(); await questionController.Add(_questionModel2); await questionController.AddReply(_replyModel, savedQuestion.Id); var okResult = await questionController.GetUnanswered(); var questions = okResult.Cast <OkObjectResult, List <QuestionModel> >(); Assert.IsInstanceOfType(okResult, typeof(OkObjectResult)); Assert.AreEqual(1, questions.Count); Assert.IsFalse(questions.TrueForAll(q => q.Replies.Count > 0)); }