private static Dictionary <string, NamedFact> GetConvertedNamedFacts <TTargetCompiler>(List <NamedFact> runnableTestsInSource, ConversionResult convertedText) where TTargetCompiler : ICompiler, new() { string code = convertedText.ConvertedCode; var targetCompiler = new TTargetCompiler(); var compiledTarget = targetCompiler.AssemblyFromCode(targetCompiler.CreateTree(code), AdditionalReferences); var runnableTestsInTarget = XUnitFactDiscoverer.GetNamedFacts(compiledTarget).ToDictionary(f => f.Name); Assert.Equal(runnableTestsInSource.Select(f => f.Name), runnableTestsInTarget.Keys); return(runnableTestsInTarget); }
/// <summary> /// Returns facts which when executed, ensure the source Fact succeeds, then convert it, and ensure the target Fact succeeds too. /// </summary> public static IEnumerable <NamedFact> GetSelfVerifyingFacts <TSourceCompiler, TTargetCompiler, TLanguageConversion>(string testFilepath) where TSourceCompiler : ICompiler, new() where TTargetCompiler : ICompiler, new() where TLanguageConversion : ILanguageConversion, new() { var sourceFileText = File.ReadAllText(testFilepath, Encoding.UTF8); var sourceCompiler = new TSourceCompiler(); var syntaxTree = sourceCompiler.CreateTree(sourceFileText).WithFilePath(Path.GetFullPath(testFilepath)); var compiledSource = sourceCompiler.AssemblyFromCode(syntaxTree, AdditionalReferences); var runnableTestsInSource = XUnitFactDiscoverer.GetNamedFacts(compiledSource).ToList(); Assert.NotEmpty(runnableTestsInSource); return(GetSelfVerifyingFacts <TTargetCompiler, TLanguageConversion>(sourceFileText, runnableTestsInSource)); }