public void CSVParseTestSuccess() { var dataSource = new WindowsFileSystem(_csvDataFilePath); var dataFromFileSystem = dataSource.FetchData(); var dataToImport = new CSVDataToImport(dataFromFileSystem); var dataSourceLocation = new CSVDataSourceLocation(6, 3); var dataDateTimeSourceLocation = new CSVDataSourceLocation(6, 0); var parser = new CellParser(new DefaultParserFactory()); var parseDoubleResult = parser.Parse(dataToImport, dataSourceLocation, typeof(double)); Assert.NotNull(parseDoubleResult); Assert.AreEqual(parseDoubleResult.Level, ResultLevel.INFO); Assert.AreEqual(parseDoubleResult.Message, "Parsing value successfully"); Assert.AreEqual(0.3, ((IParsingResult)parseDoubleResult).Value); var parseDateTimeResult = parser.Parse(dataToImport, dataDateTimeSourceLocation, typeof(DateTime)); Assert.NotNull(parseDateTimeResult); Assert.AreEqual(parseDateTimeResult.Level, ResultLevel.INFO); Assert.AreEqual(parseDateTimeResult.Message, "Parsing value successfully"); Assert.AreEqual(new DateTime(2013, 12, 12, 14, 0, 0), ((IParsingResult)parseDateTimeResult).Value); }
private static IExcelImporter CreateExcelImporter() { var cellCoordinateParser = new CellCoordinateParser(); var cellValueParser = new CellValueParser(); var cellParser = new CellParser(cellCoordinateParser, cellValueParser); var excelImporter = new ExcelImporter(cellParser); return(excelImporter); }
private ExcelDataSet CreateDataSet() { var cellCoordinateParser = new CellCoordinateParser(); var cellValueParser = new CellValueParser(); var cellParser = new CellParser(cellCoordinateParser, cellValueParser); var importer = new ExcelImporter(cellParser); var dataSet = importer.GetCellValues(@"data.xlsx"); return(dataSet); }
public override Expression VisitEXPR_Literal([NotNull] S_ScriptParser.EXPR_LiteralContext context) { string s = context.sliteral().GetText(); Cell x = CellValues.NullINT; if (context.sliteral().LITERAL_BOOL() != null) { x = CellParser.ParseBOOL(s); } else if (context.sliteral().LITERAL_DATE_TIME() != null) { x = CellParser.ParseDATE(s); } else if (context.sliteral().LITERAL_BYTE() != null) { x = CellParser.ParseBYTE(s); } else if (context.sliteral().LITERAL_SHORT() != null) { x = CellParser.ParseSHORT(s); } else if (context.sliteral().LITERAL_INT() != null) { x = CellParser.ParseINT(s); } else if (context.sliteral().LITERAL_LONG() != null) { x = CellParser.ParseLONG(s); } else if (context.sliteral().LITERAL_SINGLE() != null) { x = CellParser.ParseSINGLE(s); } else if (context.sliteral().LITERAL_DOUBLE() != null) { x = CellParser.ParseDOUBLE(s); } else if (context.sliteral().LITERAL_BINARY() != null) { x = CellParser.ParseBINARY(s); } else if (context.sliteral().LITERAL_BSTRING() != null) { x = CellParser.ParseBSTRING(s); } else if (context.sliteral().LITERAL_CSTRING() != null) { x = CellParser.ParseCSTRING(s); } return(new Expression.Literal(this._Host, this._Master, x)); }
public void TestMethod1() { var cellCoordinateParser = new CellCoordinateParser(); var cellValueParser = new CellValueParser(); var cellParser = new CellParser(cellCoordinateParser, cellValueParser); var importer = new ExcelImporter(cellParser); var result = importer.GetCellValues(@"data.xlsx"); Assert.AreEqual(15, result.TrialDataRows.Count); Assert.AreEqual("Vpn", result.TrialDataRows[0].Values[0]); }
public void NotSupportDataSourceTest() { var dataSourceLocation = new CSVDataSourceLocation(0, 0); var mockDataToImport = new Mock <IDataToImport>(); var parserFactory = new DefaultParserFactory(); var testCellParser = new CellParser(parserFactory); var testParsingResult = testCellParser.Parse(mockDataToImport.Object, dataSourceLocation, typeof(int)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.FATAL, testParsingResult.Level); Assert.AreEqual("Castle.Proxies.IDataToImportProxy is not supported by CSV Cell Parser", testParsingResult.Message); Assert.Null(testParsingResult.Value); }
// Records // public static Record ToRecord(string Text, Schema Columns, char[] Delims, char Escape) { // SplitUpper the data // string[] t = StringUtil.Split(Text, Delims, Escape, false); // Check the length // if (t.Length != Columns.Count) { throw new ArgumentException(string.Format("BString has {0} fields, but schema has {1} fields", t.Length, Columns.Count)); } // Build the record // RecordBuilder rb = new RecordBuilder(); for (int i = 0; i < t.Length; i++) { rb.Add(CellParser.Parse(t[i], Columns.ColumnAffinity(i))); } return(rb.ToRecord()); }
public void PasingSuccessTest() { var dataSourceLocation = new CSVDataSourceLocation(0, 0); var dataToImport = new CSVDataToImport("test.csv", new string[][] { new string[] { "1", "2", "3" } } ); var parserFactory = new DefaultParserFactory(); var testCellParser = new CellParser(parserFactory); var testParsingResult = testCellParser.Parse(dataToImport, dataSourceLocation, typeof(int)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.INFO, testParsingResult.Level); Assert.AreEqual("Parsing value successfully", testParsingResult.Message); Assert.AreEqual(1, (int)testParsingResult.Value); }
public void OutOfRangeTest() { var dataSourceLocation = new CSVDataSourceLocation(5, 0); var dataToImport = new CSVDataToImport("test.csv", new string[][] { new string[] { "1", "2", "3" } } ); var parserFactory = new DefaultParserFactory(); var testCellParser = new CellParser(parserFactory); var testParsingResult = testCellParser.Parse(dataToImport, dataSourceLocation, typeof(int)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.FATAL, testParsingResult.Level); Assert.AreEqual("Index is out of range", testParsingResult.Message); Assert.Null(testParsingResult.Value); }