public async Task ShouldThrowValidationExceptionOnModifyWhenStudentIdIsInvalidAndLogItAsync()
        {
            //given
            Guid           invalidStudentId   = Guid.Empty;
            DateTimeOffset dateTime           = GetRandomDateTime();
            StudentExam    randomStudentExam  = CreateRandomStudentExam(dateTime);
            StudentExam    invalidStudentExam = randomStudentExam;

            invalidStudentExam.StudentId = invalidStudentId;

            var invalidStudentExamException = new InvalidStudentExamException(
                parameterName: nameof(StudentExam.StudentId),
                parameterValue: invalidStudentExam.StudentId);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(invalidStudentExamException);

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnModifyWhenStudentExamIsNullAndLogItAsync()
        {
            //given
            StudentExam invalidStudentExam       = null;
            var         nullStudentExamException = new NullStudentExamException();

            var expectedStudentExamValidationException =
                new StudentExamValidationException(nullStudentExamException);

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnModifyWhenUpdatedDateIsSameAsCreatedDateAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime          = GetRandomDateTime();
            StudentExam    randomStudentExam = CreateRandomStudentExam(dateTime);
            StudentExam    inputStudentExam  = randomStudentExam;

            var invalidStudentExamException = new InvalidStudentExamException(
                parameterName: nameof(StudentExam.UpdatedDate),
                parameterValue: inputStudentExam.UpdatedDate);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(invalidStudentExamException);

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

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #4
0
        public async void ShouldThrowValidationExceptionOnAddWhenStudentExamIsNullAndLogItAsync()
        {
            // given
            StudentExam randomStudentExam        = default;
            StudentExam nullStudentExam          = randomStudentExam;
            var         nullStudentExamException = new NullStudentExamException();

            var expectedStudentExamValidationException =
                new StudentExamValidationException(nullStudentExamException);

            // when
            ValueTask <StudentExam> addStudentExamTask =
                this.studentExamService.AddStudentExamAsync(nullStudentExam);

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #5
0
        private StudentExamValidationException CreateAndLogValidationException(Exception exception)
        {
            var StudentExamValidationException = new StudentExamValidationException(exception);

            this.loggingBroker.LogError(StudentExamValidationException);

            return(StudentExamValidationException);
        }
        public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotSameAsCreateDateAndLogItAsync()
        {
            // given
            int            randomNumber       = GetRandomNumber();
            int            randomMinutes      = randomNumber;
            DateTimeOffset randomDate         = GetRandomDateTime();
            StudentExam    randomStudentExam  = CreateRandomStudentExam(randomDate);
            StudentExam    invalidStudentExam = randomStudentExam;

            invalidStudentExam.UpdatedDate = randomDate;
            StudentExam storageStudentExam = randomStudentExam.DeepClone();
            Guid        studentId          = invalidStudentExam.StudentId;
            Guid        semesterCourseId   = invalidStudentExam.ExamId;

            invalidStudentExam.CreatedDate = storageStudentExam.CreatedDate.AddMinutes(randomNumber);

            var invalidStudentExamException = new InvalidStudentExamException(
                parameterName: nameof(StudentExam.CreatedDate),
                parameterValue: invalidStudentExam.CreatedDate);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(invalidStudentExamException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamByIdAsync(invalidStudentExam.Id))
            .ReturnsAsync(storageStudentExam);

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

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

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

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        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 #8
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 #9
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();
        }
Beispiel #10
0
        public async void ShouldThrowValidationExceptionOnRetrieveWhenIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomStudentExamId = default;
            Guid inputStudentExamId  = randomStudentExamId;

            var invalidStudentExamException = new InvalidStudentExamException(
                parameterName: nameof(StudentExam.Id),
                parameterValue: inputStudentExamId);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(invalidStudentExamException);

            // 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(It.IsAny <Guid>()),
                                          Times.Never);

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