Beispiel #1
0
        public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageStudentRegistrationIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset      randomDateTime            = GetRandomDateTime();
            StudentRegistration randomStudentRegistration = CreateRandomStudentRegistration();
            Guid inputStudentRegistrationId           = randomStudentRegistration.RegistrationId;
            Guid inputStudentId                       = randomStudentRegistration.StudentId;
            StudentRegistration noStudentRegistration = null;

            var notFoundStudentRegistrationException =
                new NotFoundStudentRegistrationException(inputStudentRegistrationId, inputStudentId);

            var expectedStudentRegistrationValidationException =
                new StudentRegistrationValidationException(notFoundStudentRegistrationException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentRegistrationByIdAsync(inputStudentRegistrationId, inputStudentId))
            .ReturnsAsync(noStudentRegistration);
            // when
            ValueTask <StudentRegistration> actualStudentRegistrationDeleteTask =
                this.studentRegistrationService.RemoveStudentRegistrationByIdsAsync(
                    inputStudentRegistrationId,
                    inputStudentId);

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

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public async void ShouldThrowValidationExceptionOnRetrieveWhenStorageStudentRegistrationIsNullAndLogItAsync()
        {
            // given
            Guid randomStudentId      = Guid.NewGuid();
            Guid inputStudentId       = randomStudentId;
            Guid randomRegistrationId = Guid.NewGuid();
            Guid inputRegistrationId  = randomRegistrationId;
            StudentRegistration invalidStorageStudentRegistration = null;
            var notFoundStudentRegistrationException = new NotFoundStudentRegistrationException(inputStudentId, inputRegistrationId);

            var expectedStudentRegistrationValidationException =
                new StudentRegistrationValidationException(notFoundStudentRegistrationException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentRegistrationByIdAsync(inputStudentId, inputRegistrationId))
            .ReturnsAsync(invalidStorageStudentRegistration);

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

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

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