public void Matches_IsTrue_WhenParametersAreEquivalent() { var function1 = @"using System; public static void Run(string id, out string output) { output = string.Empty; }"; // Diferent formatting, qualified name, not using alias var function2 = @"using System; public static void Run( System.String id , out String output ) { string result = string.Empty; output = result; }"; var tree1 = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var tree2 = CSharpSyntaxTree.ParseText(function2, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation1 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references) .AddSyntaxTrees(tree1)); var compilation2 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test2", references: references) .AddSyntaxTrees(tree2)); var signature1 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); var signature2 = compilation2.GetEntryPointSignature(new FunctionEntryPointResolver()); Assert.True(signature1.Equals(signature2)); Assert.Equal(signature1.GetHashCode(), signature2.GetHashCode()); }
private Tuple <FunctionSignature, FunctionSignature> GetFunctionSignatures(string function1, string function2) { var tree1 = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var tree2 = CSharpSyntaxTree.ParseText(function2, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation1 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references) .AddSyntaxTrees(tree1)); var compilation2 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test2", references: references) .AddSyntaxTrees(tree2)); var signature1 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); var signature2 = compilation2.GetEntryPointSignature(new FunctionEntryPointResolver()); return(Tuple.Create(signature1, signature2)); }
public void Matches_IsTrue_WhenUsingLocalTypes() { var function1 = @"using System; public static void Run(Test id, out string output) { output = string.Empty; } public class Test { public string Id { get; set; } }"; var tree = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation = CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references).AddSyntaxTrees(tree); var signature1 = new Script.Description.CSharpCompilation(compilation).GetEntryPointSignature(new FunctionEntryPointResolver()); Assert.True(signature1.HasLocalTypeReference); }
public void Matches_IsFalse_WhenNotUsingLocalTypes() { var function1 = @"using System; using System.Threading.Tasks; using System.Collections.Generic; public static void Run(string id, int test1) { } public class Test { public string Id { get; set; } }"; var tree = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation = CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references).AddSyntaxTrees(tree); var signature1 = new Script.Description.CSharpCompilation(compilation).GetEntryPointSignature(new FunctionEntryPointResolver(), null); Assert.False(signature1.HasLocalTypeReference); }
private Tuple<FunctionSignature, FunctionSignature> GetFunctionSignatures(string function1, string function2) { var tree1 = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var tree2 = CSharpSyntaxTree.ParseText(function2, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation1 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references) .AddSyntaxTrees(tree1)); var compilation2 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test2", references: references) .AddSyntaxTrees(tree2)); var signature1 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); var signature2 = compilation2.GetEntryPointSignature(new FunctionEntryPointResolver()); return Tuple.Create(signature1, signature2); }
public void Matches_IsFalse_WhenNotUsingLocalTypes() { var function1 = @"using System; using System.Threading.Tasks; using System.Collections.Generic; public static void Run(string id, int test1) { } public class Test { public string Id { get; set; } }"; var tree = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation = CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references).AddSyntaxTrees(tree); var signature1 = new Script.Description.CSharpCompilation(compilation).GetEntryPointSignature(new FunctionEntryPointResolver()); Assert.False(signature1.HasLocalTypeReference); }