public bool Verify(string asmName, string typeName, string baselineFile, bool pdb) { try { var xslt = new XslCompiledTransform(); Assembly xsltasm = AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(asmName)); if (xsltasm == null) { //_output.WriteLine("Could not load file"); return(false); } Type t = xsltasm.GetType(typeName); if (t == null) { //_output.WriteLine("No type loaded"); return(false); } xslt.Load(t); var inputXml = new XmlDocument(); using (var stream = new MemoryStream()) using (var sw = new StreamWriter(stream) { AutoFlush = true }) { inputXml.LoadXml("<foo><bar>Hello, world!</bar></foo>"); xslt.Transform(inputXml, null, sw); if (!XsltVerificationLibrary.CompareXml(Path.Combine(XsltcModule.TargetDirectory, baselineFile), stream)) { //_output.WriteLine("Baseline file comparison failed"); return(false); } } return(true); } catch (Exception e) { s_output.WriteLine(e.Message); return(false); } // Turning this off as this causes noise on different platforms like IA64. // Also since we verify the assembly by loading there is not really a need for this verification. // if (succeeded && runAssemblyVerification) { // String peOutput = String.Empty; // succeeded = XsltVerificationLibrary.VerifyAssemblyUsingPEVerify( // asmName, // logger, // ref peOutput); // logger.LogMessage("Assembly Verification Result: " + peOutput); //} }
public bool Verify(string asmName, string typeName, string baselineFile, bool pdb) { try { var xslt = new XslCompiledTransform(); Assembly xsltasm = AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(asmName)); if (xsltasm == null) { //_output.WriteLine("Could not load file"); return(false); } Type t = xsltasm.GetType(typeName); if (t == null) { //_output.WriteLine("No type loaded"); return(false); } xslt.Load(t); var inputXml = new XmlDocument(); using (var stream = new MemoryStream()) using (var sw = new StreamWriter(stream) { AutoFlush = true }) { inputXml.LoadXml("<foo><bar>Hello, world!</bar></foo>"); xslt.Transform(inputXml, null, sw); if (!XsltVerificationLibrary.CompareXml(Path.Combine(XsltcModule.TargetDirectory, baselineFile), stream)) { //_output.WriteLine("Baseline file comparison failed"); return(false); } } return(true); } catch (Exception e) { s_output.WriteLine(e.Message); return(false); } }
/// <summary> /// Currently this method supports only 1 input file. For variations that require more than one input file to test /// @file /// functionality, custom-craft and write those input files in the body of the variation method, then pass an /// appropriate /// commandline such as @file1 @file2 @file3, along with createFromInputFile = false. /// </summary> /// <param name="commandLine"></param> /// <param name="createFromInputFile"></param> /// <param name="expectedToSucceed"></param> /// <param name="targetDirectory"></param> /// <returns></returns> private string TryCreatePersistedTransformAssembly(string commandLine, bool createFromInputFile, bool expectedToSucceed, string targetDirectory) { // If createFromInputFile is specified, create an input file now that the compiler can consume. string processArguments = createFromInputFile ? "@" + CreateInputFile(commandLine) : commandLine; var processStartInfo = new ProcessStartInfo { FileName = XsltVerificationLibrary.SearchPath("xsltc.exe"), Arguments = processArguments, //WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, WorkingDirectory = targetDirectory }; // Call xsltc to create persistant assembly. var compilerProcess = new Process { StartInfo = processStartInfo }; compilerProcess.Start(); string output = compilerProcess.StandardOutput.ReadToEnd(); compilerProcess.WaitForExit(); if (createFromInputFile) { SafeDeleteFile(processArguments.Substring(1)); } if (expectedToSucceed) { // The Assembly was created successfully if (compilerProcess.ExitCode == 0) { return(output); } throw new CTestFailedException("Failed to create assembly: " + output); } return(output); }