Exemple #1
0
        public async Task ShouldThrowValidationExceptionOnModifyWhenGuardianIsNullAndLogItAsync()
        {
            //given
            Guardian invalidGuardian       = null;
            var      nullGuardianException = new NullGuardianException();

            var expectedGuardianValidationException =
                new GuardianValidationException(nullGuardianException);

            //when
            ValueTask <Guardian> modifyGuardianTask =
                this.guardianService.ModifyGuardianAsync(invalidGuardian);

            //then
            await Assert.ThrowsAsync <GuardianValidationException>(() =>
                                                                   modifyGuardianTask.AsTask());

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenGuardianIsNullAndLogItAsync()
        {
            // given
            Guardian randomGuardian        = default;
            Guardian nullGuardian          = randomGuardian;
            var      nullGuardianException = new NullGuardianException();

            var expectedGuardianValidationException =
                new GuardianValidationException(nullGuardianException);

            // when
            ValueTask <Guardian> createGuardianTask =
                this.guardianService.CreateGuardianAsync(nullGuardian);

            // then
            await Assert.ThrowsAsync <GuardianValidationException>(() =>
                                                                   createGuardianTask.AsTask());

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

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

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