Example #1
0
        public void GetValuesTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
            {
                object[] objValues = new object[CsvReaderSampleData.SampleData1RecordCount];
                string[] values    = new string[CsvReaderSampleData.SampleData1RecordCount];

                foreach (IDataRecord reader in csv)
                {
                    Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, reader.GetValues(objValues));

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        var csvRecord = (CsvRecord)reader;
                        if (string.IsNullOrEmpty(csvRecord[i]))
                        {
                            Assert.AreEqual(DBNull.Value, objValues[i]);
                        }

                        values[i] = objValues[i].ToString();
                    }

                    CsvReaderSampleData.CheckSampleData1(csv.HasHeaders, csv.CurrentRecordIndex, values);
                }
            }
        }
Example #2
0
 public void FieldCountTest1()
 {
     using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
     {
         CsvReaderSampleData.CheckSampleData1(csv);
     }
 }
Example #3
0
 public void ParsingTest37()
 {
     using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), false))
     {
         csv.SupportsMultiline = false;
         CsvReaderSampleData.CheckSampleData1(csv);
     }
 }
Example #4
0
        public void IterationTest1()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
            {
                int index = 0;

                foreach (CsvRecord record in csv)
                {
                    CsvReaderSampleData.CheckSampleData1(csv.HasHeaders, index, record.ToArray());
                    index++;
                }
            }
        }
Example #5
0
        public void Checkdata5(int bufferSize)
        {
            const string data = CsvReaderSampleData.SampleData1;

            try
            {
                using (CsvRecordReader csv = new CsvRecordReader(new StringReader(data), true, bufferSize))
                {
                    CsvReaderSampleData.CheckSampleData1(csv);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("BufferSize={0}", bufferSize), ex);
            }
        }
Example #6
0
        public void IndexerByFieldIndexTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
            {
                string[] values = new string[CsvReaderSampleData.SampleData1RecordCount];

                foreach (IDataRecord reader in csv)
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        values[i] = (string)reader[i];
                    }

                    CsvReaderSampleData.CheckSampleData1(csv.HasHeaders, csv.CurrentRecordIndex, values);
                }
            }
        }
Example #7
0
        public void IndexerByFieldNameTest()
        {
            using (CsvRecordReader csv = new CsvRecordReader(new StringReader(CsvReaderSampleData.SampleData1), true))
            {
                string[] values = new string[CsvReaderSampleData.SampleData1RecordCount];

                foreach (IDataRecord reader in csv)
                {
                    values[0] = (string)reader[CsvReaderSampleData.SampleData1Header0];
                    values[1] = (string)reader[CsvReaderSampleData.SampleData1Header1];
                    values[2] = (string)reader[CsvReaderSampleData.SampleData1Header2];
                    values[3] = (string)reader[CsvReaderSampleData.SampleData1Header3];
                    values[4] = (string)reader[CsvReaderSampleData.SampleData1Header4];
                    values[5] = (string)reader[CsvReaderSampleData.SampleData1Header5];

                    CsvReaderSampleData.CheckSampleData1(csv.HasHeaders, csv.CurrentRecordIndex, values);
                }
            }
        }