Пример #1
0
        private static void ValidateAgainstStorageExamFeeOnModify(ExamFee inputExamFee, ExamFee storageExamFee)
        {
            switch (inputExamFee)
            {
            case { } when inputExamFee.CreatedDate != storageExamFee.CreatedDate:
                throw new InvalidExamFeeException(
                          parameterName: nameof(ExamFee.CreatedDate),
                          parameterValue: inputExamFee.CreatedDate);

            case { } when inputExamFee.CreatedBy != storageExamFee.CreatedBy:
                throw new InvalidExamFeeException(
                          parameterName: nameof(ExamFee.CreatedBy),
                          parameterValue: inputExamFee.CreatedBy);

            case { } when inputExamFee.UpdatedDate == storageExamFee.UpdatedDate:
                throw new InvalidExamFeeException(
                          parameterName: nameof(ExamFee.UpdatedDate),
                          parameterValue: inputExamFee.UpdatedDate);
            }
        }
Пример #2
0
        private void ValidateInvalidAuditFieldsOnCreate(ExamFee examFee)
        {
            switch (examFee)
            {
            case { } when examFee.UpdatedBy != examFee.CreatedBy:
                throw new InvalidExamFeeException(
                          parameterName: nameof(ExamFee.UpdatedBy),
                          parameterValue: examFee.UpdatedBy);

            case { } when examFee.UpdatedDate != examFee.CreatedDate:
                throw new InvalidExamFeeException(
                          parameterName: nameof(ExamFee.UpdatedDate),
                          parameterValue: examFee.UpdatedDate);

            case { } when IsDateNotRecent(examFee.CreatedDate):
                throw new InvalidExamFeeException(
                          parameterName: nameof(ExamFee.CreatedDate),
                          parameterValue: examFee.CreatedDate);
            }
        }
Пример #3
0
        private void ValidateExamFeeOnModify(ExamFee examFee)
        {
            ValidateExamFeeIsNull(examFee);

            Validate(
                (Rule: IsInvalid(examFee.Id), Parameter: nameof(ExamFee.Id)),
                (Rule: IsInvalid(examFee.ExamId), Parameter: nameof(ExamFee.ExamId)),
                (Rule: IsInvalid(examFee.FeeId), Parameter: nameof(ExamFee.FeeId)),
                (Rule: IsInvalid(examFee.CreatedBy), Parameter: nameof(ExamFee.CreatedBy)),
                (Rule: IsInvalid(examFee.UpdatedBy), Parameter: nameof(ExamFee.UpdatedBy)),
                (Rule: IsInvalid(examFee.CreatedDate), Parameter: nameof(ExamFee.CreatedDate)),
                (Rule: IsInvalid(examFee.UpdatedDate), Parameter: nameof(ExamFee.UpdatedDate)),
                (Rule: IsNotRecent(examFee.UpdatedDate), Parameter: nameof(ExamFee.UpdatedDate)),

                (Rule: IsSame(
                     firstId: examFee.UpdatedDate,
                     secondId: examFee.CreatedDate,
                     secondIdName: nameof(ExamFee.CreatedDate)),
                 Parameter: nameof(ExamFee.UpdatedDate)));
        }
Пример #4
0
        public async Task ShouldDeleteExamFeeAsync()
        {
            // given
            ExamFee randomExamFee = await PostRandomExamFeeAsync();

            ExamFee inputExamFee    = randomExamFee;
            ExamFee expectedExamFee = inputExamFee;

            // when
            ExamFee deletedExamFee = await DeleteExamFeeAsync(inputExamFee);

            ValueTask <ExamFee> getExamFeeByIdTask =
                this.otripleSApiBroker.GetExamFeeByIdAsync(inputExamFee.Id);

            // then
            deletedExamFee.Should().BeEquivalentTo(expectedExamFee);

            await Assert.ThrowsAsync <HttpResponseNotFoundException>(() =>
                                                                     getExamFeeByIdTask.AsTask());
        }
