5using Microsoft.VisualStudio.TestTools.UnitTesting;
7using System.Collections.Generic;
8using System.Collections.Immutable;
10using System.Threading;
11using System.Threading.Tasks;
22 var ids = fix.FixableDiagnosticIds.ToList();
24 Assert.AreEqual(1, ids.Count, nameof(ids.Count));
25 Assert.AreEqual(ids[0], Constants.AnalyzerIdentifiers.IsBusinessObjectSerializable,
26 nameof(Constants.AnalyzerIdentifiers.IsBusinessObjectSerializable));
36public class A : BusinessBase<A>
39 public void Fetch() { }
41 var document = TestHelpers.Create(code);
42 var tree = await document.GetSyntaxTreeAsync();
44 var sourceSpan = diagnostics[0].Location.SourceSpan;
46 var actions =
new List<CodeAction>();
47 var codeActionRegistration =
new Action<CodeAction, ImmutableArray<Diagnostic>>(
48 (a, _) => { actions.Add(a); });
51 var codeFixContext =
new CodeFixContext(document, diagnostics[0],
52 codeActionRegistration,
new CancellationToken(
false));
53 await fix.RegisterCodeFixesAsync(codeFixContext);
55 Assert.AreEqual(1, actions.Count, nameof(actions.Count));
57 await TestHelpers.VerifyChangesAsync(actions,
58 IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableDescription, document,
61 Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType<AttributeSyntax>().Any(_ => _.Name.ToString() ==
"Serializable"));
71public class A : BusinessBase<A>
74 public void Fetch() { }
76 var document = TestHelpers.Create(code);
77 var tree = await document.GetSyntaxTreeAsync();
79 var sourceSpan = diagnostics[0].Location.SourceSpan;
81 var actions =
new List<CodeAction>();
82 var codeActionRegistration =
new Action<CodeAction, ImmutableArray<Diagnostic>>(
83 (a, _) => { actions.Add(a); });
86 var codeFixContext =
new CodeFixContext(document, diagnostics[0],
87 codeActionRegistration,
new CancellationToken(
false));
88 await fix.RegisterCodeFixesAsync(codeFixContext);
90 Assert.AreEqual(1, actions.Count, nameof(actions.Count));
92 await TestHelpers.VerifyChangesAsync(actions,
93 IsBusinessObjectSerializableMakeSerializableCodeFixConstants.AddSerializableAndUsingDescription, document,
96 Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType<UsingDirectiveSyntax>().Any(
97 _ => _.Name.GetText().ToString() ==
"System"));
98 Assert.IsTrue(newRoot.DescendantNodes(_ => true).OfType<AttributeSyntax>().Any(_ => _.Name.ToString() ==
"Serializable"));
void VerifyGetFixableDiagnosticIds()
async Task VerifyGetFixesWhenUsingSystemExists()
async Task VerifyGetFixesWhenUsingSystemDoesNotExists()