public void Enumerator_ReadInputStreamToDataRowsPerPartes_WithSmallBuffer_CheckReadedAllRows_StreamAndItsConnectIsClosedAfterForeach()
        {
            var cmd = new SqlCommand("SELECT * FROM TestTable", ConnectHelper.CreateConnection());
            ISqlValueSerializer serializer = new SqlValueSerializerCsvSimple();
            var bufferSize = 10;

            //ACT with ASSERT
            using (var sqlDataReaderStream = new SqlStream(cmd, serializer))
            {
                var table = sqlDataReaderStream.DataTableWithoutData;
                Assert.AreEqual(0, table.Rows.Count);
                List <DataRow> rows        = new List <DataRow>();
                var            oldPosition = sqlDataReaderStream.Position;
                foreach (var row in new StreamToEnumerableDataRows(sqlDataReaderStream, table, serializer, bufferSize))
                {
                    Assert.Greater(sqlDataReaderStream.Position, oldPosition);
                    oldPosition = sqlDataReaderStream.Position;
                    rows.Add(row);
                    Assert.AreEqual(ConnectionState.Open, cmd.Connection.State);
                }
                //after dispose foreach is disposed readed stream too and it close connection
                Assert.AreEqual(ConnectionState.Closed, cmd.Connection.State);
                Assert.AreEqual(3, rows.Count);
            }
        }
Esempio n. 2
0
        private void TestSqlValueSerializerForReadingAndWriting(ISqlValueSerializer p_SqlValueSerializer, int p_BufferSize = 8192)
        {
            var cmd = new SqlCommand("SELECT * FROM TestTable", ConnectHelper.CreateConnection());

            //ACT with ASSERT
            using (var sqlDataReaderStream = new SqlStream(cmd, p_SqlValueSerializer))
            {
                var table = sqlDataReaderStream.DataTableWithoutData;
                Assert.AreEqual(0, table.Rows.Count);
                new StreamToDataTableRows().ReadStreamToDataTable(sqlDataReaderStream, table, p_SqlValueSerializer, p_BufferSize);
                Assert.AreEqual(3, table.Rows.Count);
                Assert.AreEqual(@"Test Tab	and NewLine
is ok", table.Rows[2]["TestString"], "Failed test string with special chars (same as RowSplitter and ColumnSplitter in Csv format)");
            }
        }