コード例 #1
0
        public async Task ShouldThrowValidationExceptionOnModifyWhenExamFeeIdIsInvalidAndLogItAsync()
        {
            //given
            Guid           invalidExamId         = Guid.Empty;
            DateTimeOffset dateTime              = GetRandomDateTime();
            StudentExamFee randomStudentExamFee  = CreateRandomStudentExamFee(dateTime);
            StudentExamFee invalidStudentExamFee = randomStudentExamFee;

            invalidStudentExamFee.ExamFeeId = invalidExamId;

            var invalidStudentExamFeeInputException = new InvalidStudentExamFeeException(
                parameterName: nameof(StudentExamFee.ExamFeeId),
                parameterValue: invalidStudentExamFee.ExamFeeId);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(invalidStudentExamFeeInputException);

            //when
            ValueTask <StudentExamFee> modifyStudentExamFeeTask =
                this.studentExamFeeService.ModifyStudentExamFeeAsync(invalidStudentExamFee);

            //then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         modifyStudentExamFeeTask.AsTask());

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnCreateWhenStudentExamFeeIsNullAndLogItAsync()
        {
            // given
            StudentExamFee invalidStudentExamFee = null;

            var nullStudentExamFeeException = new NullStudentExamFeeException();

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(nullStudentExamFeeException);

            // when
            ValueTask <StudentExamFee> createStudentExamFeeTask =
                this.studentExamFeeService.AddStudentExamFeeAsync(invalidStudentExamFee);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         createStudentExamFeeTask.AsTask());

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotSameAsCreateDateAndLogItAsync()
        {
            // given
            int            randomNumber          = GetRandomNumber();
            int            randomMinutes         = randomNumber;
            DateTimeOffset randomDate            = GetRandomDateTime();
            StudentExamFee randomStudentExamFee  = CreateRandomStudentExamFee(randomDate);
            StudentExamFee invalidStudentExamFee = randomStudentExamFee;

            invalidStudentExamFee.UpdatedDate = randomDate;
            StudentExamFee storageStudentExamFee = randomStudentExamFee.DeepClone();
            Guid           studentId             = invalidStudentExamFee.StudentId;
            Guid           semesterCourseId      = invalidStudentExamFee.ExamFeeId;

            invalidStudentExamFee.CreatedDate = storageStudentExamFee.CreatedDate.AddMinutes(randomNumber);

            var invalidStudentExamFeeInputException = new InvalidStudentExamFeeException(
                parameterName: nameof(StudentExamFee.CreatedDate),
                parameterValue: invalidStudentExamFee.CreatedDate);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(invalidStudentExamFeeInputException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamFeeByIdsAsync(
                                             invalidStudentExamFee.StudentId,
                                             invalidStudentExamFee.ExamFeeId))
            .ReturnsAsync(storageStudentExamFee);

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

            // when
            ValueTask <StudentExamFee> modifyStudentExamFeeTask =
                this.studentExamFeeService.ModifyStudentExamFeeAsync(invalidStudentExamFee);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         modifyStudentExamFeeTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamFeeByIdsAsync(
                                              invalidStudentExamFee.StudentId,
                                              invalidStudentExamFee.ExamFeeId),
                                          Times.Once);

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
コード例 #4
0
        private StudentExamFeeValidationException CreateAndLogValidationException(Exception exception)
        {
            var studentExamFeeValidationException = new StudentExamFeeValidationException(exception);

            this.loggingBroker.LogError(studentExamFeeValidationException);

            return(studentExamFeeValidationException);
        }
        public async Task ShouldThrowValidationExceptionOnModifyIfStudentExamFeeDoesnotExistAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            DateTimeOffset dateTime                  = GetRandomDateTime();
            StudentExamFee randomStudentExamFee      = CreateRandomStudentExamFee(dateTime);
            StudentExamFee nonExistentStudentExamFee = randomStudentExamFee;

            nonExistentStudentExamFee.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes);
            StudentExamFee noStudentExamFee = null;

            var notFoundStudentExamFeeException =
                new NotFoundStudentExamFeeException(
                    nonExistentStudentExamFee.StudentId,
                    nonExistentStudentExamFee.ExamFeeId);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(notFoundStudentExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamFeeByIdsAsync(
                                             nonExistentStudentExamFee.StudentId,
                                             nonExistentStudentExamFee.ExamFeeId))
            .ReturnsAsync(noStudentExamFee);

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

            // when
            ValueTask <StudentExamFee> modifyStudentExamFeeTask =
                this.studentExamFeeService.ModifyStudentExamFeeAsync(nonExistentStudentExamFee);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         modifyStudentExamFeeTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamFeeByIdsAsync(
                                              nonExistentStudentExamFee.StudentId,
                                              nonExistentStudentExamFee.ExamFeeId),
                                          Times.Once);

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnCreateWhenStudentExamFeeAlreadyExistsAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime                    = GetRandomDateTime();
            StudentExamFee randomStudentExamFee        = CreateRandomStudentExamFee(dateTime);
            StudentExamFee alreadyExistsStudentExamFee = randomStudentExamFee;

            alreadyExistsStudentExamFee.UpdatedBy = alreadyExistsStudentExamFee.CreatedBy;
            string randomMessage         = GetRandomMessage();
            string exceptionMessage      = randomMessage;
            var    duplicateKeyException = new DuplicateKeyException(exceptionMessage);

            var alreadyExistsStudentExamFeeException =
                new AlreadyExistsStudentExamFeeException(duplicateKeyException);

            var expectedExamFeeValidationException =
                new StudentExamFeeValidationException(alreadyExistsStudentExamFeeException);

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

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertStudentExamFeeAsync(alreadyExistsStudentExamFee))
            .ThrowsAsync(duplicateKeyException);

            // when
            ValueTask <StudentExamFee> createStudentExamFeeTask =
                this.studentExamFeeService.AddStudentExamFeeAsync(alreadyExistsStudentExamFee);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         createStudentExamFeeTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertStudentExamFeeAsync(alreadyExistsStudentExamFee),
                                          Times.Once);

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnCreateWhenCreatedDateIsNotRecentAndLogItAsync(
            int minutes)
        {
            // given
            DateTimeOffset dateTime             = GetRandomDateTime();
            StudentExamFee randomStudentExamFee = CreateRandomStudentExamFee(dateTime);
            StudentExamFee inputStudentExamFee  = randomStudentExamFee;

            inputStudentExamFee.UpdatedBy   = inputStudentExamFee.CreatedBy;
            inputStudentExamFee.CreatedDate = dateTime.AddMinutes(minutes);
            inputStudentExamFee.UpdatedDate = inputStudentExamFee.CreatedDate;

            var invalidStudentExamFeeInputException = new InvalidStudentExamFeeException(
                parameterName: nameof(StudentExamFee.CreatedDate),
                parameterValue: inputStudentExamFee.CreatedDate);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(invalidStudentExamFeeInputException);

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

            // when
            ValueTask <StudentExamFee> createStudentExamFeeTask =
                this.studentExamFeeService.AddStudentExamFeeAsync(inputStudentExamFee);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         createStudentExamFeeTask.AsTask());

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
コード例 #8
0
        public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageStudentExamFeeIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset randomDateTime       = GetRandomDateTime();
            StudentExamFee randomStudentExamFee = CreateRandomStudentExamFee(randomDateTime);
            Guid           inputStudentId       = randomStudentExamFee.StudentId;
            Guid           inputExamFeeId       = randomStudentExamFee.ExamFeeId;
            StudentExamFee nullStudentExamFees  = null;

            var notFoundStudentExamFeeException =
                new NotFoundStudentExamFeeException(inputStudentId, inputExamFeeId);

            var expectedAssignmentValidationException =
                new StudentExamFeeValidationException(notFoundStudentExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamFeeByIdsAsync(
                                             It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(nullStudentExamFees);

            // when
            ValueTask <StudentExamFee> removeStudentExamFeeTask =
                this.studentExamFeeService.RemoveStudentExamFeeByIdAsync(
                    inputStudentId,
                    inputExamFeeId);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         removeStudentExamFeeTask.AsTask());

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        ShouldThrowValidationExceptionOnRetrieveWhenStorageStudentExamFeeIsNullAndLogItAsync()
        {
            // given
            Guid           randomStudentId = Guid.NewGuid();
            Guid           inputStudentId  = randomStudentId;
            Guid           randomExamFeeId = Guid.NewGuid();
            Guid           inputExamFeeId  = randomExamFeeId;
            StudentExamFee invalidStorageStudentExamFee = null;

            var notFoundStudentExamFeeException =
                new NotFoundStudentExamFeeException(
                    inputStudentId, inputExamFeeId);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(notFoundStudentExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamFeeByIdsAsync(
                                             inputStudentId, inputExamFeeId))
            .ReturnsAsync(invalidStorageStudentExamFee);

            // when
            ValueTask <StudentExamFee> retrieveStudentExamFeeByIdTask =
                this.studentExamFeeService.RetrieveStudentExamFeeByIdsAsync(
                    inputStudentId, inputExamFeeId);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         retrieveStudentExamFeeByIdTask.AsTask());

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
コード例 #10
0
        public async Task ShouldThrowValidatonExceptionOnRemoveWhenExamFeeIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomStudentId = Guid.NewGuid();
            Guid inputStudentId  = randomStudentId;
            Guid randomExamFeeId = default;
            Guid inputExamFeeId  = randomExamFeeId;

            var invalidStudentExamFeeInputException = new InvalidStudentExamFeeException(
                parameterName: nameof(StudentExamFee.ExamFeeId),
                parameterValue: inputExamFeeId);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(invalidStudentExamFeeInputException);

            // when
            ValueTask <StudentExamFee> removeStudentExamFeeTask =
                this.studentExamFeeService.RemoveStudentExamFeeByIdAsync(
                    inputStudentId,
                    inputExamFeeId);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         removeStudentExamFeeTask.AsTask());

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnModifyWhenCreatedDateIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime             = GetRandomDateTime();
            StudentExamFee randomStudentExamFee = CreateRandomStudentExamFee(dateTime);
            StudentExamFee inputStudentExamFee  = randomStudentExamFee;

            inputStudentExamFee.CreatedDate = default;

            var invalidStudentExamFeeInputException = new InvalidStudentExamFeeException(
                parameterName: nameof(StudentExamFee.CreatedDate),
                parameterValue: inputStudentExamFee.CreatedDate);

            var expectedStudentExamFeeValidationException =
                new StudentExamFeeValidationException(invalidStudentExamFeeInputException);

            // when
            ValueTask <StudentExamFee> modifyStudentExamFeeTask =
                this.studentExamFeeService.ModifyStudentExamFeeAsync(inputStudentExamFee);

            // then
            await Assert.ThrowsAsync <StudentExamFeeValidationException>(() =>
                                                                         modifyStudentExamFeeTask.AsTask());

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

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

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