public async Task ShouldThrowValidatonExceptionOnDeleteWhenStorageCategoryIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime            = GetRandomDateTime();
            Category       randomCategory      = CreateRandomCategory(dateTime);
            Guid           inputCategoryId     = randomCategory.Id;
            Category       inputCategory       = randomCategory;
            Category       nullStorageCategory = null;

            var notFoundCategoryException = new NotFoundCategoryException(inputCategoryId);

            var expectedCategoryValidationException =
                new CategoryValidationException(notFoundCategoryException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCategoryByIdAsync(inputCategoryId))
            .ReturnsAsync(nullStorageCategory);

            // when
            ValueTask <Category> actualCategoryTask =
                this.categoryService.RemoveCategoryByIdAsync(inputCategoryId);

            // then
            await Assert.ThrowsAsync <CategoryValidationException>(() => actualCategoryTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCategoryByIdAsync(inputCategoryId),
                                          Times.Once);

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Ejemplo n.º 2
0
        public async void ShouldThrowValidationExceptionOnRetrieveByIdWhenStorageCategoryIsNullAndLogItAsync()
        {
            // given
            Guid     randomCategoryId          = Guid.NewGuid();
            Guid     someCategoryId            = randomCategoryId;
            Category invalidStorageCategory    = null;
            var      notFoundCategoryException = new NotFoundCategoryException(someCategoryId);

            var exceptionCategoryValidationException =
                new CategoryValidationException(notFoundCategoryException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCategoryByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(invalidStorageCategory);

            // when
            ValueTask <Category> retrieveCategoryByIdTask =
                this.categoryService.RetrieveCategoryByIdAsync(someCategoryId);

            // then
            await Assert.ThrowsAsync <CategoryValidationException>(() =>
                                                                   retrieveCategoryByIdTask.AsTask());

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

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

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

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