示例#1
0
        public async Task ShouldThrowValidationExceptionOnModifyIfExamFeeDoesntExistAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            DateTimeOffset dateTime           = GetRandomDateTime();
            ExamFee        randomExamFee      = CreateRandomExamFee(dateTime);
            ExamFee        nonExistentExamFee = randomExamFee;

            nonExistentExamFee.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes);
            ExamFee noExamFee = null;
            var     notFoundExamFeeException = new NotFoundExamFeeException(nonExistentExamFee.Id);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(notFoundExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(nonExistentExamFee.Id))
            .ReturnsAsync(noExamFee);

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

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

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectExamFeeByIdAsync(nonExistentExamFee.Id),
                                          Times.Once);

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
示例#2
0
        public async Task ShouldThrowValidationExceptionOnDeleteWhenStorageExamFeeIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset randomDateTime     = GetRandomDateTime();
            ExamFee        randomExamFee      = CreateRandomExamFee(randomDateTime);
            Guid           inputExamFeeId     = randomExamFee.Id;
            ExamFee        nullStorageExamFee = null;

            var notFoundExamFeeException = new NotFoundExamFeeException(inputExamFeeId);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(notFoundExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(inputExamFeeId))
            .ReturnsAsync(nullStorageExamFee);

            // when
            ValueTask <ExamFee> actualExamFeeDeleteTask =
                this.examFeeService.RemoveExamFeeByIdAsync(inputExamFeeId);

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectExamFeeByIdAsync(inputExamFeeId),
                                          Times.Once);

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnRetrieveWhenStorageExamFeeIsNullAndLogItAsync()
        {
            // given
            Guid    randomExamFeeId          = Guid.NewGuid();
            Guid    inputExamFeeId           = randomExamFeeId;
            ExamFee invalidStorageExamFee    = null;
            var     notFoundExamFeeException = new NotFoundExamFeeException(inputExamFeeId);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(notFoundExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(inputExamFeeId))
            .ReturnsAsync(invalidStorageExamFee);

            // when
            ValueTask <ExamFee> retrieveExamFeeByIdTask =
                this.examFeeService.RetrieveExamFeeByIdAsync(inputExamFeeId);

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

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectExamFeeByIdAsync(inputExamFeeId),
                                          Times.Once);

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