public void TestReaderRead()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Write(dataLine1.Replace("Son of a beach!", "Son of a gun!"));
                            writer.Write(dataLine1.Replace("Son of a beach!", "Monkey's Uncle!"));
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                Assert.NotNull(dataReader);
                                Assert.False(dataReader.IsClosed);
                                Assert.True(dataReader.Read(), "1st read failed");
                                Assert.Equal("Son of a beach!", dataReader["StringField"]);
                                Assert.True(dataReader.Read(), "2nd read failed");
                                Assert.Equal("Son of a gun!", dataReader["StringField"]);
                                Assert.True(dataReader.Read(), "3rd read failed");
                                Assert.Equal("Monkey's Uncle!", dataReader["StringField"]);
                                Assert.False(dataReader.Read(), "last read failed");
                            }
                        }
        }
        public void TestIsClosed()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.False(dataReader.IsClosed, "data reader should not be closed yet.");
                                dataReader.Read();
                                Assert.True(dataReader.IsClosed, "data reader should be closed but is not.");
                            }
                        }
        }
        public void TestGetString()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal("Son of a beach!", dataReader.GetString(11));
                            }
                        }
        }
        public void TestGetBoolean()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.True(dataReader.GetBoolean(0), "Boolean value should be true.");
                            }
                        }
        }
        public void TestFieldCount()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(15, dataReader.FieldCount);
                            }
                        }
        }
        public void TestIsDbNull()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.True(dataReader.IsDBNull(12));
                                Assert.True(dataReader.IsDBNull(13));
                            }
                        }
        }
        public void TestGetInt64()
        {
            Int64 integer64 = Int64.MaxValue;

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(integer64, dataReader.GetInt64(10));
                            }
                        }
        }
        public void TestGetGuid()
        {
            Guid guid = Guid.Parse("3E11803C-AB25-454C-953E-D940E4FCF655");

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(guid, dataReader.GetGuid(7));
                            }
                        }
        }
        public void TestGetFloat()
        {
            float flt = 34.56F;

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(flt, dataReader.GetFloat(6));
                            }
                        }
        }
        public void TestGetDouble()
        {
            double dbl = 890.12D;

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(dbl, dataReader.GetDouble(5));
                            }
                        }
        }
        public void TestGetDecimal()
        {
            decimal dec = 123.4567M;

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(dec, dataReader.GetDecimal(4));
                            }
                        }
        }
        public void TestGetDateTime()
        {
            var datetime = DateTime.Parse("01/01/2016");

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(datetime, dataReader.GetDateTime(3));
                            }
                        }
        }
        public void TestGetByte()
        {
            byte b = Byte.Parse("255");

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                Assert.Equal(b, dataReader.GetByte(1));
                            }
                        }
        }
        public void TestGetSchemaTable()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                        using (var dtReader = new DelimitedTextReader(reader))
                        {
                            writer.Write(headerLine);
                            writer.Write(dataLine1);
                            writer.Flush();
                            stream.Position = 0;

                            using (var dataReader = new DelimitedTextDataReader(dtReader))
                            {
                                dataReader.Read();
                                DataTable dt = dataReader.GetSchemaTable();
                                Assert.NotNull(dt);
                                Assert.Equal(15, dt.Rows.Count);
                                Assert.Equal("StringField", dt.Rows[11][0].ToString());
                            }
                        }
        }
        public void TestReaderDispose()
        {
            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var reader = new StreamReader(stream))
                    {
                        var dtReader = new DelimitedTextReader(reader);
                        writer.Write(headerLine);
                        writer.Write(dataLine1);
                        writer.Flush();
                        stream.Position = 0;

                        using (var dataReader = new DelimitedTextDataReader(dtReader))
                        {
                            dataReader.Read();
                            Assert.Equal("Son of a beach!", dataReader["StringField"]);
                        }

                        dtReader.Dispose();
                        Assert.Null(dtReader.Parser);
                    }
        }