public async Task Should_return_null_when_author_not_found()
        {
            // Arrange
            string authorId = Guid.NewGuid().ToString();

            CommentRepositoryMock.Setup(x => x.GetCommentByAuthorAsync(authorId, default(CancellationToken))).ReturnsAsync(MockDataItems.Where(v => v.AuthorId == authorId));

            // Act
            IEnumerable <Comment> resultComments = await ServiceUnderTest.GetCommentByAuthorAsync(authorId, default(CancellationToken));

            // Assert
            Assert.Empty(resultComments);
        }
        public async Task Should_return_items_by_parent()
        {
            // Arrange
            string parentId = MockDataItems[2].ParentId;

            CommentRepositoryMock.Setup(x => x.GetCommentsByParentAsync(parentId, default(CancellationToken))).ReturnsAsync(MockDataItems.Where(v => v.ParentId == parentId));

            // Act
            IEnumerable <Comment> resultComments = await ServiceUnderTest.GetCommentsByParentAsync(parentId, default(CancellationToken));

            // Assert
            Assert.Equal(MockDataItems.Where(v => v.ParentId == parentId), resultComments);
        }
        public async Task Should_fail_create_new_comment_no_author_id()
        {
            // Arrange
            Comment newComment = new Comment {
                ParentId = Guid.NewGuid().ToString(), Value = "This new comment is awesome", Votes = 0
            };

            CommentRepositoryMock.Setup(x => x.CreateNewCommentAsync(newComment, default(CancellationToken))).ReturnsAsync(Guid.NewGuid().ToString());

            // Act
            ArgumentNullException exception = await Assert.ThrowsAsync <ArgumentNullException>(() => ServiceUnderTest.CreateNewCommentAsync(newComment, default(CancellationToken)));

            // Assert
            Assert.Equal(nameof(newComment.AuthorId), exception.ParamName);
        }
        public async Task Should_return_items_by_author()
        {
            // Arrange
            string authorId = MockDataItems[1].AuthorId;

            CommentRepositoryMock.Setup(x => x.GetCommentByAuthorAsync(authorId, default(CancellationToken))).ReturnsAsync(MockDataItems.Where(i => i.AuthorId == authorId));

            IEnumerable <Comment> expectedData = MockDataItems.Where(i => i.AuthorId == authorId);

            // Act
            IEnumerable <Comment> resultComments = await ServiceUnderTest.GetCommentByAuthorAsync(authorId, default(CancellationToken));

            // Assert
            Assert.Equal(expectedData, resultComments);
        }
        public async Task Should_update_existing_comment()
        {
            // Arrange
            Comment newComment = new Comment {
                Id = Guid.NewGuid().ToString(), AuthorId = Guid.NewGuid().ToString(), ParentId = Guid.NewGuid().ToString(), Value = "I'm prone to changing my mind, maybe more than once", Votes = 0
            };

            CommentRepositoryMock.Setup(x => x.UpdateCommentAsync(newComment, default(CancellationToken))).ReturnsAsync(newComment.Id);
            CommentRepositoryMock.Setup(x => x.GetCommentById(newComment.Id, default(CancellationToken))).ReturnsAsync(newComment);

            // Act
            Comment resultComment = await ServiceUnderTest.UpdateCommentAsync(newComment, default(CancellationToken));

            // Assert
            Assert.Equal(newComment, resultComment);
        }
        public async Task Should_create_new_comment()
        {
            // Arrange
            string  newId      = Guid.NewGuid().ToString();
            Comment newComment = new Comment {
                Id = newId, AuthorId = Guid.NewGuid().ToString(), ParentId = Guid.NewGuid().ToString(), Value = "This new comment is awesome", Votes = 0
            };

            CommentRepositoryMock.Setup(x => x.CreateNewCommentAsync(newComment, default(CancellationToken))).ReturnsAsync(newId);
            CommentRepositoryMock.Setup(x => x.GetCommentById(newId, default(CancellationToken))).ReturnsAsync(newComment);

            // Act
            Comment resultComment = await ServiceUnderTest.CreateNewCommentAsync(newComment, default(CancellationToken));

            // Assert
            Assert.Same(newComment, resultComment);
        }