6using Microsoft.VisualStudio.TestTools.UnitTesting;
8using System.Collections.Generic;
9using System.Collections.Immutable;
11using System.Threading;
12using System.Threading.Tasks;
23 var ids = fix.FixableDiagnosticIds.ToList();
25 Assert.AreEqual(1, ids.Count, nameof(ids.Count));
26 Assert.AreEqual(ids[0], Constants.AnalyzerIdentifiers.EvaluateManagedBackingFields,
27 nameof(Constants.AnalyzerIdentifiers.EvaluateManagedBackingFields));
36public class A : BusinessBase<A>
38 PropertyInfo<string> DataProperty =
39 RegisterProperty<string>(_ => _.Data);
42 get { return GetProperty(DataProperty); }
43 set { SetProperty(DataProperty, value); }
46 var document = TestHelpers.Create(code);
47 var tree = await document.GetSyntaxTreeAsync();
49 var sourceSpan = diagnostics[0].Location.SourceSpan;
51 var actions =
new List<CodeAction>();
52 var codeActionRegistration =
new Action<CodeAction, ImmutableArray<Diagnostic>>(
53 (a, _) => { actions.Add(a); });
56 var codeFixContext =
new CodeFixContext(document, diagnostics[0],
57 codeActionRegistration,
new CancellationToken(
false));
58 await fix.RegisterCodeFixesAsync(codeFixContext);
60 Assert.AreEqual(1, actions.Count, nameof(actions.Count));
62 await TestHelpers.VerifyChangesAsync(actions,
63 EvaluateManagedBackingFieldsCodeFixConstants.FixManagedBackingFieldDescription, document,
66 var fieldNode = newRoot.DescendantNodes(_ => true).OfType<FieldDeclarationSyntax>().Single().Declaration.Variables[0];
67 var fieldSymbol = model.GetDeclaredSymbol(fieldNode) as IFieldSymbol;
69 Assert.IsTrue(fieldSymbol.DeclaredAccessibility == Accessibility.Public);
70 Assert.IsTrue(fieldSymbol.IsStatic);
71 Assert.IsTrue(fieldSymbol.IsReadOnly);
81public class A : BusinessBase<A>
84 private static readonly PropertyInfo<string> DataProperty = RegisterProperty<string>(_ => _.Data);
87 public string Data => GetProperty(DataProperty);
89 var document = TestHelpers.Create(code);
90 var tree = await document.GetSyntaxTreeAsync();
92 var sourceSpan = diagnostics[0].Location.SourceSpan;
94 var actions =
new List<CodeAction>();
95 var codeActionRegistration =
new Action<CodeAction, ImmutableArray<Diagnostic>>(
96 (a, _) => { actions.Add(a); });
99 var codeFixContext =
new CodeFixContext(document, diagnostics[0],
100 codeActionRegistration,
new CancellationToken(
false));
101 await fix.RegisterCodeFixesAsync(codeFixContext);
103 Assert.AreEqual(1, actions.Count, nameof(actions.Count));
104 await TestHelpers.VerifyChangesAsync(actions,
105 EvaluateManagedBackingFieldsCodeFixConstants.FixManagedBackingFieldDescription, document,
108 var fieldNode = newRoot.DescendantNodes(_ => true).OfType<FieldDeclarationSyntax>().Single().Declaration.Variables[0];
109 var fieldSymbol = model.GetDeclaredSymbol(fieldNode) as IFieldSymbol;
111 Assert.IsTrue(fieldSymbol.DeclaredAccessibility == Accessibility.Public);
112 Assert.IsTrue(fieldSymbol.IsStatic);
113 Assert.IsTrue(fieldSymbol.IsReadOnly);
115 Assert.IsTrue(newRoot.DescendantTrivia(_ => true, true).Any(_ => _.IsKind(SyntaxKind.RegionDirectiveTrivia)));
void VerifyGetFixableDiagnosticIds()
async Task VerifyGetFixes()
async Task VerifyGetFixesWithTrivia()