Пример #1
0
        public void MoveToTest_SeekableStream(bool withCaching)
        {
            using (var ms = new MemoryStream())
            {
                var writer = new StreamWriter(ms, Encoding.Unicode);
                writer.Write(DelimitedRecordReaderTestData.SampleData1);
                writer.Flush();

                ms.Position = 0;

                using (var csv = new DelimitedRecordReader(new StreamReader(ms, Encoding.Unicode)))
                {
                    if (withCaching)
                    {
                        csv.StartCachingRecordPositions();
                    }

                    while (csv.Read() == ReadResult.Success)
                    {
                    }

                    for (int i = DelimitedRecordReaderTestData.SampleData1RecordCount - 1; i >= 0; i--)
                    {
                        Assert.AreEqual(ReadResult.Success, csv.MoveTo(i));
                        DelimitedRecordReaderTestData.CheckSampleData1(csv, false, i);
                    }
                }
            }
        }
Пример #2
0
        public void ReadColumnHeadersTest_Called([Values(false, true)] bool useDynamicColumnCount)
        {
            using (var csv = new DelimitedRecordReader(new StringReader(DelimitedRecordReaderTestData.SampleData1)))
            {
                csv.DynamicColumnCount = useDynamicColumnCount;

                Assert.AreEqual(ReadResult.Success, csv.ReadColumnHeaders());

                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1RecordCount, csv.Columns.Count);

                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1Header0, csv.Columns[0].Name);
                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1Header1, csv.Columns[1].Name);
                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1Header2, csv.Columns[2].Name);
                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1Header3, csv.Columns[3].Name);
                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1Header4, csv.Columns[4].Name);
                Assert.AreEqual(DelimitedRecordReaderTestData.SampleData1Header5, csv.Columns[5].Name);

                Assert.AreEqual(0, csv.Columns.IndexOf(DelimitedRecordReaderTestData.SampleData1Header0));
                Assert.AreEqual(1, csv.Columns.IndexOf(DelimitedRecordReaderTestData.SampleData1Header1));
                Assert.AreEqual(2, csv.Columns.IndexOf(DelimitedRecordReaderTestData.SampleData1Header2));
                Assert.AreEqual(3, csv.Columns.IndexOf(DelimitedRecordReaderTestData.SampleData1Header3));
                Assert.AreEqual(4, csv.Columns.IndexOf(DelimitedRecordReaderTestData.SampleData1Header4));
                Assert.AreEqual(5, csv.Columns.IndexOf(DelimitedRecordReaderTestData.SampleData1Header5));

                DelimitedRecordReaderTestData.CheckSampleData1(csv, true, true);
            }
        }
Пример #3
0
 public void ReadColumnHeadersTest_NotCalledWithDynamicColumns()
 {
     using (var csv = new DelimitedRecordReader(new StringReader(DelimitedRecordReaderTestData.SampleData1)))
     {
         csv.DynamicColumnCount = true;
         DelimitedRecordReaderTestData.CheckSampleData1(csv, false, true);
     }
 }
Пример #4
0
 public void FieldCountTest1()
 {
     using (var csv = new DelimitedRecordReader(new StringReader(DelimitedRecordReaderTestData.SampleData1)))
     {
         Assert.AreEqual(ReadResult.Success, csv.ReadColumnHeaders());
         DelimitedRecordReaderTestData.CheckSampleData1(csv, true, true);
     }
 }
Пример #5
0
 public void ParsingTest_SpecificBufferSize([Random(1, 1024, 1000)] int bufferSize)
 {
     using (DelimitedRecordReader reader = new DelimitedRecordReader(new StringReader(DelimitedRecordReaderTestData.SampleData1), bufferSize))
     {
         Assert.AreEqual(ReadResult.Success, reader.ReadColumnHeaders());
         DelimitedRecordReaderTestData.CheckSampleData1(reader, true, true);
     }
 }
Пример #6
0
        public void CopyCurrentRecordToTest([Range(0, 5)] int startIndex)
        {
            using (var csv = new DelimitedRecordReader(new StringReader(DelimitedRecordReaderTestData.SampleData1)))
            {
                var record = new string[DelimitedRecordReaderTestData.SampleData1ColumnCount + startIndex];

                while (csv.Read() == ReadResult.Success)
                {
                    csv.CopyCurrentRecordTo(record, startIndex);
                    DelimitedRecordReaderTestData.CheckSampleData1(record, false, csv.CurrentRecordIndex, startIndex);
                }
            }
        }
Пример #7
0
        public void MoveToTest_Forward(
            [Values(false, true)] bool readHeaders,
            [Range(0, DelimitedRecordReaderTestData.SampleData1RecordCount - 1)] int toRecordIndex)
        {
            using (var csv = new DelimitedRecordReader(new StringReader(DelimitedRecordReaderTestData.SampleData1)))
            {
                if (readHeaders)
                {
                    Assert.AreEqual(ReadResult.Success, csv.ReadColumnHeaders());
                }

                csv.MoveTo(toRecordIndex);
                DelimitedRecordReaderTestData.CheckSampleData1(csv, readHeaders, toRecordIndex);
            }
        }