Exemple #1
0
        public async Task ShouldThrowValidatonExceptionOnDeleteWhenStorageTagIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime       = GetRandomDateTime();
            Tag            randomTag      = CreateRandomTag(dateTime);
            Guid           inputTagId     = randomTag.Id;
            Tag            inputTag       = randomTag;
            Tag            nullStorageTag = null;

            var notFoundTagException = new NotFoundTagException(inputTagId);

            var expectedTagValidationException =
                new TagValidationException(notFoundTagException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTagByIdAsync(inputTagId))
            .ReturnsAsync(nullStorageTag);

            // when
            ValueTask <Tag> actualTagTask =
                this.tagService.RemoveTagByIdAsync(inputTagId);

            // then
            await Assert.ThrowsAsync <TagValidationException>(() => actualTagTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTagByIdAsync(inputTagId),
                                          Times.Once);

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnRetrieveByIdWhenStorageTagIsNullAndLogItAsync()
        {
            // given
            Guid randomTagId          = Guid.NewGuid();
            Guid someTagId            = randomTagId;
            Tag  invalidStorageTag    = null;
            var  notFoundTagException = new NotFoundTagException(someTagId);

            var exceptionTagValidationException =
                new TagValidationException(notFoundTagException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTagByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(invalidStorageTag);

            // when
            ValueTask <Tag> retrieveTagByIdTask =
                this.tagService.RetrieveTagByIdAsync(someTagId);

            // then
            await Assert.ThrowsAsync <TagValidationException>(() =>
                                                              retrieveTagByIdTask.AsTask());

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

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

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

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