public void AssertGetValueParserTest(Type valueType, Type expectedValueParserType) { var parserFactory = new DefaultParserFactory(); var actualValueParser = parserFactory.GetValueParser(valueType); Assert.NotNull(actualValueParser); Assert.AreEqual(expectedValueParserType, actualValueParser.GetType()); }
public void AssertGetValueParserTest(Type valueType, Type expectedValueParserType) { var parserFactory = new DefaultParserFactory(); var actualValueParser = parserFactory.GetValueParser(valueType); Assert.NotNull(actualValueParser); Assert.AreEqual(expectedValueParserType, actualValueParser.GetType()); }
public void Create_DelegatesConfiguration() { var factory = new DefaultParserFactory(); var configuration = new ContentTypeConfiguration(CodeGeneratorConfiguration.Create(), "DocumentType"); var dataTypeDefinitions = new List <DataTypeDefinition>(); var parser = factory.Create(configuration, dataTypeDefinitions); Assert.IsInstanceOf <DocumentTypeCodeParser>(parser); }
public void NotSupportDataSourceTest() { var dataSourceLocation = new XMLDataSourceLocation("", ""); var mockDataToImport = new Mock<IDataToImport>(); var parserFactory = new DefaultParserFactory(); var testCellParser = new ElementParser(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 XML Node Parser", testParsingResult.Message); Assert.Null(testParsingResult.Value); }
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); }
private static string AddScopeToSelectors(string filePath, SourceText inputSourceText, string cssScope, out IEnumerable <RazorDiagnostic> diagnostics) { var cssParser = new DefaultParserFactory().CreateParser(); var inputText = inputSourceText.ToString(); var stylesheet = cssParser.Parse(inputText, insertComments: false); var resultBuilder = new StringBuilder(); var previousInsertionPosition = 0; var foundDiagnostics = new List <RazorDiagnostic>(); var ensureNoImportsVisitor = new EnsureNoImports(filePath, inputSourceText, stylesheet, foundDiagnostics); ensureNoImportsVisitor.Visit(); var scopeInsertionPositionsVisitor = new FindScopeInsertionEdits(stylesheet); scopeInsertionPositionsVisitor.Visit(); foreach (var edit in scopeInsertionPositionsVisitor.Edits) { resultBuilder.Append(inputText.Substring(previousInsertionPosition, edit.Position - previousInsertionPosition)); previousInsertionPosition = edit.Position; switch (edit) { case InsertSelectorScopeEdit _: resultBuilder.AppendFormat(CultureInfo.InvariantCulture, "[{0}]", cssScope); break; case InsertKeyframesNameScopeEdit _: resultBuilder.AppendFormat(CultureInfo.InvariantCulture, "-{0}", cssScope); break; case DeleteContentEdit deleteContentEdit: previousInsertionPosition += deleteContentEdit.DeleteLength; break; default: throw new NotImplementedException($"Unknown edit type: '{edit}'"); } } resultBuilder.Append(inputText.Substring(previousInsertionPosition)); diagnostics = foundDiagnostics; return(resultBuilder.ToString()); }
public void ParsingSuccessTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataToImport = new XMLDataToImport(dataFromFileSystem); var dataSourceLocation = new XMLDataSourceLocation("LabReport", "Lab_Report_Number"); var parserFactory = new DefaultParserFactory(); var testCellParser = new ElementParser(parserFactory); var testParsingResult = testCellParser.Parse(dataToImport, dataSourceLocation, typeof(string)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.INFO, testParsingResult.Level); Assert.AreEqual("Parsing value successfully", testParsingResult.Message); Assert.AreEqual("LR04927", testParsingResult.Value); }
public void OutOfRangeTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataSourceLocation = new XMLDataSourceLocation("here", "there"); var dataToImport = new XMLDataToImport(dataFromFileSystem); var parserFactory = new DefaultParserFactory(); var testElementParser = new ElementParser(parserFactory); var testParsingResult = testElementParser.Parse(dataToImport, dataSourceLocation, typeof(int)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.FATAL, testParsingResult.Level); //Assert.AreEqual("Argument is out of range", testParsingResult.Message); Assert.Null(testParsingResult.Value); }
public void OutOfRangeTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataSourceLocation = new XMLDataSourceLocation("here","there"); var dataToImport = new XMLDataToImport(dataFromFileSystem); var parserFactory = new DefaultParserFactory(); var testElementParser = new ElementParser(parserFactory); var testParsingResult = testElementParser.Parse(dataToImport, dataSourceLocation, typeof(int)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.FATAL, testParsingResult.Level); //Assert.AreEqual("Argument is out of range", testParsingResult.Message); Assert.Null(testParsingResult.Value); }
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); }
public void ParseTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "TestJSONFile.json"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataSourceLocation = new JSONDataSourceLocation("objects[*].name", true); var dataToImport = new JSONDataToImport(dataFromFileSystem); var parserFactory = new DefaultParserFactory(); var testParser = new SimpleJSONObjectParser(parserFactory); var parseResults = testParser.Parse(dataToImport, dataSourceLocation, typeof(string)) as ParsingResult; dynamic result = parseResults.Value; Assert.NotNull(parseResults); Assert.AreEqual("Cruise", result[0]); Assert.AreEqual("Data retrieval", result[1]); Assert.AreEqual("Derivation", result[2]); }
// Public for tests public static string AddScopeToSelectors(string inputText, string cssScope) { var cssParser = new DefaultParserFactory().CreateParser(); var stylesheet = cssParser.Parse(inputText, insertComments: false); var resultBuilder = new StringBuilder(); var previousInsertionPosition = 0; var scopeInsertionPositionsVisitor = new FindScopeInsertionEdits(stylesheet); scopeInsertionPositionsVisitor.Visit(); foreach (var edit in scopeInsertionPositionsVisitor.Edits) { resultBuilder.Append(inputText.Substring(previousInsertionPosition, edit.Position - previousInsertionPosition)); previousInsertionPosition = edit.Position; switch (edit) { case InsertSelectorScopeEdit _: resultBuilder.AppendFormat("[{0}]", cssScope); break; case InsertKeyframesNameScopeEdit _: resultBuilder.AppendFormat("-{0}", cssScope); break; case DeleteContentEdit deleteContentEdit: previousInsertionPosition += deleteContentEdit.DeleteLength; break; default: throw new NotImplementedException($"Unknown edit type: '{edit}'"); } } resultBuilder.Append(inputText.Substring(previousInsertionPosition)); return(resultBuilder.ToString()); }
// Public for tests public static string AddScopeToSelectors(string inputText, string cssScope) { var cssParser = new DefaultParserFactory().CreateParser(); var stylesheet = cssParser.Parse(inputText, insertComments: false); var resultBuilder = new StringBuilder(); var previousInsertionPosition = 0; var scopeInsertionPositionsVisitor = new FindScopeInsertionPositionsVisitor(stylesheet); scopeInsertionPositionsVisitor.Visit(); foreach (var(currentInsertionPosition, insertionType) in scopeInsertionPositionsVisitor.InsertionPositions) { resultBuilder.Append(inputText.Substring(previousInsertionPosition, currentInsertionPosition - previousInsertionPosition)); switch (insertionType) { case ScopeInsertionType.Selector: resultBuilder.AppendFormat("[{0}]", cssScope); break; case ScopeInsertionType.KeyframesName: resultBuilder.AppendFormat("-{0}", cssScope); break; default: throw new NotImplementedException($"Unknown insertion type: '{insertionType}'"); } previousInsertionPosition = currentInsertionPosition; } resultBuilder.Append(inputText.Substring(previousInsertionPosition)); return(resultBuilder.ToString()); }
public void AssertGetValueParserFailTest(Type valueType) { var parserFactory = new DefaultParserFactory(); var actualValueParser = parserFactory.GetValueParser(valueType); }
public void AssertGetValueParserFailTest(Type valueType) { var parserFactory = new DefaultParserFactory(); var actualValueParser = parserFactory.GetValueParser(valueType); }
public void ParsingSuccessTest() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "XMLSample.xml"); var dataSource = new WindowsFileSystem(path); var dataFromFileSystem = dataSource.FetchData(); var dataToImport = new XMLDataToImport(dataFromFileSystem); var dataSourceLocation = new XMLDataSourceLocation("LabReport", "Lab_Report_Number"); var parserFactory = new DefaultParserFactory(); var testCellParser = new ElementParser(parserFactory); var testParsingResult = testCellParser.Parse(dataToImport, dataSourceLocation, typeof(string)) as ParsingResult; Assert.NotNull(testParsingResult); Assert.AreEqual(ResultLevel.INFO, testParsingResult.Level); Assert.AreEqual("Parsing value successfully", testParsingResult.Message); Assert.AreEqual("LR04927",testParsingResult.Value); }