public void GetEnumerator_returns_rows_from_the_current_result_set() { var reader = Common.Internal.Materialization.MockHelper.CreateDbDataReader( new[] { new object[] { 1, "a" }, new object[] { 2, "b" } }, new[] { new object[] { 3, "c" } }); var bufferedReader = new BufferedDataReader(reader); bufferedReader.Initialize("2008", FakeSqlProviderServices.Instance); var enumerator = bufferedReader.GetEnumerator(); var list = new List <object>(); do { while (enumerator.MoveNext()) { var dataRecord = (DbDataRecord)enumerator.Current; for (var i = 0; i < dataRecord.FieldCount; i++) { list.Add(dataRecord.GetValue(i)); } } }while (bufferedReader.NextResult()); Assert.Equal(new object[] { 1, "a", 2, "b", 3, "c" }, list); }
private void Manipulation_methods_perform_expected_actions(bool spatial, bool async) { var reader = Common.Internal.Materialization.MockHelper.CreateDbDataReader( new[] { new object[] { 1, "a" } }, new object[0][]); var bufferedDataReader = new BufferedDataReader(reader); var spatialDataReaderMock = new Mock <DbSpatialDataReader>(); var providerServicesMock = new Mock <DbProviderServices>(); if (spatial) { spatialDataReaderMock.Setup(m => m.IsGeographyColumn(0)).Returns(true); spatialDataReaderMock.Setup(m => m.IsGeometryColumn(1)).Returns(true); #if !NET40 if (async) { spatialDataReaderMock.Setup(m => m.GetGeographyAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult((DbGeography)null)); spatialDataReaderMock.Setup(m => m.GetGeometryAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult((DbGeometry)null)); } #endif providerServicesMock.Protected() .Setup <DbSpatialDataReader>("GetDbSpatialDataReader", reader, "2008") .Returns(spatialDataReaderMock.Object); } try { Assert.False(bufferedDataReader.IsClosed); if (async) { #if !NET40 bufferedDataReader.InitializeAsync("2008", providerServicesMock.Object, CancellationToken.None).Wait(); #endif } else { bufferedDataReader.Initialize("2008", providerServicesMock.Object); } Assert.False(bufferedDataReader.IsClosed); } finally { MutableResolver.ClearResolvers(); } if (spatial) { if (async) { #if !NET40 spatialDataReaderMock.Verify(m => m.GetGeographyAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once()); spatialDataReaderMock.Verify(m => m.GetGeometryAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once()); #endif } else { spatialDataReaderMock.Verify(m => m.GetGeography(It.IsAny <int>()), Times.Once()); spatialDataReaderMock.Verify(m => m.GetGeometry(It.IsAny <int>()), Times.Once()); } } Assert.True(bufferedDataReader.HasRows); if (async) { #if !NET40 Assert.True(bufferedDataReader.ReadAsync().Result); Assert.False(bufferedDataReader.ReadAsync().Result); #endif } else { Assert.True(bufferedDataReader.Read()); Assert.False(bufferedDataReader.Read()); } Assert.True(bufferedDataReader.HasRows); if (async) { #if !NET40 Assert.True(bufferedDataReader.NextResultAsync().Result); #endif } else { Assert.True(bufferedDataReader.NextResult()); } Assert.False(bufferedDataReader.HasRows); if (async) { #if !NET40 Assert.False(bufferedDataReader.ReadAsync().Result); Assert.False(bufferedDataReader.NextResultAsync().Result); #endif } else { Assert.False(bufferedDataReader.Read()); Assert.False(bufferedDataReader.NextResult()); } Assert.False(bufferedDataReader.IsClosed); bufferedDataReader.Close(); Assert.True(bufferedDataReader.IsClosed); }