public async void ShouldThrowValidationExceptionOnAddWhenContactIdIsInvalidAndLogItAsync()
        {
            // given
            GuardianContact randomGuardianContact = CreateRandomGuardianContact();
            GuardianContact inputGuardianContact  = randomGuardianContact;

            inputGuardianContact.ContactId = default;

            var invalidGuardianContactInputException = new InvalidGuardianContactInputException(
                parameterName: nameof(GuardianContact.ContactId),
                parameterValue: inputGuardianContact.ContactId);

            var expectedGuardianContactValidationException =
                new GuardianContactValidationException(invalidGuardianContactInputException);

            // when
            ValueTask <GuardianContact> addGuardianContactTask =
                this.guardianContactService.AddGuardianContactAsync(inputGuardianContact);

            // then
            await Assert.ThrowsAsync <GuardianContactValidationException>(() =>
                                                                          addGuardianContactTask.AsTask());

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 2
0
        public async Task ShouldThrowValidatonExceptionOnRetrieveWhenContactIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomContactId  = default;
            Guid randomGuardianId = Guid.NewGuid();
            Guid inputContactId   = randomContactId;
            Guid inputGuardianId  = randomGuardianId;

            var invalidGuardianContactInputException = new InvalidGuardianContactInputException(
                parameterName: nameof(GuardianContact.ContactId),
                parameterValue: inputContactId);

            var expectedGuardianContactValidationException =
                new GuardianContactValidationException(invalidGuardianContactInputException);

            // when
            ValueTask <GuardianContact> retrieveGuardianContactTask =
                this.guardianContactService.RetrieveGuardianContactByIdAsync(inputGuardianId, inputContactId);

            // then
            await Assert.ThrowsAsync <GuardianContactValidationException>(() => retrieveGuardianContactTask.AsTask());

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

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

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