Ejemplo n.º 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 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();
        }
        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();
        }
Ejemplo n.º 4
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();
        }