Пример #1
0
        public async Task ShouldThrowValidationExceptionOnModifyWhenExamFeeIsNullAndLogItAsync()
        {
            //given
            ExamFee invalidExamFee       = null;
            var     nullExamFeeException = new NullExamFeeException();

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(nullExamFeeException);

            //when
            ValueTask <ExamFee> modifyExamFeeTask =
                this.examFeeService.ModifyExamFeeAsync(invalidExamFee);

            //then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  modifyExamFeeTask.AsTask());

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenExamFeeIsNullAndLogItAsync()
        {
            // given
            ExamFee randomExamFee        = default;
            ExamFee nullExamFee          = randomExamFee;
            var     nullExamFeeException = new NullExamFeeException();

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(nullExamFeeException);

            // when
            ValueTask <ExamFee> addExamFeeTask =
                this.examFeeService.AddExamFeeAsync(nullExamFee);

            // then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  addExamFeeTask.AsTask());

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

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

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