public void ShouldThrowDependencyExceptionOnRetrieveAllStudentAttachmentsWhenSqlExceptionOccursAndLogIt() { // given var sqlException = GetSqlException(); var expectedStudentAttachmentDependencyException = new StudentAttachmentDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectAllStudentAttachments()) .Throws(sqlException); // when . then Assert.Throws <StudentAttachmentDependencyException>(() => this.studentAttachmentService.RetrieveAllStudentAttachments()); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs(expectedStudentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectAllStudentAttachments(), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync() { // given StudentAttachment randomStudentAttachment = CreateRandomStudentAttachment(); StudentAttachment inputStudentAttachment = randomStudentAttachment; var databaseUpdateException = new DbUpdateException(); var expectedStudentAttachmentDependencyException = new StudentAttachmentDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.InsertStudentAttachmentAsync(inputStudentAttachment)) .ThrowsAsync(databaseUpdateException); // when ValueTask <StudentAttachment> addStudentAttachmentTask = this.studentAttachmentService.AddStudentAttachmentAsync(inputStudentAttachment); // then await Assert.ThrowsAsync <StudentAttachmentDependencyException>(() => addStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentAttachmentAsync(inputStudentAttachment), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
private StudentAttachmentDependencyException CreateAndLogDependencyException(Exception exception) { var StudentAttachmentDependencyException = new StudentAttachmentDependencyException(exception); this.loggingBroker.LogError(StudentAttachmentDependencyException); return(StudentAttachmentDependencyException); }
private StudentAttachmentDependencyException CreateAndLogCriticalDependencyException(Exception exception) { var studentAttachmentDependencyException = new StudentAttachmentDependencyException(exception); this.loggingBroker.LogCritical(studentAttachmentDependencyException); return(studentAttachmentDependencyException); }
public async Task ShouldThrowDependencyExceptionOnRemoveWhenDbUpdateConcurrencyExceptionOccursAndLogItAsync() { // given var randomAttachmentId = Guid.NewGuid(); var randomStudentId = Guid.NewGuid(); Guid someAttachmentId = randomAttachmentId; Guid someStudentId = randomStudentId; var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedAttachmentException = new LockedStudentAttachmentException(databaseUpdateConcurrencyException); var expectedStudentAttachmentException = new StudentAttachmentDependencyException(lockedAttachmentException); this.storageBrokerMock.Setup(broker => broker.SelectStudentAttachmentByIdAsync(someStudentId, someAttachmentId)) .ThrowsAsync(databaseUpdateConcurrencyException); // when ValueTask <StudentAttachment> removeStudentAttachmentTask = this.studentAttachmentService.RemoveStudentAttachmentByIdAsync(someStudentId, someAttachmentId); // then await Assert.ThrowsAsync <StudentAttachmentDependencyException>(() => removeStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentAttachmentException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentAttachmentByIdAsync(someStudentId, someAttachmentId), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteStudentAttachmentAsync(It.IsAny <StudentAttachment>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnRetrieveWhenSqlExceptionOccursAndLogItAsync() { // given Guid randomAttachmentId = Guid.NewGuid(); Guid inputAttachmentId = randomAttachmentId; Guid randomStudentId = Guid.NewGuid(); Guid inputStudentId = randomStudentId; SqlException sqlException = GetSqlException(); var expectedStudentAttachmentDependencyException = new StudentAttachmentDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectStudentAttachmentByIdAsync(inputStudentId, inputAttachmentId)) .ThrowsAsync(sqlException); // when ValueTask <StudentAttachment> retrieveStudentAttachmentTask = this.studentAttachmentService.RetrieveStudentAttachmentByIdAsync (inputStudentId, inputAttachmentId); // then await Assert.ThrowsAsync <StudentAttachmentDependencyException>(() => retrieveStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs(expectedStudentAttachmentDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentAttachmentByIdAsync(inputStudentId, inputAttachmentId), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }