示例#1
0
        public void TestCsvRecordReaderRead()
        {
            string filename = ".unittestscsvrecorreader" + nameof(TestCsvRecordReaderRead);

            CreateCsvTempFile(filename);

            FileSource source = new FileSource(filename, Path.GetTempPath());

            CsvRecordReader reader = new CsvRecordReader(source);

            Assert.Throws <InvalidOperationException>(() => reader.Read(3));

            reader.Prepare();

            string[][] lineparts = (string[][])reader.Read(2);

            Assert.AreEqual(2, lineparts.Length);
            Assert.AreEqual(5, lineparts[0].Length);
            Assert.AreEqual(new[] { "5.1", "3.5", "1.4", "0.2", "Iris-setosa" }, lineparts[0]);

            lineparts = (string[][])reader.Read(3);

            Assert.AreEqual(1, lineparts.Length);
            Assert.AreEqual(5, lineparts[0].Length);

            reader.Dispose();

            DeleteTempFile(filename);
        }