private AssignmentAttachmentDependencyValidationException CreateAndLogDependencyValidationException( Exception exception) { var assignmentAttachmentDependencyValidationException = new AssignmentAttachmentDependencyValidationException(exception); this.loggingBroker.LogError(assignmentAttachmentDependencyValidationException); return(assignmentAttachmentDependencyValidationException); }
public async Task ShouldThrowDependencyValidationOnRemoveWhenDbUpdateConcurrencyExceptionOccursAndLogItAsync() { // given Guid someAttachmentId = Guid.NewGuid(); Guid someAssignmentId = Guid.NewGuid(); var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedAttachmentException = new LockedAssignmentAttachmentException(databaseUpdateConcurrencyException); var expectedAssignmentAttachmentDependencyValidationException = new AssignmentAttachmentDependencyValidationException(lockedAttachmentException); this.storageBrokerMock.Setup(broker => broker.SelectAssignmentAttachmentByIdAsync(someAssignmentId, someAttachmentId)) .ThrowsAsync(databaseUpdateConcurrencyException); // when ValueTask <AssignmentAttachment> removeAssignmentAttachmentTask = this.assignmentAttachmentService .RemoveAssignmentAttachmentByIdAsync( assignmentId: someAssignmentId, attachmentId: someAttachmentId); // then await Assert.ThrowsAsync <AssignmentAttachmentDependencyValidationException>(() => removeAssignmentAttachmentTask.AsTask()); this.storageBrokerMock.Verify(broker => broker.SelectAssignmentAttachmentByIdAsync(someAssignmentId, someAttachmentId), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedAssignmentAttachmentDependencyValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteAssignmentAttachmentAsync(It.IsAny <AssignmentAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }