Esempio n. 1
0
        public async Task ComputeRefactorings()
        {
            var code     = Resources.SampleViewModel;
            var doc      = CreateDocument(code, "SampleViewModel.cs");
            var span     = new TextSpan(code.IndexOf("public string Name") + "public string ".Length, "Name".Length);
            var actions  = new List <CodeAction>();
            var context  = new CodeRefactoringContext(doc, span, actions.Add, CancellationToken.None);
            var provider = new PrismCodeRefactoringProvider();

            await provider.ComputeRefactoringsAsync(context);

            Assert.That(actions, Has.Count.EqualTo(1));
        }
Esempio n. 2
0
        public async Task ApplyRefactoring(string code, string refactoredCode)
        {
            var doc       = CreateDocument(code, "SampleViewModel.cs");
            var workspace = doc.Project.Solution.Workspace;
            var span      = new TextSpan(code.IndexOf("public string Name") + "public string ".Length, "Name".Length);
            var actions   = new List <CodeAction>();
            var context   = new CodeRefactoringContext(doc, span, actions.Add, CancellationToken.None);
            var provider  = new PrismCodeRefactoringProvider();
            await provider.ComputeRefactoringsAsync(context);

            var action = actions.First();

            var operations = await action.GetOperationsAsync(CancellationToken.None);

            operations[0].Apply(workspace, CancellationToken.None);

            var updatedCode = await workspace.CurrentSolution.GetDocument(doc.Id).GetTextAsync();

            Assert.That(updatedCode.ToString(), Is.EqualTo(refactoredCode));
        }