protected async Task ConfirmDeleteAsync(bool deleteConfirmed) { try { if (deleteConfirmed) { if (Id == Guid.Empty) { return; } if (!await PostsLogic.DeletePostAsync(Id)) { RemoveDeletedPostFromPostsList(); } } } catch (UserException e) { Logger.LogError(e, e.Message); await ShowErrorMessageAsync(e.Message); } catch (Exception e) { Logger.LogError(e, e.Message); await ShowErrorMessageAsync(); } }
public async Task GetPostsAsync() { Posts = await PostsLogic.GetPostsAsync(); }
public void ShouldThrowExceptionWhenGetPopularPostsFailsOnPostsLookup() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetPopular(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.GetPopularPosts(5)); }
public void ShouldThrowExceptionWhenGetMorePostsByTagFailsOnPostsLookup() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetMorePostsByTag(It.IsAny<string>(), It.IsAny<int>(), 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.GetMorePostsByTag("foo", 10)); }
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()); }
public void ShouldGetPostsByCommunity() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetByCommunity(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(_posts); 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.GetPostsByCommunity(1); Assert.NotNull(result); Assert.IsInstanceOf(typeof(List<Common.Contracts.Post>), result); }
public void ShouldReturnEmptyListWhenSearchPostsFoundNoRecords() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.SearchPosts(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(_posts); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.SearchPosts("foo", 1, 1); Assert.AreEqual(0, result.Count); }
public void ShouldThrowExceptionWhenGetPostByIdFails() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>())) .Throws(new Exception()); 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>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.GetPost(1)); }
public void ShouldThrowExceptionWhenUpdatePostHasMoreThanOneVideo() { #region Variables var param = new Common.Contracts.Post { PostContents = new List<Common.Contracts.PostContent> { new Common.Contracts.PostContent { Media = new Common.Contracts.Media { MediaType = "video/mp4" } }, new Common.Contracts.PostContent { Media = new Common.Contracts.Media { MediaType = "video/avi" } } }, Tags = null, PostTitle = "Foo", PostMessage = "Lorem Ipsum Dolor", User = new Common.Contracts.User { Id = 1, UserName = "******" } }; #endregion _postRepository = new Mock<IPostRepository>(); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.UpdatePost(param)); }
public void ShouldThrowExceptionWhenUpdatePostFails() { #region Variables var param = new Common.Contracts.Post { PostContents = null, Tags = null, PostTitle = "Foo", PostMessage = "Lorem Ipsum Dolor", User = new Common.Contracts.User { Id = 1, UserName = "******" } }; #endregion _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Edit(It.IsAny<Post>())).Throws(new Exception()); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.UpdatePost(param)); }
public void ShouldUpdatePost() { #region Variables var dbResult = new Post { PostId = 3, PostLikes = null, PostContents = _postContents.Where(a => a.PostId == 1).ToList(), Comments = null, Tags = _tags.Where(a => a.TagId != 3).ToList(), PostTitle = "Foo", PostMessage = "Lorem Ipsum Dolor", UserId = 1, User = new User { UserId = 1, UserName = "******" } }; var param = new Common.Contracts.Post { PostContents = new List<Common.Contracts.PostContent> { new Common.Contracts.PostContent { Id = 1, PostContentTitle = "Foo", PostContentText = "Lorem Ipsum Dolor", PostId = 1, Media = new Common.Contracts.Media() }, new Common.Contracts.PostContent { Id = 2, PostContentTitle = "Bar", PostContentText = "Lorem Ipsum Dolor", PostId = 1, Media = new Common.Contracts.Media() } }, Tags = new List<Common.Contracts.Tag> { new Common.Contracts.Tag { TagId = 1, TagName = "lorem" }, new Common.Contracts.Tag { TagId = 2, TagName = "ipsum" } }, PostTitle = "Foo", PostMessage = "Lorem Ipsum Dolor", User = new Common.Contracts.User { Id = 1, UserName = "******" } }; #endregion _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Edit(It.IsAny<Post>())).Returns(new Post { PostId = 3 }); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>())) .Returns(new List<Post> { dbResult }); 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>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.UpdatePost(param); Assert.IsNotNull(result); Assert.AreEqual(3, result.Id); }
public void ShouldReturnTrueOnValidatePostContentsIfEmpty() { var param = new List<Common.Contracts.PostContent>(); _postRepository = new Mock<IPostRepository>(); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.ValidatePostContents(param); Assert.IsTrue(result); }
public void ShouldReturnCleanPostFromEntity() { #region param var param = new Post { Communities = new List<Community> { new Community { Leader = new User(), Members = new List<User>(), Posts = new List<Post>() } }, User = new User { BackgroundId = 1, PictureId = 2, CreatedCommunities = new List<Community>(), JoinedCommunities = new List<Community>(), Posts = new List<Post>() }, PostContents = new List<PostContent> { new PostContent { Media = new Media { MediaPath = "foo", ThumbnailPath = "foo" } } } }; #endregion _postRepository = new Mock<IPostRepository>(); _postContentRepository = new Mock<IPostContentRepository>(); _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.EntityToDtoPostCleanUp(param, 1); Assert.IsNotNull(result); Assert.IsNotNull(result.Communities); Assert.IsNotNull(result.User); Assert.IsNotNull(result.PostContents); Assert.IsNull(result.Communities[0].Leader); Assert.IsNull(result.Communities[0].Members); Assert.IsNull(result.Communities[0].Posts); Assert.IsNull(result.PostContents[0].Media.MediaPath); Assert.IsNull(result.PostContents[0].Media.ThumbnailPath); }
public void ShouldReturnCleanCommunitiesOnPrepareCommunities() { var param = new List<Common.Contracts.Community> { new Common.Contracts.Community { Leader = new Common.Contracts.User(), Members = new List<Common.Contracts.User>(), Posts = new List<Common.Contracts.Post>() }, new Common.Contracts.Community { Leader = new Common.Contracts.User(), Members = new List<Common.Contracts.User>(), Posts = new List<Common.Contracts.Post>() } }; _postRepository = new Mock<IPostRepository>(); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.PrepareCommunities(param); Assert.IsNotNull(result); Assert.IsNull(result[0].Leader); Assert.IsNull(result[0].Members); Assert.IsNull(result[0].Posts); Assert.IsNull(result[1].Leader); Assert.IsNull(result[1].Members); Assert.IsNull(result[1].Posts); }
public void ShouldSetPostContentsToNullWhenEmptyOnPostCleanUp() { var param = new Common.Contracts.Post { PostContents = null }; _postRepository = new Mock<IPostRepository>(); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.PostCleanUp(param); Assert.IsNotNull(result); Assert.IsNull(result.PostContents); }
public ArrayList Get() { return(PostsLogic.getNewestPosts(4)); }
public void ShouldSetCommunitiesToListPostWhenNullOnPostCleanUp() { var param = new Common.Contracts.Post { Communities = null }; _postRepository = new Mock<IPostRepository>(); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.PostCleanUp(param); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(List<Common.Contracts.Community>), result.Communities); }
public void ShouldReturnTrueOnDeletePostContent() { var post = new Post { PostId = 3, PostLikes = null, PostContents = _postContents.Where(a => a.PostId == 1).ToList(), Comments = null, 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.Delete(It.IsAny<Post>())); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), true)) .Returns(new List<Post> { post }); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.DeletePost(1); Assert.IsTrue(result); }
public void ShouldSearchPosts() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.SearchPosts(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(_posts); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.SearchPosts("foo", 1, 1); Assert.NotNull(result); Assert.IsInstanceOf(typeof(List<Common.Contracts.Post>), result); }
public void ShouldReturnFalseWhenDeletePostContentFoundNoRecord() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), true)) .Returns(new List<Post>()); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.DeletePost(1); Assert.IsFalse(result); }
public void ShouldThrowExceptionWhenSearchPostsFails() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.SearchPosts(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Throws(new Exception("foo")); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.SearchPosts("foo", 1, 1)); }
public void ShouldThrowExceptionWhenDeletePostContentFails() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), true)) .Throws(new Exception()); _postContentRepository = new Mock<IPostContentRepository>(); _mediaRepository = new Mock<IMediaRepository>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); Assert.Throws<BlogException>(() => _postsLogic.DeletePost(1)); }
public void ShouldThrowExceptionWhenGetPostsByCommunityFails() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetByCommunity(It.IsAny<int>(), It.IsAny<int>(), 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.GetPostsByCommunity(1)); }
public void ShouldFetchBackgroundPictureWhenGetPostsUserHasNoBackgroundPicture() { 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 = null, 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)) .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); Assert.NotNull(result[0].User.Background); }
public void ShouldReturnEmptyListWhenGetMorePostsByTagFoundNoRecords() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetMorePostsByTag(It.IsAny<string>(), It.IsAny<int>(), 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.GetMorePostsByTag("foo", 10); Assert.AreEqual(0, 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)); }
public void ShouldReturnEmptyListWhenGetPopularPostsFoundNoRecords() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetPopular(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.GetPopularPosts(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 ShouldGetMorePopularPosts() { 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.GetMorePopularPosts(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<int>(), 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.GetMorePopularPosts(5, 5); Assert.AreEqual(1, result.Count); }
public void ShouldGetPostById() { var post = _posts.FirstOrDefault(a => a.PostId == 1); _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>())) .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.GetPost(1); Assert.NotNull(result); Assert.AreEqual(1, result.Id); }
public void ShouldGetPostByIdWithUserBackground() { 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 = "******", BackgroundId = 1 } }; _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>())) .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.GetPost(1); Assert.NotNull(result); Assert.NotNull(result.User.Background); Assert.AreEqual(1, result.Id); }
public void ShouldErrorWhenGetPostByIdFoundNoRecord() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Post, bool>>>(), It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>())) .Returns(new List<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>(); _postsLogic = new PostsLogic(_postRepository.Object, _postContentRepository.Object, _mediaRepository.Object); var result = _postsLogic.GetPost(1); Assert.NotNull(result.Error); Assert.AreEqual((int)Constants.Error.RecordNotFound, result.Error.Id); Assert.AreEqual("Cannot find post with Id 1", result.Error.Message); }
public IHttpActionResult Get(int id) { var post = PostsLogic.getPostById(id); return(Json <Models.Posts>(post)); }
public void ShouldThrowExceptionWhenGetPostsForUserFailsOnPostsLookup() { _postRepository = new Mock<IPostRepository>(); _postRepository.Setup(a => a.GetPostsForUser(It.IsAny<int>(), It.IsAny<int>(), 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.GetPostsForUser(1, 5, 5)); }