public void TestMethodBlockGenerator() { HookedRenderInfoGenerator generator = new HookedRenderInfoGenerator(); ClassInfo classInfo = FactoryHelper.CreateClassInfo(); CodeRunnerInfo codeRunnerInfo = FactoryHelper.GenerateCodeRunnerInfo(); classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0); int id = 0; CodeRunBlockRenderingInfo renderInfo = generator.CodeRunBlockRenderInfoForMethod(classInfo, id); Assert.IsTrue(renderInfo.renderingInfo[0][0].Contains("OnMethodEnter")); Assert.IsTrue(renderInfo.renderingInfo[0][1].Contains("LogLineRun")); Assert.IsTrue(renderInfo.renderingInfo[0][2].Contains("0")); }
public static TestCase GetSimple2LineMethodCase() { string testMethod = @""" class TestClass { void MethodA() { int count = 0; count ++; } } """; ClassInfo classInfo = FactoryHelper.CreateClassInfo(); classInfo.RelativeFilePath = "TestFile.cs"; CodeRunnerInfo codeRunnerInfo = new CodeRunnerInfo(); codeRunnerInfo.Name = "MethodA"; codeRunnerInfo.IsConstructor = false; codeRunnerInfo.blockInfo[0] = new BlockInfo(); codeRunnerInfo.blockInfo[0].CloseBraceLineNo = 7; StatementInfo sInfo = new StatementInfo(); sInfo = new StatementInfo { LineNo = 5 }; codeRunnerInfo.blockInfo[0].Add(sInfo); sInfo = new StatementInfo { LineNo = 6 }; codeRunnerInfo.blockInfo[0].Add(sInfo); classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0); CSfileInfo cSfileInfo = new CSfileInfo(); cSfileInfo.Classes.Add(classInfo); Dictionary <int, List <string> > renderingInfo = new Dictionary <int, List <string> >() { }; renderingInfo[0] = new List <string>() { "OnMethodEnter();", "LogLineRun()", "0", "LogLineRun()", "1", "LogLineRun()", }; List <string> expectedStatementSubStrings = new List <string>() { "OnMethodEnter", "LogLineRun", "int count", "LogLineRun", "count ++", }; SyntaxNode methSyntax = Helpers.GetFirstMethodSyntax(testMethod); SyntaxTree root = Helpers.GetRoot(testMethod); return(new TestCase { Code = testMethod, ClassInfo = classInfo, ExpectedStatements = expectedStatementSubStrings, ExpectedStatementCount = 6, Node = methSyntax, RenderInfo = renderingInfo, Root = root, FileName = classInfo.RelativeFilePath, CSFileInfo = cSfileInfo, }); }
public static TestCase GetSingleIfMethod() { string testMethod = @""" class TestClass { void MethodA() { int b=3; if(true) { int count = 0; } } } """; MethodDeclarationSyntax methSyntax = Helpers.GetFirstMethodSyntax(testMethod); ClassInfo classInfo = FactoryHelper.CreateClassInfo(); classInfo.RelativeFilePath = "TestFile.cs"; CodeRunnerInfo codeRunnerInfo = new CodeRunnerInfo(); codeRunnerInfo.Name = "MethodA"; codeRunnerInfo.IsConstructor = false; codeRunnerInfo.blockInfo[0] = new BlockInfo(); codeRunnerInfo.blockInfo[0].CloseBraceLineNo = 9; codeRunnerInfo.blockInfo[1] = new BlockInfo(); codeRunnerInfo.blockInfo[1].CloseBraceLineNo = 10; StatementInfo sInfo = new StatementInfo(); sInfo = new StatementInfo { LineNo = 5 }; codeRunnerInfo.blockInfo[0].Add(sInfo); sInfo = new StatementInfo { LineNo = 6 }; codeRunnerInfo.blockInfo[0].Add(sInfo); sInfo = new StatementInfo { LineNo = 8 }; codeRunnerInfo.blockInfo[1].Add(sInfo); classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0); CSfileInfo cSfileInfo = new CSfileInfo(); cSfileInfo.Classes.Add(classInfo); SyntaxTree root = Helpers.GetRoot(testMethod); List <string> expectedStatementSubStrings = new List <string>() { "OnMethodEnter", "LogLineRun", "int b", "LogLineRun", "if(true)", "LogLineRun", "LogLineRun", "int count", "LogLineRun", }; return(new TestCase { Code = testMethod, ClassInfo = classInfo, ExpectedStatements = expectedStatementSubStrings, ExpectedStatementCount = 9, Node = methSyntax, Root = root, CSFileInfo = cSfileInfo, FileName = classInfo.RelativeFilePath }); }