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 Task ShouldModifySemesterCourseAsync()
        {
            // given
            int            randomNumber                      = GetRandomNumber();
            int            randomDays                        = randomNumber;
            DateTimeOffset randomDate                        = GetRandomDateTime();
            DateTimeOffset randomInputDate                   = GetRandomDateTime();
            SemesterCourse randomSemesterCourse              = CreateRandomSemesterCourse(randomInputDate);
            SemesterCourse inputSemesterCourse               = randomSemesterCourse;
            SemesterCourse afterUpdateStorageSemesterCourse  = inputSemesterCourse;
            SemesterCourse expectedSemesterCourse            = afterUpdateStorageSemesterCourse;
            SemesterCourse beforeUpdateStorageSemesterCourse = randomSemesterCourse.DeepClone();

            inputSemesterCourse.UpdatedDate = randomDate;
            Guid semesterCourseId = inputSemesterCourse.Id;

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

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

            this.storageBrokerMock.Setup(broker =>
                                         broker.UpdateSemesterCourseAsync(inputSemesterCourse))
            .ReturnsAsync(afterUpdateStorageSemesterCourse);

            // when
            SemesterCourse actualSemesterCourse =
                await this.semesterCourseService.ModifySemesterCourseAsync(inputSemesterCourse);

            // then
            actualSemesterCourse.Should().BeEquivalentTo(expectedSemesterCourse);

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.UpdateSemesterCourseAsync(inputSemesterCourse),
                                          Times.Once);

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