public void ShouldThrowDependencyExceptionOnRetrieveAllExamAttachmentsWhenSqlExceptionOccursAndLogIt() { // given var sqlException = GetSqlException(); var expectedExamAttachmentDependencyException = new ExamAttachmentDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectAllExamAttachments()) .Throws(sqlException); // when Action retrieveAllExamAttachmentsAction = () => this.examAttachmentService.RetrieveAllExamAttachments(); // then Assert.Throws <ExamAttachmentDependencyException>( retrieveAllExamAttachmentsAction); this.storageBrokerMock.Verify(broker => broker.SelectAllExamAttachments(), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( expectedExamAttachmentDependencyException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync() { // given ExamAttachment randomExamAttachment = CreateRandomExamAttachment(); ExamAttachment someExamAttachment = randomExamAttachment; var databaseUpdateException = new DbUpdateException(); var expectedExamAttachmentDependencyException = new ExamAttachmentDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.InsertExamAttachmentAsync(someExamAttachment)) .ThrowsAsync(databaseUpdateException); // when ValueTask <ExamAttachment> addExamAttachmentTask = this.examAttachmentService.AddExamAttachmentAsync(someExamAttachment); // then await Assert.ThrowsAsync <ExamAttachmentDependencyException>(() => addExamAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedExamAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertExamAttachmentAsync(someExamAttachment), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public void ShouldThrowDependencyExceptionOnRetrieveAllExamAttachmentsWhenDbExceptionOccursAndLogIt() { // given var databaseUpdateException = new DbUpdateException(); var expectedAttachmentDependencyException = new ExamAttachmentDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.SelectAllExamAttachments()) .Throws(databaseUpdateException); // when . then Assert.Throws <ExamAttachmentDependencyException>(() => this.examAttachmentService.RetrieveAllExamAttachments()); this.storageBrokerMock.Verify(broker => broker.SelectAllExamAttachments(), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedAttachmentDependencyException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
private ExamAttachmentDependencyException CreateAndLogDependencyException(Exception exception) { var examAttachmentDependencyException = new ExamAttachmentDependencyException(exception); this.loggingBroker.LogError(examAttachmentDependencyException); return(examAttachmentDependencyException); }
public async Task ShouldThrowDependencyExceptionOnRemoveWhenDbUpdateConcurrencyExceptionOccursAndLogItAsync() { // given Guid someAttachmentId = Guid.NewGuid(); Guid someExamId = Guid.NewGuid(); var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedAttachmentException = new LockedExamAttachmentException(databaseUpdateConcurrencyException); var expectedExamAttachmentException = new ExamAttachmentDependencyException(lockedAttachmentException); this.storageBrokerMock.Setup(broker => broker.SelectExamAttachmentByIdAsync(someExamId, someAttachmentId)) .ThrowsAsync(databaseUpdateConcurrencyException); // when ValueTask <ExamAttachment> removeExamAttachmentTask = this.examAttachmentService.RemoveExamAttachmentByIdAsync(someExamId, someAttachmentId); // then await Assert.ThrowsAsync <ExamAttachmentDependencyException>(() => removeExamAttachmentTask.AsTask()); this.storageBrokerMock.Verify(broker => broker.SelectExamAttachmentByIdAsync(someExamId, someAttachmentId), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedExamAttachmentException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteExamAttachmentAsync(It.IsAny <ExamAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnRetrieveWhenSqlExceptionOccursAndLogItAsync() { // given Guid someAttachmentId = Guid.NewGuid(); Guid someExamId = Guid.NewGuid(); SqlException sqlException = GetSqlException(); var expectedExamAttachmentDependencyException = new ExamAttachmentDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectExamAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>())) .ThrowsAsync(sqlException); // when ValueTask <ExamAttachment> retrieveExamAttachmentTask = this.examAttachmentService.RetrieveExamAttachmentByIdAsync( someExamId, someAttachmentId); // then await Assert.ThrowsAsync <ExamAttachmentDependencyException>(() => retrieveExamAttachmentTask.AsTask()); this.storageBrokerMock.Verify(broker => broker.SelectExamAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( expectedExamAttachmentDependencyException))), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }