コード例 #1
0
        public async Task ShouldThrowValidationExceptionOnModifyIfFeeIsNullAndLogItAsync()
        {
            //given
            Fee invalidFee       = null;
            var nullFeeException = new NullFeeException();

            var expectedFeeValidationException =
                new FeeValidationException(nullFeeException);

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

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

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
コード例 #2
0
        public async void ShouldThrowValidationExceptionOnAddWhenFeeIsNullAndLogItAsync()
        {
            // given
            Fee randomFee        = default;
            Fee nullFee          = randomFee;
            var nullFeeException = new NullFeeException();

            var expectedFeeValidationException =
                new FeeValidationException(nullFeeException);

            // when
            ValueTask <Fee> createFeeTask =
                this.feeService.AddFeeAsync(nullFee);

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

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

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

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