public void ShouldThrowExceptionWhenSearchCommentFails() { _commentsRepository = new Mock<ICommentRepository>(); _commentsRepository.Setup(a => a.SearchComments(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Throws(new Exception("foo")); _userRepository = new Mock<IUserRepository>(); _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object); Assert.Throws<BlogException>(() => _commentsLogic.SearchComments("foo", 1, 1)); }
public void ShouldSearchComments() { _commentsRepository = new Mock<ICommentRepository>(); _commentsRepository.Setup(a => a.SearchComments(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(_comments); _userRepository = new Mock<IUserRepository>(); _commentsLogic = new CommentsLogic(_commentsRepository.Object, _userRepository.Object); var results = _commentsLogic.SearchComments("foo", 1, 1); Assert.NotNull(results); Assert.IsInstanceOf(typeof(List<Common.Contracts.Comment>), results); }