public async Task ShouldThrowValidatonExceptionOnRetrieveWhenContactIdIsInvalidAndLogItAsync() { // given Guid invalidContactId = Guid.Empty; Guid randomGuardianId = Guid.NewGuid(); Guid inputContactId = invalidContactId; Guid inputGuardianId = randomGuardianId; var invalidGuardianContactException = new InvalidGuardianContactException( parameterName: nameof(GuardianContact.ContactId), parameterValue: inputContactId); var expectedGuardianContactValidationException = new GuardianContactValidationException(invalidGuardianContactException); // 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(); }
public async void ShouldThrowValidationExceptionOnAddWhenContactIdIsInvalidAndLogItAsync() { // given GuardianContact randomGuardianContact = CreateRandomGuardianContact(); GuardianContact inputGuardianContact = randomGuardianContact; inputGuardianContact.ContactId = default; var invalidGuardianContactException = new InvalidGuardianContactException( parameterName: nameof(GuardianContact.ContactId), parameterValue: inputGuardianContact.ContactId); var expectedGuardianContactValidationException = new GuardianContactValidationException(invalidGuardianContactException); // 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(); }