コード例 #1
0
        public async Task ShouldThrowValidationExceptionOnModifyWhenRegistrationIsNullAndLogItAsync()
        {
            //given
            Registration invalidRegistration       = null;
            var          nullRegistrationException = new NullRegistrationException();

            var expectedRegistrationValidationException =
                new RegistrationValidationException(nullRegistrationException);

            //when
            ValueTask <Registration> modifyRegistrationTask =
                this.registrationService.ModifyRegistrationAsync(invalidRegistration);

            //then
            await Assert.ThrowsAsync <RegistrationValidationException>(() =>
                                                                       modifyRegistrationTask.AsTask());

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
コード例 #2
0
        public async void ShouldThrowValidationExceptionOnAddWhenRegistrationIsNullAndLogItAsync()
        {
            // given
            Registration randomRegistration        = default;
            Registration nullRegistration          = randomRegistration;
            var          nullRegistrationException = new NullRegistrationException();

            var expectedRegistrationValidationException =
                new RegistrationValidationException(nullRegistrationException);

            // when
            ValueTask <Registration> createRegistrationTask =
                this.registrationService.AddRegistrationAsync(nullRegistration);

            // then
            await Assert.ThrowsAsync <RegistrationValidationException>(() =>
                                                                       createRegistrationTask.AsTask());

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

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

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