public void GetInvocationsTest1() { var expected = new List <StaticCodeAnalysis.Invocation> { new StaticCodeAnalysis.Invocation( new List <int> { 29 }, new List <MethodDeclarationSyntax> { testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C1.M2(int, int)"), testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C2.M2(int, int)") }), new StaticCodeAnalysis.Invocation( new List <int> { 33 }, new List <MethodDeclarationSyntax> { testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C1.M3(int, bool, string)"), testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C2.M3(int, bool, string)"), testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C3_1.M3(int, bool, string)") }) }; var actual = testAnalysis.GetInvocations(testAnalysis.GetMethodDeclSyntax("int ExampleCode1.C1.M1(int)")); CollectionAssert.AreEqual(expected, actual); }
// creates and returns the YoYo graph public YoYoGraph CreateYoYoGraph() { YoYoGraph graph = new YoYoGraph(); // create a node for each method List <MethodDeclarationSyntax> methods = codeAnalysis.GetAllMethods(); foreach (MethodDeclarationSyntax method in methods) { graph.AddNode(new YoYoNode(codeAnalysis.GetMethodId(method), codeAnalysis.GetFullMethodName(method), method)); } // create a node for each invocation and add the links List <Node> methodNodes = new List <Node>(graph.Nodes); foreach (YoYoNode methodNode in methodNodes) { int invocCount = 0; List <StaticCodeAnalysis.Invocation> invocations = codeAnalysis.GetInvocations(methodNode.Method); foreach (StaticCodeAnalysis.Invocation invocation in invocations) { YoYoNode invocNode = new YoYoNode(methodNode.Id + "_I" + invocCount.ToString(), $"invocs (L {String.Join(", ", invocation.Lines.Select(l => l + 1))})", invocation); graph.AddNode(invocNode); invocCount++; graph.AddLink(new YoYoLink(methodNode.Id, invocNode.Id)); foreach (MethodDeclarationSyntax invocOption in invocation.Methods) { graph.AddLink(new YoYoLink(invocNode.Id, graph.GetNode(codeAnalysis.GetMethodId(invocOption)).Id)); } } } return(graph); }
public void GetInvocationsTest() { var expected = new List <StaticCodeAnalysis.Invocation> { new StaticCodeAnalysis.Invocation( new List <int> { 29, 30, 32 }, new List <MethodDeclarationSyntax> { testAnalysis.GetMethodDeclSyntax("int ExampleCode3.B.N()"), testAnalysis.GetMethodDeclSyntax("int ExampleCode3.C1.N()") }), new StaticCodeAnalysis.Invocation( new List <int> { 31, 33 }, new List <MethodDeclarationSyntax> { testAnalysis.GetMethodDeclSyntax("int ExampleCode3.A.N()"), testAnalysis.GetMethodDeclSyntax("int ExampleCode3.B.N()"), testAnalysis.GetMethodDeclSyntax("int ExampleCode3.C1.N()"), testAnalysis.GetMethodDeclSyntax("int ExampleCode3.D.N()") }) }; var actual = testAnalysis.GetInvocations(testAnalysis.GetMethodDeclSyntax("int ExampleCode3.A.M(ExampleCode3.IA)")); CollectionAssert.AreEqual(expected, actual); }