Example #1
0
        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);
        }
Example #2
0
        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));
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        public void ShouldGetRelatedPostsEvenIfPostHasUserRelatedPostsFound()
        {
            var post = new Post
            {
                PostId = 1,
                PostLikes = _postLikes.Where(a => a.PostId == 1).ToList(),
                PostContents = _postContents.Where(a => a.PostId == 1).ToList(),
                Tags = new List<Tag>(),
                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.Find(It.IsAny<Expression<Func<Post, bool>>>(),
                It.IsAny<Func<IQueryable<Post>, IOrderedQueryable<Post>>>(), It.IsAny<string>()))
                .Returns(new List<Post> { post });
            _postRepository.Setup(a => a.GetPostsByTag(It.IsAny<string>(), It.IsAny<int>()))
                .Returns(new List<Post> { post });
            _postRepository.Setup(a => a.GetByUser(It.IsAny<int>(), It.IsAny<int>()))
                .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>();
            _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.GetRelatedPosts(1);

            Assert.NotNull(result);
            Assert.NotNull(result.PostsByTags);
            Assert.NotNull(result.PostsByUser);
        }