public async Task ShouldThrowValidationExceptionOnRetrieveIfStudentWasNotFoundAndLogItAsync()
        {
            // given
            Student noStudent            = null;
            Guid    nonExistentStudentId = Guid.NewGuid();

            var notFoundStudentException =
                new NotFoundStudentException(studentId: nonExistentStudentId);

            var expectedStudentValidationException =
                new StudentValidationException(notFoundStudentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentByIdAsync(nonExistentStudentId))
            .ReturnsAsync(noStudent);

            // when
            ValueTask <Student> retrieveStudentByIdTask =
                this.studentService.RetrieveStudentAsync(nonExistentStudentId);

            // then
            await Assert.ThrowsAsync <StudentValidationException>(() =>
                                                                  retrieveStudentByIdTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentByIdAsync(nonExistentStudentId),
                                          Times.Once);

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldThrowValidationExceptionOnModifyIfStudentDoesntExistAndLogItAsync()
        {
            DateTimeOffset randomDateTime     = GetRandomDateTime();
            Student        randomStudent      = CreateRandomStudent();
            Student        nonExistentStudent = randomStudent;

            nonExistentStudent.UpdatedDate = randomDateTime;
            Student noStudent = null;
            var     notFoundStudentException = new NotFoundStudentException(nonExistentStudent.Id);

            var expectedStudentValidationException =
                new StudentValidationException(notFoundStudentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentByIdAsync(nonExistentStudent.Id))
            .ReturnsAsync(noStudent);

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

            // when
            ValueTask <Student> modifyStudentTask =
                this.studentService.ModifyStudentAsync(nonExistentStudent);

            // then
            await Assert.ThrowsAsync <StudentValidationException>(() =>
                                                                  modifyStudentTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentByIdAsync(nonExistentStudent.Id),
                                          Times.Once);

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnDeleteWhenStorageStudentIsNullAndLogItAsync()
        {
            // given
            Guid    randomStudentId          = Guid.NewGuid();
            Guid    inputStudentId           = randomStudentId;
            Student invalidStorageStudent    = null;
            var     notFoundStudentException = new NotFoundStudentException(inputStudentId);

            var expectedStudentValidationException =
                new StudentValidationException(notFoundStudentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentByIdAsync(inputStudentId))
            .ReturnsAsync(invalidStorageStudent);

            // when
            ValueTask <Student> deleteStudentTask =
                this.studentService.RemoveStudentByIdAsync(inputStudentId);

            // then
            await Assert.ThrowsAsync <StudentValidationException>(() =>
                                                                  deleteStudentTask.AsTask());

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

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentByIdAsync(inputStudentId),
                                          Times.Once);

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

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