public async void ShouldThrowValidationExceptionOnAddWhenRegistrationIdIsInvalidAndLogItAsync()
        {
            // given
            StudentRegistration randomStudentRegistration = CreateRandomStudentRegistration();
            StudentRegistration inputStudentRegistration  = randomStudentRegistration;

            inputStudentRegistration.RegistrationId = default;

            var invalidStudentRegistrationInputException = new InvalidStudentRegistrationException(
                parameterName: nameof(StudentRegistration.RegistrationId),
                parameterValue: inputStudentRegistration.RegistrationId);

            var expectedStudentRegistrationValidationException =
                new StudentRegistrationValidationException(invalidStudentRegistrationInputException);

            // when
            ValueTask <StudentRegistration> addStudentRegistrationTask =
                this.studentRegistrationService.AddStudentRegistrationAsync(inputStudentRegistration);

            // then
            await Assert.ThrowsAsync <StudentRegistrationValidationException>(() =>
                                                                              addStudentRegistrationTask.AsTask());

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
コード例 #2
0
        public async void ShouldThrowValidationExceptionOnRetrieveWhenIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomStudentId      = default;
            Guid inputStudentId       = randomStudentId;
            Guid randomRegistrationId = default;
            Guid inputRegistrationId  = randomRegistrationId;
            var  invalidStudentRegistrationInputException = new InvalidStudentRegistrationException(
                parameterName: nameof(StudentRegistration.StudentId),
                parameterValue: inputStudentId);

            var expectedStudentRegistrationValidationException =
                new StudentRegistrationValidationException(invalidStudentRegistrationInputException);

            // when
            ValueTask <StudentRegistration> retrieveStudentRegistrationByIdTask =
                this.studentRegistrationService.RetrieveStudentRegistrationByIdAsync(inputStudentId, inputRegistrationId);

            // then
            await Assert.ThrowsAsync <StudentRegistrationValidationException>(() =>
                                                                              retrieveStudentRegistrationByIdTask.AsTask());

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

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

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