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();
        }
Exemplo n.º 2
0
        public async Task ShouldModifyStudentExamFeeAsync()
        {
            // given
            int            randomNumber    = GetRandomNumber();
            int            randomDays      = randomNumber;
            DateTimeOffset randomDate      = GetRandomDateTime();
            DateTimeOffset randomInputDate = GetRandomDateTime();

            StudentExamFee randomStudentExamFee =
                CreateRandomStudentExamFee(randomInputDate);

            StudentExamFee inputStudentExamFee = randomStudentExamFee;
            StudentExamFee afterUpdateStorageStudentExamFee = randomStudentExamFee;
            StudentExamFee expectedStudentExamFee           = randomStudentExamFee;

            StudentExamFee beforeUpdateStorageStudentExamFee =
                randomStudentExamFee.DeepClone();

            inputStudentExamFee.UpdatedDate = randomDate;
            Guid studentId  = inputStudentExamFee.StudentId;
            Guid guardianId = inputStudentExamFee.ExamFeeId;

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

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamFeeByIdsAsync(
                                             inputStudentExamFee.StudentId,
                                             inputStudentExamFee.ExamFeeId))
            .ReturnsAsync(beforeUpdateStorageStudentExamFee);

            this.storageBrokerMock.Setup(broker =>
                                         broker.UpdateStudentExamFeeAsync(inputStudentExamFee))
            .ReturnsAsync(afterUpdateStorageStudentExamFee);

            // when
            StudentExamFee actualStudentExamFee =
                await this.studentExamFeeService.ModifyStudentExamFeeAsync(
                    inputStudentExamFee);

            // then
            actualStudentExamFee.Should().BeEquivalentTo(expectedStudentExamFee);

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.UpdateStudentExamFeeAsync(inputStudentExamFee),
                                          Times.Once);

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