public void ShouldThrowDependencyExceptionOnRetrieveAllWhenDbExceptionOccursAndLogIt() { // given var databaseUpdateException = new DbUpdateException(); var expectedStudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.SelectAllStudentSemesterCourses()) .Throws(databaseUpdateException); // when . then Assert.Throws <StudentSemesterCourseDependencyException>(() => this.studentSemesterCourseService.RetrieveAllStudentSemesterCourses()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentSemesterCourseDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectAllStudentSemesterCourses(), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnDeleteWhenDbExceptionOccursAndLogItAsync() { // given Guid someSemesterCourseId = Guid.NewGuid(); Guid someStudentId = Guid.NewGuid(); var databaseUpdateException = new DbUpdateException(); var expectedStudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(databaseUpdateException); this.storageBrokerMock.Setup(broker => broker.SelectStudentSemesterCourseByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>())) .ThrowsAsync(databaseUpdateException); // when ValueTask <StudentSemesterCourse> deleteSemesterCourseTask = this.studentSemesterCourseService.RemoveStudentSemesterCourseByIdsAsync(someSemesterCourseId, someStudentId); // then await Assert.ThrowsAsync <StudentSemesterCourseDependencyException>(() => deleteSemesterCourseTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentSemesterCourseDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentSemesterCourseByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public void ShouldThrowDependencyExceptionOnRetrieveAllWhenSqlExceptionOccursAndLogIt() { // given SqlException sqlException = GetSqlException(); var expectedStudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectAllStudentSemesterCourses()) .Throws(sqlException); // when Action retrieveAllStudentSemesterCourseAction = () => this.studentSemesterCourseService.RetrieveAllStudentSemesterCourses(); // then Assert.Throws <StudentSemesterCourseDependencyException>( retrieveAllStudentSemesterCourseAction); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( expectedStudentSemesterCourseDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectAllStudentSemesterCourses(), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
private StudentSemesterCourseDependencyException CreateAndLogDependencyException(Exception exception) { var studentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(exception); this.loggingBroker.LogError(studentSemesterCourseDependencyException); return(studentSemesterCourseDependencyException); }
private StudentSemesterCourseDependencyException CreateAndLogCriticalDependencyException(Exception exception) { var StudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(exception); this.loggingBroker.LogCritical(StudentSemesterCourseDependencyException); return(StudentSemesterCourseDependencyException); }
public async Task ShouldThrowDependencyExceptionOnModifyIfDbUpdateConcurrencyExceptionOccursAndLogItAsync() { // given int randomNegativeNumber = GetNegativeRandomNumber(); DateTimeOffset randomDateTime = GetRandomDateTime(); StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(randomDateTime); StudentSemesterCourse someStudentSemesterCourse = randomStudentSemesterCourse; someStudentSemesterCourse.CreatedDate = randomDateTime.AddMinutes(randomNegativeNumber); var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedStudentSemesterCourseException = new LockedStudentSemesterCourseException(databaseUpdateConcurrencyException); var expectedStudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(lockedStudentSemesterCourseException); this.storageBrokerMock.Setup(broker => broker.SelectStudentSemesterCourseByIdAsync (It.IsAny <Guid>(), It.IsAny <Guid>())) .ThrowsAsync(databaseUpdateConcurrencyException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(randomDateTime); // when ValueTask <StudentSemesterCourse> modifyStudentSemesterCourseTask = this.studentSemesterCourseService.ModifyStudentSemesterCourseAsync(someStudentSemesterCourse); // then await Assert.ThrowsAsync <StudentSemesterCourseDependencyException>(() => modifyStudentSemesterCourseTask.AsTask()); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentSemesterCourseByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentSemesterCourseDependencyException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnCreateWhenDbExceptionOccursAndLogItAsync() { // given DateTimeOffset dateTime = GetRandomDateTime(); StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(dateTime); StudentSemesterCourse inputStudentSemesterCourse = randomStudentSemesterCourse; inputStudentSemesterCourse.UpdatedBy = inputStudentSemesterCourse.CreatedBy; inputStudentSemesterCourse.UpdatedDate = inputStudentSemesterCourse.CreatedDate; var databaseUpdateException = new DbUpdateException(); var expectedStudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(databaseUpdateException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(dateTime); this.storageBrokerMock.Setup(broker => broker.InsertStudentSemesterCourseAsync(It.IsAny <StudentSemesterCourse>())) .ThrowsAsync(databaseUpdateException); // when ValueTask <StudentSemesterCourse> createStudentSemesterCourseTask = this.studentSemesterCourseService.CreateStudentSemesterCourseAsync(inputStudentSemesterCourse); // then await Assert.ThrowsAsync <StudentSemesterCourseDependencyException>(() => createStudentSemesterCourseTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentSemesterCourseDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentSemesterCourseAsync(It.IsAny <StudentSemesterCourse>()), Times.Once); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowDependencyExceptionOnRetrieveWhenSqlExceptionOccursAndLogItAsync() { // given Guid randomSemesterCourseId = Guid.NewGuid(); Guid inputSemesterCourseId = randomSemesterCourseId; Guid randomStudentId = Guid.NewGuid(); Guid inputStudentId = randomStudentId; SqlException sqlException = GetSqlException(); var expectedStudentSemesterCourseDependencyException = new StudentSemesterCourseDependencyException(sqlException); this.storageBrokerMock.Setup(broker => broker.SelectStudentSemesterCourseByIdAsync(inputStudentId, inputSemesterCourseId)) .ThrowsAsync(sqlException); // when ValueTask <StudentSemesterCourse> deleteStudentSemesterCourseTask = this.studentSemesterCourseService.RetrieveStudentSemesterCourseByIdAsync (inputStudentId, inputSemesterCourseId); // then await Assert.ThrowsAsync <StudentSemesterCourseDependencyException>(() => deleteStudentSemesterCourseTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs(expectedStudentSemesterCourseDependencyException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentSemesterCourseByIdAsync(inputStudentId, inputSemesterCourseId), Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }