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 void ShouldThrowValidationExceptionOnAddWhenGuardianAttachmentIsNullAndLogItAsync() { // given GuardianAttachment randomGuardianAttachment = default; GuardianAttachment nullGuardianAttachment = randomGuardianAttachment; var nullGuardianAttachmentException = new NullGuardianAttachmentException(); var expectedGuardianAttachmentValidationException = new GuardianAttachmentValidationException(nullGuardianAttachmentException); // when ValueTask <GuardianAttachment> addGuardianAttachmentTask = this.guardianAttachmentService.AddGuardianAttachmentAsync(nullGuardianAttachment); // 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(); }
private GuardianAttachmentValidationException CreateAndLogValidationException(Exception exception) { var guardianAttachmentValidationException = new GuardianAttachmentValidationException(exception); this.loggingBroker.LogError(guardianAttachmentValidationException); return(guardianAttachmentValidationException); }
public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageGuardianAttachmentIsInvalidAndLogItAsync() { // given DateTimeOffset randomDateTime = GetRandomDateTime(); GuardianAttachment randomGuardianAttachment = CreateRandomGuardianAttachment(randomDateTime); Guid inputAttachmentId = randomGuardianAttachment.AttachmentId; Guid inputGuardianId = randomGuardianAttachment.GuardianId; GuardianAttachment nullStorageGuardianAttachment = null; var notFoundGuardianAttachmentException = new NotFoundGuardianAttachmentException(inputGuardianId, inputAttachmentId); var expectedSemesterCourseValidationException = new GuardianAttachmentValidationException(notFoundGuardianAttachmentException); this.storageBrokerMock.Setup(broker => broker.SelectGuardianAttachmentByIdAsync(inputGuardianId, inputAttachmentId)) .ReturnsAsync(nullStorageGuardianAttachment); // when ValueTask <GuardianAttachment> removeGuardianAttachmentTask = this.guardianAttachmentService.RemoveGuardianAttachmentByIdAsync(inputGuardianId, inputAttachmentId); // then await Assert.ThrowsAsync <GuardianAttachmentValidationException>(() => removeGuardianAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedSemesterCourseValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectGuardianAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteGuardianAttachmentAsync(It.IsAny <GuardianAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync() { // given GuardianAttachment randomGuardianAttachment = CreateRandomGuardianAttachment(); GuardianAttachment invalidGuardianAttachment = randomGuardianAttachment; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage); var invalidGuardianAttachmentReferenceException = new InvalidGuardianAttachmentReferenceException(foreignKeyConstraintConflictException); var expectedGuardianAttachmentValidationException = new GuardianAttachmentValidationException(invalidGuardianAttachmentReferenceException); this.storageBrokerMock.Setup(broker => broker.InsertGuardianAttachmentAsync(invalidGuardianAttachment)) .ThrowsAsync(foreignKeyConstraintConflictException); // when ValueTask <GuardianAttachment> addGuardianAttachmentTask = this.guardianAttachmentService.AddGuardianAttachmentAsync(invalidGuardianAttachment); // 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(invalidGuardianAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenGuardianAttachmentAlreadyExistsAndLogItAsync() { // given GuardianAttachment randomGuardianAttachment = CreateRandomGuardianAttachment(); GuardianAttachment alreadyExistsGuardianAttachment = randomGuardianAttachment; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var duplicateKeyException = new DuplicateKeyException(exceptionMessage); var alreadyExistsGuardianAttachmentException = new AlreadyExistsGuardianAttachmentException(duplicateKeyException); var expectedGuardianAttachmentValidationException = new GuardianAttachmentValidationException(alreadyExistsGuardianAttachmentException); this.storageBrokerMock.Setup(broker => broker.InsertGuardianAttachmentAsync(alreadyExistsGuardianAttachment)) .ThrowsAsync(duplicateKeyException); // when ValueTask <GuardianAttachment> addGuardianAttachmentTask = this.guardianAttachmentService.AddGuardianAttachmentAsync(alreadyExistsGuardianAttachment); // 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(alreadyExistsGuardianAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }