internal virtual IDbEnumerator <T> GetDbEnumerator() { this.EnsureCanEnumerateResults(); Shaper <T> shaper = this._shaper; this._shaper = (Shaper <T>)null; return(shaper.GetEnumerator()); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> public IEnumerator <T> GetEnumerator() { EnsureCanEnumerateResults(); Shaper <T> shaper = _shaper; _shaper = null; IEnumerator <T> result = shaper.GetEnumerator(); return(result); }
private void Returns_SimpleEnumerator_for_simple_CoordinatorFactory( Func<IDbEnumerator<object>, List<object>> toList) { var sourceEnumerable = new[] { new object[] { 1 }, new object[] { 2 } }; var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0)); var shaper = new Shaper<object>( MockHelper.CreateDbDataReader(sourceEnumerable), /*context*/ null, /*workspace*/ null, MergeOption.AppendOnly, /*stateCount*/ 1, coordinatorFactory, /*readerOwned*/ false, /*useSpatialReader*/ false); var actualEnumerator = shaper.GetEnumerator(); Assert.Equal(sourceEnumerable.SelectMany(e => e).ToList(), toList(actualEnumerator)); }
private void Returns_ObjectQueryNestedEnumerator_for_nested_coordinatorFactories( Func<IDbEnumerator<object>, List<object>> toList) { var sourceEnumerable = new[] { new object[] { 1, "A", null }, new object[] { 2, null, "X" }, new object[] { 3, "B", "Z" }, // Should stop reading at "B", since the coordinators are at the same depth new object[] { 4, "C", null }, new object[] { 4, "D", null } // 4 shouldn't be added as it's repeated }; var actualValuesFromNestedCoordinatorOne = new List<string>(); var nestedCoordinatorFactoryOne = Objects.MockHelper.CreateCoordinatorFactory<string, string>( depth: 1, stateSlot: 1, ordinal: 1, nestedCoordinators: new CoordinatorFactory[0], producedValues: actualValuesFromNestedCoordinatorOne); var actualValuesFromNestedCoordinatorTwo = new List<string>(); var nestedCoordinatorFactoryTwo = Objects.MockHelper.CreateCoordinatorFactory<string, string>( depth: 1, stateSlot: 2, ordinal: 2, nestedCoordinators: new CoordinatorFactory[0], producedValues: actualValuesFromNestedCoordinatorTwo); var actualValuesFromRootCoordinator = new List<object>(); var rootCoordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory<int, object>( depth: 0, stateSlot: 0, ordinal: 0, nestedCoordinators: new[] { nestedCoordinatorFactoryOne, nestedCoordinatorFactoryTwo }, producedValues: actualValuesFromRootCoordinator); var shaper = new Shaper<object>( MockHelper.CreateDbDataReader(sourceEnumerable), /*context*/ null, /*workspace*/ null, MergeOption.AppendOnly, /*stateCount*/ 3, rootCoordinatorFactory, /*readerOwned*/ false, /*useSpatialReader*/ false, shouldReleaseConnection: true); var actualEnumerator = shaper.GetEnumerator(); Assert.Equal(new object[] { 1, 2, 3, 4 }.ToList(), toList(actualEnumerator)); Assert.Equal(new object[] { 1, 2, 3, 4 }.ToList(), actualValuesFromRootCoordinator); Assert.Equal(new[] { "A", "B", "C", "D" }.ToList(), actualValuesFromNestedCoordinatorOne); Assert.Equal(new[] { "X" }.ToList(), actualValuesFromNestedCoordinatorTwo); }
public void RecordStateEnumerator_MoveNextAsync_returns_reader_consumed_even_if_task_is_being_cancelled() { var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => (RecordState)null, s => true); var shaper = new Shaper<RecordState>( new Mock<DbDataReader>().Object, /*context*/ null, /*workspace*/ null, MergeOption.AppendOnly, /*stateCount*/ 1, coordinatorFactory, /*readerOwned*/ false, /*streaming*/ false); using (var enumerator = shaper.GetEnumerator()) { Assert.Contains("RecordStateEnumerator", enumerator.GetType().FullName); enumerator.MoveNext(); Assert.False(enumerator.MoveNextAsync(new CancellationToken(canceled: true)).GetAwaiter().GetResult()); } }
public void ObjectQueryNestedEnumerator_MoveNextAsync_throws_OperationCanceledException_if_task_is_cancelled() { var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0), s => true); var shaper = new Shaper<object>( new Mock<DbDataReader>().Object, /*context*/ null, /*workspace*/ null, MergeOption.AppendOnly, /*stateCount*/ 1, coordinatorFactory, /*readerOwned*/ false, /*streaming*/ false); using (var enumerator = shaper.GetEnumerator()) { Assert.Contains("ObjectQueryNestedEnumerator", enumerator.GetType().FullName); Assert.Throws<OperationCanceledException>( () => enumerator.MoveNextAsync(new CancellationToken(canceled: true)) .GetAwaiter().GetResult()); } }
public void SimpleEnumerator_MoveNextAsync_does_not_throw_if_shaper_is_not_active_even_if_task_is_being_cancelled() { var coordinatorFactory = Objects.MockHelper.CreateCoordinatorFactory(s => s.Reader.GetValue(0)); var shaper = new Shaper<object>( new Mock<DbDataReader>().Object, /*context*/ null, /*workspace*/ null, MergeOption.AppendOnly, /*stateCount*/ 1, coordinatorFactory, /*readerOwned*/ false, /*streaming*/ false); using (var enumerator = shaper.GetEnumerator()) { Assert.Contains("SimpleEnumerator", enumerator.GetType().FullName); enumerator.MoveNext(); Assert.False(enumerator.MoveNextAsync(new CancellationToken(canceled: true)) .GetAwaiter().GetResult()); } }