public void CanParseSchemaAndGenerateCode(ParserTestFile xmlSchemaTestFile) { var generatedCode = SchemaCorrectorHelper.GetSchemaCorrectorCode(xmlSchemaTestFile); var didGenerateCode = !string.IsNullOrWhiteSpace(generatedCode); Assert.True(didGenerateCode); }
public void CanGetStreamForAllParserTestFiles(ParserTestFile testFile) { using (var testFileStream = TestFilesFactory.GetStreamForTestFile(testFile)) { Assert.NotNull(testFileStream); Assert.True(testFileStream.Length > 0); } }
public void CanCallCorrectCodeOnXml(ParserTestFile xmlSchemaTestFile) { var sourceDoc = GetExampleDocument(); var actualDoc = SchemaCorrectorHelper.CorrectXmlInstanceForSchema(xmlSchemaTestFile, sourceDoc); var expectedDoc = GetExampleDocument(); var xDocComparator = new XDocumentComparator(expectedDoc, actualDoc); xDocComparator.AssertXDocumentsAreEqual(); }
public static XDocument CorrectXmlInstanceForSchema(ParserTestFile schema, XDocument xmlInstance) { var compilation = GetCompilationForSchema(schema); var assembly = CompileLoadAndGetAssembly(compilation); var codeCorrectorType = assembly.GetType($"{GENERATED_CODE_NAMESPACE}.{CODE_GENERATOR_CLASSNAME}"); var codeCorrector = Activator.CreateInstance(codeCorrectorType, xmlInstance); var codeCorrectorMethod = codeCorrectorType.GetTypeInfo().GetDeclaredMethod(CODE_GENERATOR_METHOD_NAME); var correctedInstance = codeCorrectorMethod.Invoke(codeCorrector, null); return(correctedInstance as XDocument); }
private static CSharpCompilation GetCompilationForSchema(ParserTestFile testFile) { var xmlCorrectorCode = GetSchemaCorrectorCode(testFile); var syntaxTree = CSharpSyntaxTree.ParseText(xmlCorrectorCode); string assemblyName = Path.GetRandomFileName(); var references = GetAssemblyReferences(); CSharpCompilation compilation = CSharpCompilation.Create( assemblyName, new[] { syntaxTree }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); return(compilation); }
public static string GetSchemaCorrectorCode(ParserTestFile testFile) { using (var schemaStream = TestFilesFactory.GetStreamForTestFile(testFile)) { var xmlSchema = new XmlTools.Parser.XmlSchemaParser(schemaStream).GetSchema(); var codeGenOptions = new XmlTools.CodeGenerator.CodeGeneratorOptions { Namespace = GENERATED_CODE_NAMESPACE }; var codeGen = new XmlTools.CodeGenerator.XmlSchemaCorrectorGenerator(xmlSchema, codeGenOptions); var generatedCode = codeGen.GenerateCode(); return(generatedCode); } }
protected CodeGeneratorTestsBase(ParserTestFile schemaFile, SchemaCorrectorTestFile invalidTestFile, SchemaCorrectorTestFile validTestFile) { _schemaFile = schemaFile; _invalidTestFile = invalidTestFile; _validTestFile = validTestFile; }
public static Stream GetStreamForTestFile(ParserTestFile file) { return(GetStreamForTestFile("Parser", file.ToString())); }
protected TestFileBase(ParserTestFile testFile) { _testFile = testFile; }