public static TestRefactoringContext Create (string content)
{
int idx = content.IndexOf ("$");
if (idx >= 0)
content = content.Substring (0, idx) + content.Substring (idx + 1);
int idx1 = content.IndexOf ("<-");
int idx2 = content.IndexOf ("->");
int selectionStart = 0;
int selectionEnd = 0;
if (0 <= idx1 && idx1 < idx2) {
content = content.Substring (0, idx2) + content.Substring (idx2 + 2);
content = content.Substring (0, idx1) + content.Substring (idx1 + 2);
selectionStart = idx1;
selectionEnd = idx2 - 2;
idx = selectionEnd;
}
var doc = new StringBuilderDocument (content);
var parser = new CSharpParser ();
var unit = parser.Parse (content, "program.cs");
foreach (var error in parser.Errors)
Console.WriteLine (error.Message);
Assert.IsFalse (parser.HasErrors, "File contains parsing errors.");
unit.Freeze ();
var parsedFile = unit.ToTypeSystem ();
IProjectContent pc = new CSharpProjectContent ();
pc = pc.UpdateProjectContent (null, parsedFile);
pc = pc.AddAssemblyReferences (new[] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
var compilation = pc.CreateCompilation ();
var resolver = new CSharpAstResolver (compilation, unit, parsedFile);
TextLocation location = TextLocation.Empty;
if (idx >= 0)
location = doc.GetLocation (idx);
return new TestRefactoringContext(doc, location, resolver) {
selectionStart = selectionStart,
selectionEnd = selectionEnd
};
}