public async Task ShouldThrowValidatonExceptionOnDeleteWhenStorageCommentIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime           = GetRandomDateTime();
            Comment        randomComment      = CreateRandomComment(dateTime);
            Guid           inputCommentId     = randomComment.Id;
            Comment        inputComment       = randomComment;
            Comment        nullStorageComment = null;

            var notFoundCommentException = new NotFoundCommentException(inputCommentId);

            var expectedCommentValidationException =
                new CommentValidationException(notFoundCommentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCommentByIdAsync(inputCommentId))
            .ReturnsAsync(nullStorageComment);

            // when
            ValueTask <Comment> actualCommentTask =
                this.commentService.RemoveCommentByIdAsync(inputCommentId);

            // then
            await Assert.ThrowsAsync <CommentValidationException>(() => actualCommentTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(expectedCommentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCommentByIdAsync(inputCommentId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteCommentAsync(It.IsAny <Comment>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
示例#2
0
        public async void ShouldThrowValidationExceptionOnRetrieveByIdWhenStorageCommentIsNullAndLogItAsync()
        {
            // given
            Guid    randomCommentId          = Guid.NewGuid();
            Guid    someCommentId            = randomCommentId;
            Comment invalidStorageComment    = null;
            var     notFoundCommentException = new NotFoundCommentException(someCommentId);

            var exceptionCommentValidationException =
                new CommentValidationException(notFoundCommentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCommentByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(invalidStorageComment);

            // when
            ValueTask <Comment> retrieveCommentByIdTask =
                this.commentService.RetrieveCommentByIdAsync(someCommentId);

            // then
            await Assert.ThrowsAsync <CommentValidationException>(() =>
                                                                  retrieveCommentByIdTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(exceptionCommentValidationException))),
                                          Times.Once);

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Never);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCommentByIdAsync(It.IsAny <Guid>()),
                                          Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }