public async Task ShouldThrowValidationExceptionOnModifyIfStudentIsNullAndLogItAsync()
        {
            //given
            Student noStudent            = null;
            var     nullStudentException = new NullStudentException();

            var expectedStudentValidationException =
                new StudentValidationException(nullStudentException);

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

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

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

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnRegisterWhenStudentIsNullAndLogItAsync()
        {
            // given
            Student randomStudent = null;
            Student nullStudent   = randomStudent;

            var nullStudentException = new NullStudentException();

            var expectedStudentValidationException =
                new StudentValidationException(nullStudentException);

            // when
            ValueTask <Student> registerStudentTask =
                this.studentService.RegisterStudentAsync(nullStudent);

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

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
예제 #3
0
        public async Task ShouldThrowValidationExceptionOnRegisterIfStudentIsNullAndLogItAsync()
        {
            // given
            Student invalidStudent       = null;
            var     nullStudentException = new NullStudentException();

            var expectedStudentValidationException =
                new StudentValidationException(nullStudentException);

            // when
            ValueTask <Student> submitStudentTask =
                this.studentService.RegisterStudentAsync(invalidStudent);

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

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

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

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