public void ShouldThrowExceptionWhenGetCommentReplyFails() { _commentsRepository = new Mock<ICommentRepository>(); _commentsRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Comment, bool>>>(), It.IsAny<Func<IQueryable<Comment>, IOrderedQueryable<Comment>>>(), It.IsAny<string>())) .Throws(new Exception()); _userRepository = new Mock<IUserRepository>(); _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object); Assert.Throws<BlogException>(() => _commentsLogic.GetReplies(5)); }
public void ShouldGetCommentReplies() { var expected = _comments.Where(a => a.ParentCommentId == 5).ToList(); _commentsRepository = new Mock<ICommentRepository>(); _commentsRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Comment, bool>>>(), It.IsAny<Func<IQueryable<Comment>, IOrderedQueryable<Comment>>>(), It.IsAny<string>())) .Returns(expected); _userRepository = new Mock<IUserRepository>(); _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object); var results = _commentsLogic.GetReplies(5); Assert.NotNull(results); Assert.NotNull(results[0].ParentCommentId); Assert.IsNull(results[0].PostId); Assert.AreEqual(1, results.Count); }