private static void ReadAndVerify(string inputFileName, CsvReaderConfiguration configuration, object[][] expectedRows) { using (var csvReader = new CsvReader(new StreamReader(inputFileName), configuration)) { IReadOnlyList <object> row; while ((row = csvReader.Read()) != null) { Assert.IsTrue(csvReader.Row <= expectedRows.Length, TestResources.ExtraRowRead); CollectionAssert.AreEqual(expectedRows[csvReader.Row - 1], row.ToArray(), TestResources.InvalidRowRead); } } }
public void Test() { var fileReaderConfig = new SinglefileLoaderStepConfig { FileName = "TestCsv.csv" }; var csvConfig = new CsvReaderConfiguration { SkipHeader = true, CsvRecords = { new CsvRecord { Name = "Test", TableName = "Data", Fields = { new CsvField { Name = "Field1", Position = 1, DefaultValue = "", Type = typeof(string) }, new CsvField { Name = "Field2", Position = 2, DefaultValue = null, Type = typeof(DateTime) }, new CsvField { Name = "Field3", Position = 3, DefaultValue = 1, Type = typeof(int) }, } } } }; var etlPipelineConfiguration = new List <ConfiguredEtlStep> { new ConfiguredEtlStep { StepType = typeof(SingleFileLoaderStep), Config = fileReaderConfig }, new ConfiguredEtlStep { StepType = typeof(CsvReaderEtlStep), Config = csvConfig } }; var container = new Container(); container.Register <CsvReaderEtlStep>(); container.Register <SingleFileLoaderStep>(); container.Register <ICsvRecordSelector, SingleRecordCsvRecordReaderSelector>(); var pipeline = EtlProcessFactory.CreateEtlPipeline(container, etlPipelineConfiguration); PipelineExecutor.RunPipeline(pipeline, context => { }, context => { }); }
public ParseCsv(CsvReaderConfiguration config) { _configuration = config; }