public void ShouldThrowExceptionWhenGetTopCommentsFails() { _commentsRepository = new Mock<ICommentRepository>(); _commentsRepository.Setup(a => a.GetTop(It.IsAny<Expression<Func<Comment, bool>>>(), It.IsAny<int>())).Throws(new Exception()); _userRepository = new Mock<IUserRepository>(); _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object); Assert.Throws<BlogException>(() => _commentsLogic.GetTopComments(2, 5)); }
public void ShouldGetTopComments() { var expected = _comments.Where(a => a.PostId == 2).ToList(); _commentsRepository = new Mock<ICommentRepository>(); _commentsRepository.Setup(a => a.GetTop(It.IsAny<Expression<Func<Comment, bool>>>(), It.IsAny<int>())) .Returns(expected); _userRepository = new Mock<IUserRepository>(); _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object); var results = _commentsLogic.GetTopComments(2, 5); Assert.NotNull(results); Assert.AreEqual(2, results.Count); Assert.AreEqual(2, results[0].PostId); Assert.AreEqual(2, results[1].PostId); }