Ejemplo n.º 1
0
        public async Task ShouldThrowValidationExceptionOnModifyIfFeeDoesntExistAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            DateTimeOffset dateTime       = GetRandomDateTime();
            Fee            randomFee      = CreateRandomFee(dateTime);
            Fee            nonExistentFee = randomFee;

            nonExistentFee.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes);
            Fee noFee = null;
            var notFoundFeeException = new NotFoundFeeException(nonExistentFee.Id);

            var expectedFeeValidationException =
                new FeeValidationException(notFoundFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectFeeByIdAsync(nonExistentFee.Id))
            .ReturnsAsync(noFee);

            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(dateTime);

            // when
            ValueTask <Fee> modifyFeeTask =
                this.feeService.ModifyFeeAsync(nonExistentFee);

            // then
            await Assert.ThrowsAsync <FeeValidationException>(() =>
                                                              modifyFeeTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectFeeByIdAsync(nonExistentFee.Id),
                                          Times.Once);

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldThrowValidatonExceptionOnRemoveWhenStorageFeeIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime       = GetRandomDateTime();
            Fee            randomFee      = CreateRandomFee(dateTime);
            Guid           inputFeeId     = randomFee.Id;
            Fee            inputFee       = randomFee;
            Fee            nullStorageFee = null;

            var notFoundFeeException = new NotFoundFeeException(inputFeeId);

            var expectedFeeValidationException =
                new FeeValidationException(notFoundFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectFeeByIdAsync(inputFeeId))
            .ReturnsAsync(nullStorageFee);

            // when
            ValueTask <Fee> actualFeeTask =
                this.feeService.RemoveFeeByIdAsync(inputFeeId);

            // then
            await Assert.ThrowsAsync <FeeValidationException>(() => actualFeeTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectFeeByIdAsync(inputFeeId),
                                          Times.Once);

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Ejemplo n.º 3
0
        public async void ShouldThrowValidationExceptionOnRetrieveByIdWhenStorageFeeIsNullAndLogItAsync()
        {
            //given
            Guid randomFeeId          = Guid.NewGuid();
            Guid someFeeId            = randomFeeId;
            Fee  invalidStorageFee    = null;
            var  notFoundFeeException = new NotFoundFeeException(someFeeId);

            var expectedFeeValidationException =
                new FeeValidationException(notFoundFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectFeeByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(invalidStorageFee);

            //when
            ValueTask <Fee> retrieveFeeByIdTask =
                this.feeService.RetrieveFeeByIdAsync(someFeeId);

            //then
            await Assert.ThrowsAsync <FeeValidationException>(() =>
                                                              retrieveFeeByIdTask.AsTask());

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

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

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

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