Esempio n. 1
0
        public async void ShouldThrowValidationExceptionOnModifyWhenUpdatedDateIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime             = GetRandomDateTime();
            StudentExamFee randomStudentExamFee = CreateRandomStudentExamFee(dateTime);
            StudentExamFee inputStudentExamFee  = randomStudentExamFee;

            inputStudentExamFee.UpdatedDate = default;

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

            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();
        }
Esempio 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();
        }
Esempio n. 3
0
 public async ValueTask <StudentExamFee> PutStudentExamFeeAsync(StudentExamFee studentExamFee) =>
 await this.apiFactoryClient.PutContentAsync(
     StudentExamFeesRelativeUrl,
     studentExamFee);