private void Verify_method_result <T>( Func <BufferedDataReader, T> method, bool async, T expectedResult, params IEnumerable <object[]>[] dataReaderContents) { var reader = Common.Internal.Materialization.MockHelper.CreateDbDataReader(dataReaderContents); var bufferedReader = new BufferedDataReader(reader); if (async) { #if !NET40 bufferedReader.InitializeAsync("2008", FakeSqlProviderServices.Instance, CancellationToken.None).Wait(); Assert.True(bufferedReader.ReadAsync().Result); #endif } else { bufferedReader.Initialize("2008", FakeSqlProviderServices.Instance); Assert.True(bufferedReader.Read()); } Assert.Equal(expectedResult, method(bufferedReader)); }
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); }