public void CanPaginatePosts()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ItemsPerPage      = 2,
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.GetPosts(new PostsInfo
            {
                Type        = "testType",
                Username    = "******",
                CurrentPage = 1,
            }) as OkObjectResult;

            Assert.NotNull(result);

            var posts = result.Value as UserPostsViewData;

            Assert.NotNull(posts);
            Assert.Equal(1, posts.PagingInfo.CurrentPage);
            Assert.Equal(3, posts.PagingInfo.TotalItems);
            Assert.Equal(2, posts.PagingInfo.ItemsPerPage);
            Assert.Equal(2, posts.PagingInfo.TotalPages);

            var postsList = posts.Posts.ToList();

            Assert.Equal(2, postsList.Count);
            Assert.Equal(1, postsList[0].Item.Id);
            Assert.Equal(4, postsList[1].Item.Id);
        }
Beispiel #2
0
        public void CanSaveComment_withParentComment()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.SaveComment(new CommentForm {
                PostId    = 1,
                Content   = "testContent",
                CommentId = 1
            }) as ObjectResult;

            _commentRepository.Verify(c => c.SaveComment(It.IsAny <Comment>()), Times.Once);
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);

            var comment = result.Value as ItemViewData <Comment>;

            Assert.IsType <ItemViewData <Comment> >(comment);
            Assert.Equal("test1", comment.Item.User.UserName);
            Assert.Equal(1, comment.Item.Post.Id);
            Assert.Equal("testContent", comment.Item.Content);
            Assert.NotNull(comment.Item.ParentComment);
        }
        public void CanGetPosts()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.GetPosts(new PostsInfo
            {
                Type        = "testType",
                Username    = "******",
                CurrentPage = 1,
            }) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);

            var posts = result.Value as UserPostsViewData;

            Assert.IsType <UserPostsViewData>(posts);
            Assert.Equal(3, posts.Posts.Count());
        }
        public void CanSavePost()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.SavePost(new PostForm
            {
                Description = "test description",
                Title       = "test title",
                Type        = "test type",
                Tags        = "test1 test2"
            }) as ObjectResult;

            _postRepository.Verify(m =>
                                   m.SavePost(It.IsAny <Post>(), It.IsAny <IEnumerable <string> >()), Times.Once);
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("saved", result.Value);
        }
        public void CannotLikeIt_PostNotFound()
        {
            var controller = new PostLikeController(
                _userRepository.Object,
                _postRepository.Object,
                _postLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.PostLike(0) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("Post not found", result.Value);
        }
Beispiel #6
0
        public void CannotGetComments_UserNotFound()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("testFail", "User")
            };

            var result = controller.GetComments(1) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("User not found", result.Value);
        }
        public void CanDeletePost()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.DeletePost(1) as ObjectResult;

            _postRepository.Verify(m =>
                                   m.DeletePost(It.IsAny <Post>()), Times.Once);
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("deleted", result.Value);
        }
        public void CannotDeletePost_PostNotFound()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.DeletePost(0) as ObjectResult;

            _postRepository.Verify(m =>
                                   m.DeletePost(It.IsAny <Post>()), Times.Never);
            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("Post not found", result.Value);
        }
Beispiel #9
0
        public void CanDeleteComment()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.DeleteComment(1) as ObjectResult;

            _commentRepository.Verify(c => c.DeleteComment(It.IsAny <Comment>()), Times.Once);
            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("Deleted", result.Value);
        }
Beispiel #10
0
        public void CannotDeleteComment_CommentNotFound()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test2", "User")
            };

            var result = controller.DeleteComment(1) as ObjectResult;

            _commentRepository.Verify(c => c.DeleteComment(It.IsAny <Comment>()), Times.Never);
            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("Comment not found", result.Value);
        }
        public void CannotGetPosts()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.GetPosts(new PostsInfo
            {
                Type        = "testType",
                Username    = "******",
                CurrentPage = 1,
            }) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("User not found", result.Value);
        }
        public void CannotSavePost()
        {
            var controller = new PostsController(
                _postRepository.Object,
                _postLikeRepository.Object,
                _blogRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("testNotFound", "User")
            };

            var result = controller.SavePost(new PostForm
            {
                Description = "test description",
                Title       = "test title",
                Type        = "test type"
            }) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("User not found", result.Value);
        }
        public void CanUnLikePost()
        {
            var controller = new PostLikeController(
                _userRepository.Object,
                _postRepository.Object,
                _postLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.PostLike(1) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);
            _postLikeRepository.Verify(m =>
                                       m.DeletePostLike(It.IsAny <PostLike>()), Times.Once);

            var post = result.Value as ItemViewData <Post>;

            Assert.NotNull(post);
        }
Beispiel #14
0
        public void CanGetComments_WithoutParentComments()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.GetComments(1) as ObjectResult;

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);

            var comments = result.Value as IEnumerable <ItemViewData <Comment> >;

            Assert.NotNull(comments);
            Assert.Equal(3, comments.Count());
        }
        public void CanLikeComment()
        {
            var controller = new CommentLikeController(
                _userRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test2", "User")
            };

            var result = controller.CommentLike(3) as ObjectResult;

            _commentLikeRepository.Verify(m =>
                                          m.SaveCommentLike(It.IsAny <CommentLike>()), Times.Once);

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(result.Value);

            var comment = result.Value as ItemViewData <Comment>;

            Assert.NotNull(comment);
        }
Beispiel #16
0
        public void CannotSaveComment_ParentCommentNotFound()
        {
            var controller = new CommentController(
                _userRepository.Object,
                _postRepository.Object,
                _commentRepository.Object,
                _commentLikeRepository.Object)
            {
                ControllerContext = FakeController.GetContextWithIdentity("test1", "User")
            };

            var result = controller.SaveComment(new CommentForm {
                PostId    = 1,
                Content   = "testContent",
                CommentId = 0
            }) as ObjectResult;

            _commentRepository.Verify(c => c.SaveComment(It.IsAny <Comment>()), Times.Never);
            Assert.NotNull(result);
            Assert.IsType <NotFoundObjectResult>(result);
            Assert.Equal(404, result.StatusCode);
            Assert.NotNull(result.Value);
            Assert.Equal("Parent comment not found", result.Value);
        }