public void PostComment_WhenCalled_ShouldReturnOkResultWithNewTotalPageCount(int totalCount, int newTotalPageCount) { _unitOfWork.Setup( u => u.CommentRepository.Count(It.IsAny <Expression <Func <Comment, bool> > >())) .Returns(totalCount); var result = _controller.PostComment(new AnswerPostCommentViewModel(1, "comment")); Assert.That(result, Is.TypeOf <OkNegotiatedContentResult <int> >()); Assert.That((result as OkNegotiatedContentResult <int>).Content, Is.EqualTo(newTotalPageCount)); }
public void PostComment_WhenCalled_ShouldSaveCommentToDatabase() { var question = _context.AddTestQuestionToDatabase(); var answer = _context.AddTestAnswerToDatabase(question.Id); var viewModel = new AnswerPostCommentViewModel(answer.Id, "Comment"); var result = _controller.PostComment(viewModel); var comment = _contextAfterAction.Comments.Single(); Assert.That(comment.AnswerId, Is.EqualTo(answer.Id)); Assert.That(comment.Content, Is.EqualTo("Comment")); Assert.That((result as OkNegotiatedContentResult <int>).Content, Is.EqualTo(1)); }