public IEnumerable <T> ReadFieldData <T>(RowReader <T> reader, string fileName) where T : class, new() { var fm = new FieldMapperReading <T>(FileDescription, fileName, false); var charLengths = fm.GetCharLengths(); return(ReadFieldDataRows(reader, fileName, fm, charLengths)); }
public void TestLogRecord_FullFields_2() { FieldMapperReading <LogRecord> fm = new FieldMapperReading <LogRecord>(_fileDescriptionNamesUs, null, false); Assert.IsNotNull(fm); Assert.IsNotNull(fm.FieldIndexInfo); Assert.IsNotNull(fm.NameToInfo); Assert.AreEqual(fm.NameToInfo.Count, 27); Assert.IsNotNull(fm.NameToInfo["PCI"]); Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true); List <int> charLengths = fm.GetCharLengths(); Assert.IsNull(charLengths); FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs); Assert.IsNotNull(dataAccess); RowReader <LogRecord> reader = dataAccess.ReadDataPreparation <LogRecord>(null); Assert.IsNotNull(reader); dataAccess.Row = new DataRow(); List <LogRecord> records = dataAccess.ReadFieldDataRows(reader, null, fm, null).ToList(); Assert.IsNotNull(records); Assert.AreEqual(records.Count, 1); Assert.AreEqual(records[0].Id, 0); Assert.AreEqual(records[0].Time.Millisecond, 359); Assert.AreEqual(records[0].Sinr, 10.1); Assert.AreEqual(records[0].UlMcs, 17); Assert.AreEqual(records[0].DlThroughput, 10749096); }
public void FileWithUnknownColumns_ShouldDiscardColumns_BasicParameters2() { FieldMapperReading<Person> fm = new FieldMapperReading<Person>(_description, null, false); List<int> charLengths = fm.GetCharLengths(); Assert.IsNull(charLengths); Assert.IsNotNull(_dataAccess.Row); Assert.AreEqual(_dataAccess.Row.Count, 0); }
public void FileWithUnknownColumns_ShouldDiscardColumns_BasicParameters2() { FieldMapperReading <Person> fm = new FieldMapperReading <Person>(_description, null, false); List <int> charLengths = fm.GetCharLengths(); Assert.IsNull(charLengths); Assert.IsNotNull(_dataAccess.Row); Assert.AreEqual(_dataAccess.Row.Count, 0); }
public void GoodFileNoSeparatorCharUSEnglish() { // Arrange CsvFileDescription fileDescription_namesUs = new CsvFileDescription { NoSeparatorChar = true, UseOutputFormatForParsingCsvValue = false, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; const string testInput = @"AAAAAAAA34.18405/23/08 BBBBBBBB10.31105/12/12 CCCCCCCC12.00012/23/08"; var expected = new[] { new ProductDataCharLength { Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23), } }; // Act and Assert FileDataAccess dataAccess = new FileDataAccess(testInput.GetStreamReader(), fileDescription_namesUs); RowReader<ProductDataCharLength> reader = dataAccess.ReadDataPreparation<ProductDataCharLength>(null); dataAccess.Row = new DataRow(); FieldMapperReading<ProductDataCharLength> fm = new FieldMapperReading<ProductDataCharLength>( fileDescription_namesUs, null, false); List<int> charLengths = fm.GetCharLengths(); Assert.AreEqual(charLengths.Count, 3); bool firstRow = true; List<ProductDataCharLength> actual=new List<ProductDataCharLength>(); while (dataAccess.Cs.ReadRow(dataAccess.Row, charLengths)) { if ((dataAccess.Row.Count == 1) && ((dataAccess.Row[0].Value == null) || (string.IsNullOrEmpty(dataAccess.Row[0].Value.Trim())))) { continue; } bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, firstRow); if (readingResult) { actual.Add(reader.Obj); } firstRow = false; } AssertCollectionsEqual(actual, expected); }
public void FileWithUnknownColumns_ShouldDiscardColumns_ReadFieldData() { FieldMapperReading<Person> fm = new FieldMapperReading<Person>(_description, null, false); List<int> charLengths = fm.GetCharLengths(); List<Person> actual = _dataAccess.ReadFieldDataRows(_reader, null, fm, charLengths).ToList(); Assert.AreEqual(actual.Count, 2); Assert.AreEqual(actual[0].Age, 15); Assert.AreEqual(actual[1].Name, "Jane"); }
public void FileWithUnknownColumns_ShouldDiscardColumns_ReadFieldData() { FieldMapperReading <Person> fm = new FieldMapperReading <Person>(_description, null, false); List <int> charLengths = fm.GetCharLengths(); List <Person> actual = _dataAccess.ReadFieldDataRows(_reader, null, fm, charLengths).ToList(); Assert.AreEqual(actual.Count, 2); Assert.AreEqual(actual[0].Age, 15); Assert.AreEqual(actual[1].Name, "Jane"); }
public void TestLogRecord_FullFields() { FieldMapperReading <LogRecord> fm = new FieldMapperReading <LogRecord>(_fileDescriptionNamesUs, null, false); Assert.IsNotNull(fm); Assert.IsNotNull(fm.FieldIndexInfo); Assert.IsNotNull(fm.NameToInfo); Assert.AreEqual(fm.NameToInfo.Count, 27); Assert.IsNotNull(fm.NameToInfo["PCI"]); Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true); List <int> charLengths = fm.GetCharLengths(); Assert.IsNull(charLengths); FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs); Assert.IsNotNull(dataAccess); RowReader <LogRecord> reader = dataAccess.ReadDataPreparation <LogRecord>(null); Assert.IsNotNull(reader); Assert.IsNotNull(dataAccess.Cs); dataAccess.Row = new DataRow(); Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row)); bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, true); Assert.IsFalse(readingResult); Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row)); Assert.AreEqual(dataAccess.Row[0].Value, "0"); Assert.AreEqual(dataAccess.Row[1].Value, "13:58:08:359"); Assert.AreEqual(dataAccess.Row.Count, 18, "row count"); Assert.AreEqual(fm.FieldIndexInfo.IndexToInfo.Length, 27, "index to info"); Assert.AreEqual(fm.FieldIndexInfo.GetMaxRowCount(18), 18); TypeFieldInfo tfi = fm.FieldIndexInfo.QueryTypeFieldInfo(true, 1); Assert.IsNotNull(tfi); Assert.AreEqual(tfi.OutputFormat, "HH:mm:ss.fff"); string value = dataAccess.Row[1].Value; Assert.AreEqual(value, "13:58:08:359"); }
public void TestLogRecord_FullFields() { FieldMapperReading<LogRecord> fm = new FieldMapperReading<LogRecord>(_fileDescriptionNamesUs, null, false); Assert.IsNotNull(fm); Assert.IsNotNull(fm.FieldIndexInfo); Assert.IsNotNull(fm.NameToInfo); Assert.AreEqual(fm.NameToInfo.Count, 27); Assert.IsNotNull(fm.NameToInfo["PCI"]); Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true); List<int> charLengths = fm.GetCharLengths(); Assert.IsNull(charLengths); FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs); Assert.IsNotNull(dataAccess); RowReader<LogRecord> reader = dataAccess.ReadDataPreparation<LogRecord>(null); Assert.IsNotNull(reader); Assert.IsNotNull(dataAccess.Cs); dataAccess.Row = new DataRow(); Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row)); bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, true); Assert.IsFalse(readingResult); Assert.IsTrue(dataAccess.Cs.ReadRow(dataAccess.Row)); Assert.AreEqual(dataAccess.Row[0].Value, "0"); Assert.AreEqual(dataAccess.Row[1].Value, "13:58:08:359"); Assert.AreEqual(dataAccess.Row.Count, 18, "row count"); Assert.AreEqual(fm.FieldIndexInfo.IndexToInfo.Length, 27, "index to info"); Assert.AreEqual(fm.FieldIndexInfo.GetMaxRowCount(18), 18); TypeFieldInfo tfi = fm.FieldIndexInfo.QueryTypeFieldInfo(true, 1); Assert.IsNotNull(tfi); Assert.AreEqual(tfi.OutputFormat, "HH:mm:ss.fff"); string value = dataAccess.Row[1].Value; Assert.AreEqual(value, "13:58:08:359"); }
public void TestLogRecord_FullFields_2() { FieldMapperReading<LogRecord> fm = new FieldMapperReading<LogRecord>(_fileDescriptionNamesUs, null, false); Assert.IsNotNull(fm); Assert.IsNotNull(fm.FieldIndexInfo); Assert.IsNotNull(fm.NameToInfo); Assert.AreEqual(fm.NameToInfo.Count, 27); Assert.IsNotNull(fm.NameToInfo["PCI"]); Assert.AreEqual(fm.NameToInfo["PCI"].HasColumnAttribute, true); List<int> charLengths = fm.GetCharLengths(); Assert.IsNull(charLengths); FileDataAccess dataAccess = new FileDataAccess(_testInput.GetStreamReader(), _fileDescriptionNamesUs); Assert.IsNotNull(dataAccess); RowReader<LogRecord> reader = dataAccess.ReadDataPreparation<LogRecord>(null); Assert.IsNotNull(reader); dataAccess.Row = new DataRow(); List<LogRecord> records = dataAccess.ReadFieldDataRows(reader, null, fm, null).ToList(); Assert.IsNotNull(records); Assert.AreEqual(records.Count, 1); Assert.AreEqual(records[0].Id, 0); Assert.AreEqual(records[0].Time.Millisecond, 359); Assert.AreEqual(records[0].Sinr, 10.1); Assert.AreEqual(records[0].UlMcs, 17); Assert.AreEqual(records[0].DlThroughput, 10749096); }
public void GoodFileNoSeparatorCharUSEnglish() { // Arrange CsvFileDescription fileDescription_namesUs = new CsvFileDescription { NoSeparatorChar = true, UseOutputFormatForParsingCsvValue = false, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; const string testInput = @"AAAAAAAA34.18405/23/08 BBBBBBBB10.31105/12/12 CCCCCCCC12.00012/23/08"; var expected = new[] { new ProductDataCharLength { Name = "AAAAAAAA", Weight = 34.184, StartDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { Name = "BBBBBBBB", Weight = 10.311, StartDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { Name = "CCCCCCCC", Weight = 12.000, StartDate = new DateTime(2008, 12, 23), } }; // Act and Assert FileDataAccess dataAccess = new FileDataAccess(testInput.GetStreamReader(), fileDescription_namesUs); RowReader <ProductDataCharLength> reader = dataAccess.ReadDataPreparation <ProductDataCharLength>(null); dataAccess.Row = new DataRow(); FieldMapperReading <ProductDataCharLength> fm = new FieldMapperReading <ProductDataCharLength>( fileDescription_namesUs, null, false); List <int> charLengths = fm.GetCharLengths(); Assert.AreEqual(charLengths.Count, 3); bool firstRow = true; List <ProductDataCharLength> actual = new List <ProductDataCharLength>(); while (dataAccess.Cs.ReadRow(dataAccess.Row, charLengths)) { if ((dataAccess.Row.Count == 1) && ((dataAccess.Row[0].Value == null) || (string.IsNullOrEmpty(dataAccess.Row[0].Value.Trim())))) { continue; } bool readingResult = reader.ReadingOneFieldRow(fm, dataAccess.Row, firstRow); if (readingResult) { actual.Add(reader.Obj); } firstRow = false; } AssertCollectionsEqual(actual, expected); }