public void ShouldThrowExceptionWhenGetRecentPostsFailsOnPostsLookup() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetRecent(It.IsAny<Expression<Func<Post, bool>>>(), 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.GetRecentPosts(5)); }
public void ShouldReturnEmptyListWhenGetRecentPostsFoundNoRecords() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetRecent(It.IsAny<Expression<Func<Post, bool>>>(), 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.GetRecentPosts(5); Assert.AreEqual(0, result.Count); }
public void ShouldThrowExceptionWhenGetPostsFailsOnMediaLookup() { var post = new Post { PostId = 1, PostLikes = _postLikes.Where(a => a.PostId == 1).ToList(), PostContents = _postContents.Where(a => a.PostId == 1).ToList(), Tags = _tags.Where(a => a.TagId != 3).ToList(), PostTitle = "Foo", PostMessage = "Lorem Ipsum Dolor", UserId = 1, User = new User { UserId = 1, UserName = "******", PictureId = 1, BackgroundId = 1 } }; _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetRecent(It.IsAny<Expression<Func<Post, bool>>>(), 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)) .Throws(new Exception()); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.GetRecentPosts(5)); }
public void ShouldGetRecentPosts() { var post = new Post { PostId = 1, PostLikes = _postLikes.Where(a => a.PostId == 1).ToList(), PostContents = _postContents.Where(a => a.PostId == 1).ToList(), Tags = _tags.Where(a => a.TagId != 3).ToList(), PostTitle = "Foo", PostMessage = "Lorem Ipsum Dolor", UserId = 1, User = new User { UserId = 1, UserName = "******" } }; _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetRecent(It.IsAny<Expression<Func<Post, bool>>>(), 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.GetRecentPosts(5); Assert.AreEqual(1, result.Count); }
public void ShouldThrowExceptionWhenGetPostsFailsOnPostContentsLookup() { var post = _posts.FirstOrDefault(a => a.PostId == 1); _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetRecent(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<int>())) .Returns(new List<Post> { post }); _postContentRepository = new Mock<IPostContentRepository>(); _postContentRepository.Setup(a => a.Find(It.IsAny<Expression<Func<PostContent, bool>>>(), true)) .Throws(new Exception()); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.GetRecentPosts(5)); }