public void ShouldThrowDependencyExceptionOnRetrieveAllAssignmentAttachmentsWhenSqlExceptionOccursAndLogIt() { // given var sqlException = GetSqlException(); var expectedAssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectAllAssignmentAttachments()) .Throws(sqlException); // when . then Assert.Throws <AssignmentAttachmentDependencyException>(() => this.assignmentAttachmentService.RetrieveAllAssignmentAttachments()); this.storageBrokerMock.Verify(broker => broker.SelectAllAssignmentAttachments(), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs(expectedAssignmentAttachmentDependencyException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync() { // given AssignmentAttachment randomAssignmentAttachment = CreateRandomAssignmentAttachment(); AssignmentAttachment inputAssignmentAttachment = randomAssignmentAttachment; var databaseUpdateException = new DbUpdateException(); var expectedAssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.InsertAssignmentAttachmentAsync(inputAssignmentAttachment)) .ThrowsAsync(databaseUpdateException); // when ValueTask <AssignmentAttachment> addAssignmentAttachmentTask = this.assignmentAttachmentService.AddAssignmentAttachmentAsync(inputAssignmentAttachment); // then await Assert.ThrowsAsync <AssignmentAttachmentDependencyException>(() => addAssignmentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedAssignmentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertAssignmentAttachmentAsync(inputAssignmentAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
private AssignmentAttachmentDependencyException CreateAndLogDependencyException(Xeption exception) { var AssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(exception); this.loggingBroker.LogError(AssignmentAttachmentDependencyException); return(AssignmentAttachmentDependencyException); }
private AssignmentAttachmentDependencyException CreateAndLogCriticalDependencyException(Exception exception) { var AssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(exception); this.loggingBroker.LogCritical(AssignmentAttachmentDependencyException); return(AssignmentAttachmentDependencyException); }
public async Task ShouldThrowDependencyExceptionOnRetrieveWhenDbExceptionOccursAndLogItAsync() { // given Guid someAttachmentId = Guid.NewGuid(); Guid someAssignmentId = Guid.NewGuid(); var databaseUpdateException = new DbUpdateException(); var failedAssigmentAttachmentStorageException = new FailedAssignmentAttachmentStorageException(databaseUpdateException); var expectedAssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(failedAssigmentAttachmentStorageException); this.storageBrokerMock.Setup(broker => broker.SelectAssignmentAttachmentByIdAsync( It.IsAny <Guid>(), It.IsAny <Guid>())) .ThrowsAsync(databaseUpdateException); // when ValueTask <AssignmentAttachment> retrieveAssignmentAttachmentTask = this.assignmentAttachmentService.RetrieveAssignmentAttachmentByIdAsync( someAssignmentId, someAttachmentId); // then await Assert.ThrowsAsync <AssignmentAttachmentDependencyException>(() => retrieveAssignmentAttachmentTask.AsTask()); this.storageBrokerMock.Verify(broker => broker.SelectAssignmentAttachmentByIdAsync( It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedAssignmentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnRemoveWhenSqlExceptionOccursAndLogItAsync() { // given Guid someAttachmentId = Guid.NewGuid(); Guid someAssignmentId = Guid.NewGuid(); SqlException sqlException = GetSqlException(); var failedAssigmentAttachmentStorageException = new FailedAssignmentAttachmentStorageException(sqlException); var expectedAssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(failedAssigmentAttachmentStorageException); this.storageBrokerMock.Setup(broker => broker.SelectAssignmentAttachmentByIdAsync(someAssignmentId, someAttachmentId)) .ThrowsAsync(sqlException); // when ValueTask <AssignmentAttachment> removeAssignmentAttachmentTask = this.assignmentAttachmentService.RemoveAssignmentAttachmentByIdAsync( someAssignmentId, someAttachmentId); // then await Assert.ThrowsAsync <AssignmentAttachmentDependencyException>(() => removeAssignmentAttachmentTask.AsTask()); this.storageBrokerMock.Verify(broker => broker.SelectAssignmentAttachmentByIdAsync(someAssignmentId, someAttachmentId), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs(expectedAssignmentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteAssignmentAttachmentAsync(It.IsAny <AssignmentAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnAddWhenSqlExceptionOccursAndLogItAsync() { // given AssignmentAttachment someAssignmentAttachment = CreateRandomAssignmentAttachment(); var sqlException = GetSqlException(); var failedAssigmentAttachmentStorageException = new FailedAssignmentAttachmentStorageException(sqlException); var expectedAssignmentAttachmentDependencyException = new AssignmentAttachmentDependencyException(failedAssigmentAttachmentStorageException); this.storageBrokerMock.Setup(broker => broker.InsertAssignmentAttachmentAsync(It.IsAny <AssignmentAttachment>())) .ThrowsAsync(sqlException); // when ValueTask <AssignmentAttachment> addAssignmentAttachmentTask = this.assignmentAttachmentService.AddAssignmentAttachmentAsync(someAssignmentAttachment); // then await Assert.ThrowsAsync <AssignmentAttachmentDependencyException>(() => addAssignmentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( expectedAssignmentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertAssignmentAttachmentAsync(It.IsAny <AssignmentAttachment>()), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }