public void Ensures_GivenValidLine_ResultsInValidIShare() { var lineParser = new CsvLineParser(); IShare share = lineParser.ParseLine("04.03.2013;7.654,67;7.708,88;7.637,32;7.691,68;2.148.781.568"); Assert.That(share.Datum, Is.EqualTo(new DateTime(2013, 3, 4))); }
public void ParseLine_InvalidDateTimeFormat_Exception() { CsvLineParser lineParser = new CsvLineParser(TestInitializationFactory.GenerateFakeColumnTypes()); string lineToParse = "2018ax01-03 12:00:00, 1,2,3,4,5"; Assert.Catch(() => lineParser.ParseLine(lineToParse)); }
public void ParseLine_ValidLineParse_Success() { CsvLineParser lineParser = new CsvLineParser(TestInitializationFactory.GenerateFakeColumnTypes()); string lineToParse = "2018-01-03 12:00:00, 1,2,3,4,5"; DataObject result = lineParser.ParseLine(lineToParse); Assert.AreEqual(result.Columns.Length, 6); Assert.AreEqual(result.Columns[0].GetType(), typeof(DateTime)); for (int i = 1; i < 6; i++) { Assert.AreEqual(result.Columns[i].GetType(), typeof(int)); Assert.AreEqual(result.Columns[i], i); } }
private void ParseCSV(string data, CsvLineParser parser, IfcClassification source) { TextReader csvReader = new StringReader(data); //header line string line = csvReader.ReadLine(); CsvLineParser lineParser = parser; lineParser.ParseHeader(line); //get first line of data line = csvReader.ReadLine(); while (line != null) { //parse line Line parsedLine = lineParser.ParseLine(line); //create IFC object IfcSystem system = GetOrCreateSystem(parsedLine.Code, parsedLine.Description); var classification = GetOrCreateClassificationReference(parsedLine.Code, parsedLine.Description, source); //set up hierarchy if (system == null) { continue; } IfcSystem parentSystem = GetOrCreateSystem(parsedLine.ParentCode); if (parentSystem != null) { parentSystem.AddObjectToGroup(system); } //read new line to be processed in the next step line = csvReader.ReadLine(); } }
public void Ensures_GivenNullValueToParse_ExepectArgumentNullException() { var lineParser = new CsvLineParser(); Assert.Throws <ArgumentNullException>(() => lineParser.ParseLine(null)); }