コード例 #1
0
 public void FieldCountTest1()
 {
     using var csv = ReadCsv.FromString(CsvReaderSampleData.SampleData1,
                                        trimmingOptions: ValueTrimmingOptions.UnquotedOnly
                                        );
     CsvReaderSampleData.CheckSampleData1(csv, false, true);
 }
コード例 #2
0
 public void ParsingTest37()
 {
     using var csv = ReadCsv.FromString(CsvReaderSampleData.SampleData1,
                                        hasHeaders: true,
                                        trimmingOptions: ValueTrimmingOptions.UnquotedOnly,
                                        schema: CsvReaderSampleData.SampleData1Schema);
     CsvReaderSampleData.CheckSampleData1(csv, true, false);
 }
コード例 #3
0
        public void SampleDataSplitTest()
        {
            var data = CsvReaderSampleData.SampleData1;

            var splitter = new CsvStateMachine(new StringReader(data), new CsvLayout(), new CsvBehaviour());

            var result = splitter.Lines().ToArray();

            CsvReaderSampleData.CheckSampleData1(false, 0, result[0].Fields);
        }
コード例 #4
0
    public void IndexerByFieldIndexTest()
    {
        using var reader = ReadCsv.FromString(
                  CsvReaderSampleData.SampleData1, hasHeaders: true, schema: CsvReaderSampleData.SampleData1Schema, trimmingOptions: ValueTrimmingOptions.UnquotedOnly);
        string[] values             = new string[CsvReaderSampleData.SampleData1RecordCount];
        int      currentRecordIndex = 0;

        while (reader.Read())
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                values[i] = (string)reader[i];
            }

            CsvReaderSampleData.CheckSampleData1(true, currentRecordIndex, values);
            currentRecordIndex++;
        }
    }
コード例 #5
0
    public void IndexerByFieldNameTest()
    {
        using var reader = ReadCsv.FromString(
                  CsvReaderSampleData.SampleData1, hasHeaders: true, trimmingOptions: ValueTrimmingOptions.UnquotedOnly);
        string[] values       = new string[CsvReaderSampleData.SampleData1RecordCount];
        int      currentIndex = 0;

        while (reader.Read())
        {
            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(true, currentIndex, values, true);
            currentIndex++;
        }
    }
コード例 #6
0
    public void GetValueTest()
    {
        using var reader = ReadCsv.FromString(
                  CsvReaderSampleData.SampleData1, hasHeaders: true, schema: CsvReaderSampleData.SampleData1Schema, trimmingOptions: ValueTrimmingOptions.UnquotedOnly);
        string[] values = new string[CsvReaderSampleData.SampleData1RecordCount];

        var currentRecordIndex = 0;

        while (reader.Read())
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                object value = reader.GetValue(i);
                values[i] = value?.ToString();
            }

            CsvReaderSampleData.CheckSampleData1(true, currentRecordIndex, values);
            currentRecordIndex++;
        }
    }
コード例 #7
0
    public void GetValuesTest()
    {
        using var reader = ReadCsv.FromString(
                  CsvReaderSampleData.SampleData1, hasHeaders: true, schema: CsvReaderSampleData.SampleData1Schema, trimmingOptions: ValueTrimmingOptions.UnquotedOnly);

        object[] objValues = new object[CsvReaderSampleData.SampleData1RecordCount];
        string[] values    = new string[CsvReaderSampleData.SampleData1RecordCount];

        int currentRecordIndex = 0;

        while (reader.Read())
        {
            Assert.AreEqual(CsvReaderSampleData.SampleData1RecordCount, reader.GetValues(objValues));

            for (int i = 0; i < reader.FieldCount; i++)
            {
                values[i] = objValues[i]?.ToString();
            }

            CsvReaderSampleData.CheckSampleData1(true, currentRecordIndex, values);
            currentRecordIndex++;
        }
    }