public void ShouldReturnEmptyListWhenGetPostsByTagFoundNoRecords() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetPostsByTag(It.IsAny<string>(), It.IsAny<int>())) .Returns(new List<Post>()); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.GetPostsByTag("lorem"); Assert.AreEqual(0, result.Count); }
public void ShouldThrowExceptionWhenGetPostsByTagFails() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetPostsByTag(It.IsAny<string>(), It.IsAny<int>())) .Throws(new Exception()); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.GetPostsByTag("lorem")); }
public void ShouldGetPostsByTag() { var post = _posts.FirstOrDefault(a => a.PostId == 1); _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetPostsByTag(It.IsAny<string>(), It.IsAny<int>())) .Returns(new List<Post> { post }); var postContents = _postContents.Where(a => a.PostId == 1).ToList(); _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Returns(postContents); _mediaRepository = new Mock<IMediaRepository>(); _mediaRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Media, bool>>>(), false)) .Returns(new List<Media> { new Media { MediaId = 1 } }); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.GetPostsByTag("lorem"); Assert.AreEqual(1, result.Count); Assert.AreEqual("lorem", result[0].Tags[0].TagName.ToLower()); }