private static void AssertAuditVariablesCount(string sourceCode, int expectedVariablesCount) { var tree = CSharpSyntaxTree.ParseText(sourceCode); IAuditVariablesWalker walker = new AuditVariablesWalker(); AuditVariablePlaceholder[] insertedNodes=walker.Walk(ProjectName, DocumentPath,tree.GetRoot()); Assert.That(insertedNodes.Length, Is.EqualTo(expectedVariablesCount)); }
public void Should_InsertAuditVariableBeforeLocalVariable() { const string expectedNodePath = "Name.doc.SampleNamespace.SampleClass.SampleMethod"; const string sourceCode=@"namespace SampleNamespace { class SampleClass { public void SampleMethod() { int a=4; } } }"; int methodStart = sourceCode.IndexOf("public void"); int expectedSpanPosition = sourceCode.IndexOf("int a", StringComparison.Ordinal) - methodStart; var tree = CSharpSyntaxTree.ParseText(sourceCode); IAuditVariablesWalker walker = new AuditVariablesWalker(); AuditVariablePlaceholder[] insertedAuditVariables=walker.Walk(ProjectName, DocumentPath,tree.GetRoot()); Assert.That(insertedAuditVariables.Length,Is.EqualTo(1)); Assert.That(insertedAuditVariables[0].DocumentPath, Is.EqualTo(DocumentPath)); Assert.That(insertedAuditVariables[0].NodePath, Is.EqualTo(expectedNodePath)); Assert.That(insertedAuditVariables[0].SpanStart, Is.EqualTo(expectedSpanPosition)); }