public async void ShouldThrowValidationExceptionOnAddWhenFeeIdIsInvalidAndLogItAsync()
        {
            // given
            ExamFee randomExamFee = CreateRandomExamFee();
            ExamFee inputExamFee  = randomExamFee;

            inputExamFee.FeeId = default;

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

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

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

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

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

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

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

            inputExamFee.CreatedBy   = default;
            inputExamFee.CreatedDate = default;
            inputExamFee.UpdatedBy   = default;
            inputExamFee.UpdatedDate = default;

            var invalidExamFeeInputException = new InvalidExamFeeException();

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

            invalidExamFeeInputException.AddData(
                key: nameof(ExamFee.CreatedDate),
                values: "Date is required");

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

            invalidExamFeeInputException.AddData(
                key: nameof(ExamFee.UpdatedDate),
                values: "Date is required");

            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.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Exemplo n.º 3
0
        public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedByNotSameAsCreatedByAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            Guid           differentId           = Guid.NewGuid();
            Guid           invalidCreatedBy      = differentId;
            DateTimeOffset randomDate            = GetRandomDateTime();
            ExamFee        randomExamFee         = CreateRandomExamFee(randomDate);
            ExamFee        invalidExamFee        = randomExamFee;

            invalidExamFee.CreatedDate = randomDate.AddMinutes(randomNegativeMinutes);
            ExamFee storageExamFee = randomExamFee.DeepClone();
            Guid    examFeeId      = invalidExamFee.Id;

            invalidExamFee.CreatedBy = invalidCreatedBy;

            var invalidExamFeeInputException = new InvalidExamFeeException(
                parameterName: nameof(ExamFee.CreatedBy),
                parameterValue: invalidExamFee.CreatedBy);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectExamFeeByIdAsync(examFeeId))
            .ReturnsAsync(storageExamFee);

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

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

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

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Exemplo n.º 4
0
        public async void ShouldThrowValidationExceptionOnModifyWhenUpdatedDateIsNotRecentAndLogItAsync(
            int minutes)
        {
            // given
            DateTimeOffset dateTime      = GetRandomDateTime();
            ExamFee        randomExamFee = CreateRandomExamFee(dateTime);
            ExamFee        inputExamFee  = randomExamFee;

            inputExamFee.UpdatedBy   = inputExamFee.CreatedBy;
            inputExamFee.UpdatedDate = dateTime.AddMinutes(minutes);

            var invalidExamFeeInputException = new InvalidExamFeeException();

            invalidExamFeeInputException.AddData(
                key: nameof(ExamFee.UpdatedDate),
                values: $"Date is not recent");

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

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

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

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

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

            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();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenIdsAreInvalidAndLogItAsync()
        {
            // given
            ExamFee randomExamFee = CreateRandomExamFee();
            ExamFee inputExamFee  = randomExamFee;

            inputExamFee.ExamId = default;
            inputExamFee.FeeId  = default;

            var invalidExamFeeInputException = new InvalidExamFeeException();

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

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

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

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

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

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Exemplo n.º 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 ShouldThrowValidationExceptionOnRetrieveWhenIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomExamFeeId = default;
            Guid inputExamFeeId  = randomExamFeeId;

            var invalidExamFeeInputException = new InvalidExamFeeException(
                parameterName: nameof(ExamFee.Id),
                parameterValue: inputExamFeeId);

            var expectedExamFeeValidationException =
                new ExamFeeValidationException(invalidExamFeeInputException);

            // 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(It.IsAny <Guid>()),
                                          Times.Never);

            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(
                parameterName: nameof(ExamFee.UpdatedDate),
                parameterValue: inputExamFee.UpdatedDate);

            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.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }