public async Task ShouldThrowValidationExceptionOnModifyWhenSemesterCourseIdIsInvalidAndLogItAsync()
        {
            //given
            Guid           invalidSemesterCourseId = Guid.Empty;
            DateTimeOffset dateTime              = GetRandomDateTime();
            SemesterCourse randomSemesterCourse  = CreateRandomSemesterCourse(dateTime);
            SemesterCourse invalidSemesterCourse = randomSemesterCourse;

            invalidSemesterCourse.Id = invalidSemesterCourseId;

            var invalidSemesterCourseInputException = new InvalidSemesterCourseException(
                parameterName: nameof(SemesterCourse.Id),
                parameterValue: invalidSemesterCourse.Id);

            var expectedSemesterCourseValidationException =
                new SemesterCourseValidationException(invalidSemesterCourseInputException);

            //when
            ValueTask <SemesterCourse> modifySemesterCourseTask =
                this.semesterCourseService.ModifySemesterCourseAsync(invalidSemesterCourse);

            //then
            await Assert.ThrowsAsync <SemesterCourseValidationException>(() =>
                                                                         modifySemesterCourseTask.AsTask());

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedByNotSameAsCreatedByAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            Guid           differentId           = Guid.NewGuid();
            Guid           invalidCreatedBy      = differentId;
            DateTimeOffset randomDate            = GetRandomDateTime();
            SemesterCourse randomSemesterCourse  = CreateRandomSemesterCourse(randomDate);
            SemesterCourse invalidSemesterCourse = randomSemesterCourse;

            invalidSemesterCourse.CreatedDate = randomDate.AddMinutes(randomNegativeMinutes);
            SemesterCourse storageSemesterCourse = randomSemesterCourse.DeepClone();
            Guid           semesterCourseId      = invalidSemesterCourse.Id;

            invalidSemesterCourse.CreatedBy = invalidCreatedBy;

            var invalidSemesterCourseInputException = new InvalidSemesterCourseException(
                parameterName: nameof(SemesterCourse.CreatedBy),
                parameterValue: invalidSemesterCourse.CreatedBy);

            var expectedSemesterCourseValidationException =
                new SemesterCourseValidationException(invalidSemesterCourseInputException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectSemesterCourseByIdAsync(semesterCourseId))
            .ReturnsAsync(storageSemesterCourse);

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

            // when
            ValueTask <SemesterCourse> modifySemesterCourseTask =
                this.semesterCourseService.ModifySemesterCourseAsync(invalidSemesterCourse);

            // then
            await Assert.ThrowsAsync <SemesterCourseValidationException>(() =>
                                                                         modifySemesterCourseTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectSemesterCourseByIdAsync(invalidSemesterCourse.Id),
                                          Times.Once);

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnModifyWhenUpdatedDateIsNotRecentAndLogItAsync(
            int minutes)
        {
            // given
            DateTimeOffset dateTime             = GetRandomDateTime();
            SemesterCourse randomSemesterCourse = CreateRandomSemesterCourse(dateTime);
            SemesterCourse inputSemesterCourse  = randomSemesterCourse;

            inputSemesterCourse.UpdatedBy   = inputSemesterCourse.CreatedBy;
            inputSemesterCourse.CreatedDate = inputSemesterCourse.CreatedDate;
            inputSemesterCourse.UpdatedDate = dateTime.AddMinutes(minutes);

            var invalidSemesterCourseInputException = new InvalidSemesterCourseException(
                parameterName: nameof(SemesterCourse.UpdatedDate),
                parameterValue: inputSemesterCourse.UpdatedDate);

            var expectedSemesterCourseValidationException =
                new SemesterCourseValidationException(invalidSemesterCourseInputException);

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

            // when
            ValueTask <SemesterCourse> modifySemesterCourseTask =
                this.semesterCourseService.ModifySemesterCourseAsync(inputSemesterCourse);

            // then
            await Assert.ThrowsAsync <SemesterCourseValidationException>(() =>
                                                                         modifySemesterCourseTask.AsTask());

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnRetrieveWhenIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomSemesterCourseId = default;
            Guid inputSemesterCourseId  = randomSemesterCourseId;

            var invalidSemesterCourseInputException = new InvalidSemesterCourseException(
                parameterName: nameof(SemesterCourse.Id),
                parameterValue: inputSemesterCourseId);

            var expectedSemesterCourseValidationException =
                new SemesterCourseValidationException(invalidSemesterCourseInputException);

            // when
            ValueTask <SemesterCourse> retrieveSemesterCourseByIdTask =
                this.semesterCourseService.RetrieveSemesterCourseByIdAsync(inputSemesterCourseId);

            // then
            await Assert.ThrowsAsync <SemesterCourseValidationException>(() =>
                                                                         retrieveSemesterCourseByIdTask.AsTask());

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnCreateWhenStartDateIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime             = GetRandomDateTime();
            SemesterCourse randomSemesterCourse = CreateRandomSemesterCourse(dateTime);
            SemesterCourse inputSemesterCourse  = randomSemesterCourse;

            inputSemesterCourse.StartDate = default;

            var invalidSemesterCourseInputException = new InvalidSemesterCourseException(
                parameterName: nameof(SemesterCourse.StartDate),
                parameterValue: inputSemesterCourse.StartDate);

            var expectedSemesterCourseValidationException =
                new SemesterCourseValidationException(invalidSemesterCourseInputException);

            // when
            ValueTask <SemesterCourse> createSemesterCourseTask =
                this.semesterCourseService.CreateSemesterCourseAsync(inputSemesterCourse);

            // then
            await Assert.ThrowsAsync <SemesterCourseValidationException>(() =>
                                                                         createSemesterCourseTask.AsTask());

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

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

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