public void CanGetRootsWhenNodeMoved() { var fileId = Guid.NewGuid().ToString(); var codeFile = this.PrepareCodeFile(fileId, this.cSharpSource01); var subject = new SingleNodeSnapshot(codeFile, new SyntaxTreeMappedVisitor <SyntaxTreeMappedVisitorContext>()); var node = codeFile.SyntaxTree.GetRoot().DescendantNodes().OfType <FieldDeclarationSyntax>().First(f => f.Declaration.Variables.Count > 0 && f.Declaration.Variables.First().Identifier.Text == "FieldToMove"); var annotatedRoot = subject.Initialize(node); codeFile.SyntaxTree = annotatedRoot.SyntaxTree; var fieldToMove = codeFile.SyntaxTree.GetRoot().DescendantNodes().OfType <FieldDeclarationSyntax>().First(f => f.Declaration.Variables.Count > 0 && f.Declaration.Variables.First().Identifier.Text == "FieldToMove"); FieldRemover remover = new FieldRemover("FieldToMove"); codeFile.SyntaxTree = remover.Visit(codeFile.SyntaxTree.GetRoot()).SyntaxTree; FieldAdder adder = new FieldAdder("MyHelperClass", fieldToMove); codeFile.SyntaxTree = adder.Visit(codeFile.SyntaxTree.GetRoot()).SyntaxTree; var result = subject.ResolveRoot(); result.Should().NotBeNull(); result.CurrentPath.ToString().Should().Be($"{Languages.CSharp}:{fileId}/Members[0]/Members[0]/Members[1]"); result.OriginalPath.ToString().Should().Be($"{Languages.CSharp}:{fileId}/Members[0]/Members[1]/Members[9]"); }
public void CanGetRootWhenUnmodified() { var fileId = Guid.NewGuid().ToString(); var codeFile = this.PrepareCodeFile(fileId, this.cSharpSource01); var subject = new SingleNodeSnapshot(codeFile, new SyntaxTreeMappedVisitor <SyntaxTreeMappedVisitorContext>()); var node = codeFile.SyntaxTree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>().First(c => c.Identifier.Text == "MyAwesomeClass"); var annotatedRoot = subject.Initialize(node); codeFile.SyntaxTree = annotatedRoot.SyntaxTree; var result = subject.ResolveRoot(); result.Should().NotBeNull(); result.CurrentPath.ToString().Should().Be($"{Languages.CSharp}:{fileId}/Members[0]/Members[1]"); result.OriginalPath.ToString().Should().Be($"{Languages.CSharp}:{fileId}/Members[0]/Members[1]"); }