Esempio n. 1
0
        public async Task GivenValidRequest_WhenTheArticleDoesNotExist_ThrowsApiExceptionForNotFound()
        {
            // Arrange
            var deleteCommentCommand = new DeleteCommentCommand(1, "how-to-not-train-your-dragon");

            // Act
            var handler  = new DeleteCommentCommandHandler(Context, CurrentUserContext);
            var response = await Should.ThrowAsync <ConduitApiException>(async() =>
            {
                await handler.Handle(deleteCommentCommand, CancellationToken.None);
            });

            // Assert
            response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
        }
Esempio n. 2
0
        public async Task GivenValidRequest_WhenTheCommentExistsAndIsOwnerByTheRequest_DeletesCommentSuccessfully()
        {
            // Arrange
            var deleteCommentCommand = new DeleteCommentCommand(1, "how-to-train-your-dragon");
            var existingComment      = Context.Comments.Find(1);

            existingComment.ShouldNotBeNull();

            // Act
            var handler  = new DeleteCommentCommandHandler(Context, CurrentUserContext);
            var response = await handler.Handle(deleteCommentCommand, CancellationToken.None);

            // Assert
            Context.Comments.Find(1).ShouldBeNull();
        }
Esempio n. 3
0
        public async Task GivenValidRequest_WhenTheCommentIsNotOwnedByTheRequester_ThrowsApiExceptionForForbidden()
        {
            // Arrange
            var deleteCommentCommand = new DeleteCommentCommand(2, "how-to-train-your-dragon");

            // Act
            var handler  = new DeleteCommentCommandHandler(Context, CurrentUserContext);
            var response = await Should.ThrowAsync <ConduitApiException>(async() =>
            {
                await handler.Handle(deleteCommentCommand, CancellationToken.None);
            });

            // Assert
            response.StatusCode.ShouldBe(HttpStatusCode.Forbidden);
        }
Esempio n. 4
0
        public void Should_call_save_method_when_delete_comment()
        {
            var commentId = Guid.NewGuid();

            var comment = Comment.CreateNew(Guid.NewGuid(), "Text", false);

            comment.GetType().GetProperty("Id").SetValue(comment, commentId, null);

            var commentRepository = new Mock <ICommentRepository>();

            commentRepository.Setup(x => x.GetById(commentId)).Returns(comment);
            commentRepository.Setup(x => x.Save(comment));

            var deleteCommentCommandHandler = new DeleteCommentCommandHandler(commentRepository.Object);

            deleteCommentCommandHandler.Handle(new DeleteCommentCommand(commentId));

            commentRepository.Verify(x => x.Save(comment));
        }