public async Task FixesAreReportedByExtension() { var expected = new ExpectedCodeFixes { CodeFixData = new CodeActionData [] { new CodeActionData { Message = "Add accessibility modifiers" }, }, CodeRefactoringData = new CodeActionData [] { new CodeActionData { Message = "To public" }, new CodeActionData { Message = "Generate overrides..." }, new CodeActionData { Message = "Generate constructor 'MyClass()'" }, new CodeActionData { Message = "Rename file to MyClass.cs" }, new CodeActionData { Message = "Rename type to a" }, } }; Projects.Solution sol = null; var old = IdeApp.Preferences.EnableSourceAnalysis; try { IdeApp.Preferences.EnableSourceAnalysis.Value = true; int expectedUpdates = 1; ImmutableArray <QuickTask> qt = ImmutableArray <QuickTask> .Empty; var tuple = await GatherFixesNoDispose <bool> (OneFromEach, (resultExt, tcs) => { if (--expectedUpdates == 0) { qt = resultExt.QuickTasks; tcs.SetResult(true); } }); var ext = tuple.Item1; sol = tuple.Item2; Assert.AreEqual(1, qt.Length); ext.Editor.CaretOffset = qt[0].Location; var fixes = await ext.GetCurrentFixesAsync(CancellationToken.None); AssertCodeFixes(fixes, expected); } finally { IdeApp.Preferences.EnableSourceAnalysis.Value = old; TypeSystemService.Unload(sol); } }
public async Task FixesAreReportedForCompilerErrors() { var expected = new ExpectedCodeFixes { CodeFixData = new CodeActionData [] { new CodeActionData { Message = "Implement interface" }, new CodeActionData { Message = "Implement interface with Dispose pattern" }, new CodeActionData { Message = "Implement interface explicitly" }, new CodeActionData { Message = "Implement interface explicitly with Dispose pattern" }, }, CodeRefactoringData = new CodeActionData[] { new CodeActionData { Message = "To public" }, }, }; Projects.Solution sol = null; var old = IdeApp.Preferences.EnableSourceAnalysis; try { IdeApp.Preferences.EnableSourceAnalysis.Value = true; int expectedUpdates = 2; ImmutableArray <Result> qt = ImmutableArray <Result> .Empty; var tuple = await GatherFixesNoDispose <bool> (IDisposableImplement, (resultExt, tcs) => { if (--expectedUpdates == 0) { qt = resultExt.GetResults().ToImmutableArray(); tcs.SetResult(true); } }); var ext = tuple.Item1; sol = tuple.Item2; Assert.AreEqual(2, qt.Length); var diag = qt.OfType <DiagnosticResult> ().Single(x => x.Diagnostic.Id == "CS0535"); ext.Editor.CaretOffset = diag.Region.Start; var fixes = await ext.GetCurrentFixesAsync(CancellationToken.None); AssertCodeFixes(fixes, expected); } finally { IdeApp.Preferences.EnableSourceAnalysis.Value = old; TypeSystemService.Unload(sol); } }
static void AssertCodeFixes(CodeActionContainer fixes, ExpectedCodeFixes expected) { var fixActions = fixes.CodeFixActions.SelectMany(x => x.Fixes).ToArray(); Assert.AreEqual(expected.CodeFixData.Length, fixActions.Length); for (int j = 0; j < expected.CodeFixData.Length; ++j) { Assert.AreEqual(expected.CodeFixData [j].Message, fixActions [j].Action.Message); } var fixRefactorings = fixes.CodeRefactoringActions.SelectMany(x => x.Actions).ToArray(); Assert.AreEqual(expected.CodeRefactoringData.Length, fixRefactorings.Length); for (int j = 0; j < expected.CodeRefactoringData.Length; ++j) { Assert.AreEqual(expected.CodeRefactoringData [j].Message, fixRefactorings [j].Message); } }
protected static async Task AssertExpectedCodeFixes(ExpectedCodeFixes expected, Ide.Gui.Document doc) { var fixes = await doc.GetContent <CodeActionEditorExtension> ().GetCurrentFixesAsync(CancellationToken.None); var fixActions = fixes.CodeFixActions.SelectMany(x => x.Fixes).OrderBy(f => f.Action.Message).ToArray(); Assert.AreEqual(expected.CodeFixData.Length, fixActions.Length); for (int j = 0; j < expected.CodeFixData.Length; ++j) { Assert.AreEqual(expected.CodeFixData [j].Message, fixActions [j].Action.Message); } var fixRefactorings = fixes.CodeRefactoringActions.SelectMany(x => x.Actions).OrderBy(f => f.Message).ToArray(); Assert.AreEqual(expected.CodeRefactoringData.Length, fixRefactorings.Length); for (int j = 0; j < expected.CodeRefactoringData.Length; ++j) { Assert.AreEqual(expected.CodeRefactoringData [j].Message, fixRefactorings [j].Message); } }