public async Task ShouldThrowValidationExceptionOnModifyIfStudentExamDoesntExistAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            DateTimeOffset dateTime               = GetRandomDateTime();
            StudentExam    randomStudentExam      = CreateRandomStudentExam(dateTime);
            StudentExam    nonExistentStudentExam = randomStudentExam;

            nonExistentStudentExam.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes);
            StudentExam noStudentExam = null;
            var         notFoundStudentExamException = new NotFoundStudentExamException(nonExistentStudentExam.Id);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(notFoundStudentExamException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamByIdAsync(nonExistentStudentExam.Id))
            .ReturnsAsync(noStudentExam);

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

            // when
            ValueTask <StudentExam> modifyStudentExamTask =
                this.studentExamService.ModifyStudentExamAsync(nonExistentStudentExam);

            // then
            await Assert.ThrowsAsync <StudentExamValidationException>(() =>
                                                                      modifyStudentExamTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamByIdAsync(nonExistentStudentExam.Id),
                                          Times.Once);

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public async Task ShouldThrowValidationExceptionOnDeleteWhenStorageStudentExamIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset randomDateTime         = GetRandomDateTime();
            StudentExam    randomStudentExam      = CreateRandomStudentExam(randomDateTime);
            Guid           inputStudentExamId     = randomStudentExam.Id;
            StudentExam    nullStorageStudentExam = null;

            var notFoundStudentExamException = new NotFoundStudentExamException(inputStudentExamId);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(notFoundStudentExamException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamByIdAsync(inputStudentExamId))
            .ReturnsAsync(nullStorageStudentExam);

            // when
            ValueTask <StudentExam> actualStudentExamDeleteTask =
                this.studentExamService.RemoveStudentExamByIdAsync(inputStudentExamId);

            // then
            await Assert.ThrowsAsync <StudentExamValidationException>(() => actualStudentExamDeleteTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamByIdAsync(inputStudentExamId),
                                          Times.Once);

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #3
0
        public async void ShouldThrowValidationExceptionOnRetrieveWhenStorageStudentExamIsNullAndLogItAsync()
        {
            // given
            Guid        randomStudentExamId          = Guid.NewGuid();
            Guid        inputStudentExamId           = randomStudentExamId;
            StudentExam invalidStorageStudentExam    = null;
            var         notFoundStudentExamException = new NotFoundStudentExamException(inputStudentExamId);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(notFoundStudentExamException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamByIdAsync(inputStudentExamId))
            .ReturnsAsync(invalidStorageStudentExam);

            // when
            ValueTask <StudentExam> retrieveStudentExamByIdTask =
                this.studentExamService.RetrieveStudentExamByIdAsync(inputStudentExamId);

            // then
            await Assert.ThrowsAsync <StudentExamValidationException>(() =>
                                                                      retrieveStudentExamByIdTask.AsTask());

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamByIdAsync(inputStudentExamId),
                                          Times.Once);

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