Пример #5
0
        public async Task ShouldThrowValidationExceptionOnDeleteWhenStorageExamFeeIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset randomDateTime     = GetRandomDateTime();
            ExamFee        randomExamFee      = CreateRandomExamFee(randomDateTime);
            Guid           inputExamFeeId     = randomExamFee.Id;
            ExamFee        nullStorageExamFee = null;

            var notFoundExamFeeException = new NotFoundExamFeeException(inputExamFeeId);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(notFoundExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(inputExamFeeId))
            .ReturnsAsync(nullStorageExamFee);

            // when
            ValueTask <ExamFee> actualExamFeeDeleteTask =
                this.examFeeService.RemoveExamFeeByIdAsync(inputExamFeeId);

            // then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() => actualExamFeeDeleteTask.AsTask());

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Пример #6
0
        public async Task ShouldThrowValidationExceptionOnModifyWhenExamIdIsInvalidAndLogItAsync()
        {
            //given
            Guid           invalidExamFeeId = Guid.Empty;
            DateTimeOffset dateTime         = GetRandomDateTime();
            ExamFee        randomExamFee    = CreateRandomExamFee(dateTime);
            ExamFee        invalidExamFee   = randomExamFee;

            invalidExamFee.ExamId = invalidExamFeeId;

            var invalidExamFeeException = new InvalidExamFeeException(
                parameterName: nameof(ExamFee.ExamId),
                parameterValue: invalidExamFee.ExamId);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeException);

            //when
            ValueTask <ExamFee> modifyExamFeeTask =
                this.examFeeService.ModifyExamFeeAsync(invalidExamFee);

            //then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  modifyExamFeeTask.AsTask());

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnRetrieveWhenStorageExamFeeIsNullAndLogItAsync()
        {
            // given
            Guid    randomExamFeeId          = Guid.NewGuid();
            Guid    inputExamFeeId           = randomExamFeeId;
            ExamFee invalidStorageExamFee    = null;
            var     notFoundExamFeeException = new NotFoundExamFeeException(inputExamFeeId);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(notFoundExamFeeException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(inputExamFeeId))
            .ReturnsAsync(invalidStorageExamFee);

            // when
            ValueTask <ExamFee> retrieveExamFeeByIdTask =
                this.examFeeService.RetrieveExamFeeByIdAsync(inputExamFeeId);

            // then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  retrieveExamFeeByIdTask.AsTask());

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnCreateWhenUpdatedDateIsNotSameToCreatedDateAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime      = GetRandomDateTime();
            ExamFee        randomExamFee = CreateRandomExamFee(dateTime);
            ExamFee        inputExamFee  = randomExamFee;

            inputExamFee.UpdatedBy   = randomExamFee.CreatedBy;
            inputExamFee.UpdatedDate = GetRandomDateTime();

            var invalidExamFeeInputException = new InvalidExamFeeException();

            invalidExamFeeInputException.AddData(
                key: nameof(ExamFee.UpdatedDate),
                values: $"Date is not the same as {nameof(ExamFee.CreatedDate)}");

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

            // when
            ValueTask <ExamFee> createExamFeeTask =
                this.examFeeService.AddExamFeeAsync(inputExamFee);

            // then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  createExamFeeTask.AsTask());

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Пример #9
0
        public async Task ShouldAddExamFeeAsync()
        {
            // given
            DateTimeOffset dateTime      = DateTimeOffset.UtcNow;
            ExamFee        randomExamFee = CreateRandomExamFee();

            randomExamFee.UpdatedBy   = randomExamFee.CreatedBy;
            randomExamFee.UpdatedDate = randomExamFee.CreatedDate;
            ExamFee inputExamFee    = randomExamFee;
            ExamFee storageExamFee  = randomExamFee;
            ExamFee expectedExamFee = randomExamFee;

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

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertExamFeeAsync(inputExamFee))
            .ReturnsAsync(storageExamFee);

            // when
            ExamFee actualExamFee =
                await this.examFeeService.AddExamFeeAsync(inputExamFee);

            // then
            actualExamFee.Should().BeEquivalentTo(expectedExamFee);

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertExamFeeAsync(inputExamFee),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Пример #10
0
        public async Task ShouldDeleteExamFeeAsync()
        {
            // given
            DateTimeOffset dateTime        = GetRandomDateTime();
            ExamFee        randomExamFee   = CreateRandomExamFee(dateTime);
            Guid           inputExamFeeId  = randomExamFee.Id;
            ExamFee        inputExamFee    = randomExamFee;
            ExamFee        storageExamFee  = inputExamFee;
            ExamFee        expectedExamFee = storageExamFee;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(inputExamFeeId))
            .ReturnsAsync(inputExamFee);

            this.storageBrokerMock.Setup(broker =>
                                         broker.DeleteExamFeeAsync(inputExamFee))
            .ReturnsAsync(storageExamFee);

            // when
            ExamFee actualExamFee =
                await this.examFeeService.RemoveExamFeeByIdAsync(inputExamFeeId);

            //then
            actualExamFee.Should().BeEquivalentTo(expectedExamFee);

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteExamFeeAsync(inputExamFee),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnCreateWhenCreatedDateIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime      = GetRandomDateTime();
            ExamFee        randomExamFee = CreateRandomExamFee(dateTime);
            ExamFee        inputExamFee  = randomExamFee;

            inputExamFee.CreatedDate = default;

            var invalidExamFeeInputException = new InvalidExamFeeException(
                parameterName: nameof(ExamFee.CreatedDate),
                parameterValue: inputExamFee.CreatedDate);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

            // when
            ValueTask <ExamFee> createExamFeeTask =
                this.examFeeService.AddExamFeeAsync(inputExamFee);

            // then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  createExamFeeTask.AsTask());

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Пример #12
0
 public async ValueTask <ExamFee> PutExamFeeAsync(ExamFee examFee) =>
 await this.apiFactoryClient.PutContentAsync(ExamFeesRelativeUrl, examFee);
Пример #13
0
        public async Task ShouldThrowValidationExceptionOnModifyWhenIdsAreInvalidAndLogItAsync()
        {
            //given
            DateTimeOffset dateTime       = GetRandomDateTime();
            ExamFee        randomExamFee  = CreateRandomExamFee(dateTime);
            ExamFee        invalidExamFee = randomExamFee;

            invalidExamFee.Id        = Guid.Empty;
            invalidExamFee.ExamId    = Guid.Empty;
            invalidExamFee.FeeId     = Guid.Empty;
            invalidExamFee.CreatedBy = default;
            invalidExamFee.UpdatedBy = default;

            var invalidExamFeeException = new InvalidExamFeeException();

            invalidExamFeeException.AddData(
                key: nameof(ExamFee.Id),
                values: "Id is required");

            invalidExamFeeException.AddData(
                key: nameof(ExamFee.ExamId),
                values: "Id is required");

            invalidExamFeeException.AddData(
                key: nameof(ExamFee.FeeId),
                values: "Id is required");

            invalidExamFeeException.AddData(
                key: nameof(ExamFee.CreatedBy),
                values: "Id is required");

            invalidExamFeeException.AddData(
                key: nameof(ExamFee.UpdatedBy),
                values: "Id is required");

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeException);

            //when
            ValueTask <ExamFee> modifyExamFeeTask =
                this.examFeeService.ModifyExamFeeAsync(invalidExamFee);

            //then
            await Assert.ThrowsAsync <ExamFeeValidationException>(() =>
                                                                  modifyExamFeeTask.AsTask());

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

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

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

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