public async Task VerifyGetFixesWhenChangingToTaskAndUsingDoesNotExist() { var code = @"using Csla; public class A : BusinessBase<A> { public async string DataPortal_Fetch() { } }"; var document = TestHelpers.Create(code); var tree = await document.GetSyntaxTreeAsync(); var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new FindOperationsWithIncorrectReturnTypesAnalyzer()); var sourceSpan = diagnostics[0].Location.SourceSpan; var actions = new List <CodeAction>(); var codeActionRegistration = new Action <CodeAction, ImmutableArray <Diagnostic> >( (a, _) => { actions.Add(a); }); var fix = new FindOperationsWithIncorrectReturnTypeResolveCorrectTypeCodeFix(); var codeFixContext = new CodeFixContext(document, diagnostics[0], codeActionRegistration, new CancellationToken(false)); await fix.RegisterCodeFixesAsync(codeFixContext); Assert.AreEqual(1, actions.Count, nameof(actions.Count)); await TestHelpers.VerifyActionAsync(actions, FindOperationsWithIncorrectReturnTypeResolveCorrectTypeCodeFixConstants.ChangeReturnTypeToTaskDescription, document, tree, new[] { "using System.Threading.Tasks;", "Task" }); }
public void VerifyGetFixableDiagnosticIds() { var fix = new FindOperationsWithIncorrectReturnTypeResolveCorrectTypeCodeFix(); var ids = fix.FixableDiagnosticIds.ToList(); Assert.AreEqual(1, ids.Count, nameof(ids.Count)); Assert.AreEqual(ids[0], Constants.AnalyzerIdentifiers.FindOperationsWithIncorrectReturnTypes, nameof(Constants.AnalyzerIdentifiers.FindOperationsWithIncorrectReturnTypes)); }
public async Task VerifyGetFixesWhenChangingToTaskAndUsingDoesNotExist() { var code = @"using Csla; public class A : BusinessBase<A> { [Fetch] public async string FetchAsync() { } }"; var document = TestHelpers.Create(code); var tree = await document.GetSyntaxTreeAsync(); var diagnostics = await TestHelpers.GetDiagnosticsAsync(code, new FindOperationsWithIncorrectReturnTypesAnalyzer()); var sourceSpan = diagnostics[0].Location.SourceSpan; var actions = new List <CodeAction>(); var codeActionRegistration = new Action <CodeAction, ImmutableArray <Diagnostic> >( (a, _) => { actions.Add(a); }); var fix = new FindOperationsWithIncorrectReturnTypeResolveCorrectTypeCodeFix(); var codeFixContext = new CodeFixContext(document, diagnostics[0], codeActionRegistration, new CancellationToken(false)); await fix.RegisterCodeFixesAsync(codeFixContext); Assert.AreEqual(1, actions.Count, nameof(actions.Count)); await TestHelpers.VerifyChangesAsync(actions, FindOperationsWithIncorrectReturnTypeResolveCorrectTypeCodeFixConstants.ChangeReturnTypeToTaskDescription, document, (model, newRoot) => { Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType <UsingDirectiveSyntax>().Any( _ => _.Name.GetText().ToString() == "System.Threading.Tasks")); var classNode = newRoot.DescendantNodes(_ => true).OfType <ClassDeclarationSyntax>().Single(); var classSymbol = model.GetDeclaredSymbol(classNode) as INamedTypeSymbol; var methodSymbol = classSymbol.GetMembers().OfType <IMethodSymbol>().Single(_ => _.Name == "FetchAsync"); Assert.AreEqual("Task", methodSymbol.ReturnType.Name); }); }