public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync() { // given GuardianAttachment randomGuardianAttachment = CreateRandomGuardianAttachment(); GuardianAttachment inputGuardianAttachment = randomGuardianAttachment; inputGuardianAttachment.AttachmentId = default; var invalidGuardianAttachmentInputException = new InvalidGuardianAttachmentException( parameterName: nameof(GuardianAttachment.AttachmentId), parameterValue: inputGuardianAttachment.AttachmentId); var expectedGuardianAttachmentValidationException = new GuardianAttachmentValidationException(invalidGuardianAttachmentInputException); // when ValueTask <GuardianAttachment> addGuardianAttachmentTask = this.guardianAttachmentService.AddGuardianAttachmentAsync(inputGuardianAttachment); // then await Assert.ThrowsAsync <GuardianAttachmentValidationException>(() => addGuardianAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedGuardianAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertGuardianAttachmentAsync(It.IsAny <GuardianAttachment>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidatonExceptionOnRetrieveWhenAttachmentIdIsInvalidAndLogItAsync() { // given Guid randomAttachmentId = default; Guid randomGuardianId = Guid.NewGuid(); Guid inputAttachmentId = randomAttachmentId; Guid inputGuardianId = randomGuardianId; var invalidGuardianAttachmentInputException = new InvalidGuardianAttachmentException( parameterName: nameof(GuardianAttachment.AttachmentId), parameterValue: inputAttachmentId); var expectedGuardianAttachmentValidationException = new GuardianAttachmentValidationException(invalidGuardianAttachmentInputException); // when ValueTask <GuardianAttachment> actualGuardianAttachmentTask = this.guardianAttachmentService.RetrieveGuardianAttachmentByIdAsync(inputGuardianId, inputAttachmentId); // then await Assert.ThrowsAsync <GuardianAttachmentValidationException>(() => actualGuardianAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedGuardianAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectGuardianAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }