public void Metadata_methods_throw_if_reader_is_closed()
        {
            var reader = Common.Internal.Materialization.MockHelper.CreateDbDataReader(new[] { new[] { new object() } });

            var bufferedDataReader = new BufferedDataReader(reader);

            bufferedDataReader.Initialize("2008", FakeSqlProviderServices.Instance);

            bufferedDataReader.Close();
            Assert.Equal(
                Strings.ADP_ClosedDataReaderError,
                Assert.Throws <InvalidOperationException>(() => bufferedDataReader.FieldCount).Message);
            Assert.Equal(
                Strings.ADP_ClosedDataReaderError,
                Assert.Throws <InvalidOperationException>(() => bufferedDataReader.GetOrdinal("columnName")).Message);
            Assert.Equal(
                Strings.ADP_ClosedDataReaderError,
                Assert.Throws <InvalidOperationException>(() => bufferedDataReader.GetDataTypeName(0)).Message);
            Assert.Equal(
                Strings.ADP_ClosedDataReaderError,
                Assert.Throws <InvalidOperationException>(() => bufferedDataReader.GetFieldType(0)).Message);
            Assert.Equal(
                Strings.ADP_ClosedDataReaderError,
                Assert.Throws <InvalidOperationException>(() => bufferedDataReader.GetName(0)).Message);
        }
        private void Metadata_methods_return_expected_results(bool async)
        {
            var reader     = Common.Internal.Materialization.MockHelper.CreateDbDataReader(new[] { new[] { new object() } });
            var readerMock = Mock.Get(reader);

            readerMock.Setup(m => m.RecordsAffected).Returns(2);
            readerMock.Setup(m => m.GetOrdinal(It.IsAny <string>())).Returns(3);
            readerMock.Setup(m => m.GetDataTypeName(It.IsAny <int>())).Returns("dataTypeName");
            readerMock.Setup(m => m.GetFieldType(It.IsAny <int>())).Returns(typeof(DBNull));
            readerMock.Setup(m => m.GetName(It.IsAny <int>())).Returns("columnName");

            var bufferedDataReader = new BufferedDataReader(reader);

            if (async)
            {
#if !NET40
                bufferedDataReader.InitializeAsync("2008", FakeSqlProviderServices.Instance, CancellationToken.None).Wait();
#endif
            }
            else
            {
                bufferedDataReader.Initialize("2008", FakeSqlProviderServices.Instance);
            }

            Assert.Equal(1, bufferedDataReader.FieldCount);
            Assert.Equal(0, bufferedDataReader.GetOrdinal("columnName"));
            Assert.Equal("dataTypeName", bufferedDataReader.GetDataTypeName(0));
            Assert.Equal(typeof(DBNull), bufferedDataReader.GetFieldType(0));
            Assert.Equal("columnName", bufferedDataReader.GetName(0));
            Assert.Throws <NotSupportedException>(() => bufferedDataReader.Depth);
            Assert.Throws <NotSupportedException>(() => bufferedDataReader.GetSchemaTable());

            bufferedDataReader.Close();
            Assert.Equal(2, bufferedDataReader.RecordsAffected);
        }