Пример #1
0
        public void TestJaggedField()
        {
            using (CsvReader r = new CsvReader(new StringReader(CSV_DOC1)))
            {
                Assert.AreEqual(0, r.Depth);
                Assert.IsFalse(r.IsClosed);
                Assert.AreEqual(3, r.FieldCount);
                Assert.IsTrue(r.Read());
                Assert.AreEqual(3, r.FieldCount);
                Assert.IsTrue(r.Read());
                
                //second row has an extra field
                Assert.AreEqual(4, r.FieldCount);
                Assert.AreEqual("3", r.GetName(3));
                Assert.AreEqual(3, r.GetOrdinal("3"));
                Assert.AreEqual("extra", r.GetValue(3));

                Assert.IsTrue(r.Read());
                Assert.IsFalse(r.IsDBNull(0));
                Assert.AreEqual("3a", r.GetString("f1"));
                Assert.IsTrue(r.IsDBNull(1));
                Assert.IsTrue(r.IsDBNull(2));

                Assert.IsTrue(r.Read());
                Assert.IsTrue(r.Read());
                Assert.IsFalse(r.Read());
            }
        }
Пример #2
0
        public void TestIndexValue()
        {
            using (CsvReader r = new CsvReader(new StringReader(CSV_DOC1)))
            {
                r.Read();
                Assert.AreEqual("1a", r["f1"]);
                Assert.AreEqual("1b", r[1]);
                Assert.AreEqual("1c", r.GetString(2));
                Assert.AreEqual("1c", r.GetValues()[2]);
            }

        }
Пример #3
0
 public void TestBadFieldName()
 {
     using (CsvReader r = new CsvReader(new StringReader(CSV_DOC1)))
     {
         r.Read();
         r.GetString("this does not exist");
     }
 }
Пример #4
0
        public void TestFieldValues()
        {
            using (TempFile temp = new TempFile())
            {
                File.WriteAllText(temp.TempPath, CSV_DOC1);
                using (CsvReader r = new CsvReader(temp.TempPath))
                {
                    Assert.AreEqual(3, r.FieldCount);
                    int row = 0;
                    while (r.Read())
                    {
                        for (int col = 0; col < 3; col++)
                        {
                            Assert.AreEqual(CSV_DOC1_VAL[row, col], r.GetString(col));
                        }

                        row++;
                    }

                    Assert.AreEqual(5, row);
                    Assert.AreEqual(5, r.RecordsAffected);
                }
            }
        }