33
44namespace StyleCop . Analyzers . Test . SpecialRules
55{
6- using System . Collections . Generic ;
76 using System . Threading ;
87 using System . Threading . Tasks ;
98 using Microsoft . CodeAnalysis ;
10- using Microsoft . CodeAnalysis . Diagnostics ;
119 using StyleCop . Analyzers . SpecialRules ;
1210 using TestHelper ;
1311 using Xunit ;
12+ using static StyleCop . Analyzers . Test . Verifiers . StyleCopDiagnosticVerifier < StyleCop . Analyzers . SpecialRules . SA0001XmlCommentAnalysisDisabled > ;
1413
1514 /// <summary>
1615 /// Unit tests for <see cref="SA0001XmlCommentAnalysisDisabled"/>.
1716 /// </summary>
18- public class SA0001UnitTests : DiagnosticVerifier
17+ public class SA0001UnitTests
1918 {
20- private DocumentationMode documentationMode ;
21-
2219 [ Theory ]
2320 [ InlineData ( DocumentationMode . Parse ) ]
2421 [ InlineData ( DocumentationMode . Diagnose ) ]
@@ -29,8 +26,18 @@ public async Task TestEnabledDocumentationModesAsync(DocumentationMode documenta
2926}
3027" ;
3128
32- this . documentationMode = documentationMode ;
33- await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
29+ await new CSharpTest
30+ {
31+ TestCode = testCode ,
32+ SolutionTransforms =
33+ {
34+ ( solution , projectId ) =>
35+ {
36+ var project = solution . GetProject ( projectId ) ;
37+ return solution . WithProjectParseOptions ( projectId , project . ParseOptions . WithDocumentationMode ( documentationMode ) ) ;
38+ } ,
39+ } ,
40+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
3441 }
3542
3643 [ Theory ]
@@ -43,24 +50,21 @@ public async Task TestDisabledDocumentationModesAsync(DocumentationMode document
4350" ;
4451
4552 // This diagnostic is reported without a location
46- DiagnosticResult expected = this . CSharpDiagnostic ( ) ;
47-
48- this . documentationMode = documentationMode ;
49- await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
50- }
51-
52- /// <inheritdoc/>
53- protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
54- {
55- yield return new SA0001XmlCommentAnalysisDisabled ( ) ;
56- }
57-
58- protected override Solution CreateSolution ( ProjectId projectId , string language )
59- {
60- Solution solution = base . CreateSolution ( projectId , language ) ;
61- Project project = solution . GetProject ( projectId ) ;
53+ DiagnosticResult expected = Diagnostic ( ) ;
6254
63- return solution . WithProjectParseOptions ( projectId , project . ParseOptions . WithDocumentationMode ( this . documentationMode ) ) ;
55+ await new CSharpTest
56+ {
57+ TestCode = testCode ,
58+ ExpectedDiagnostics = { expected } ,
59+ SolutionTransforms =
60+ {
61+ ( solution , projectId ) =>
62+ {
63+ var project = solution . GetProject ( projectId ) ;
64+ return solution . WithProjectParseOptions ( projectId , project . ParseOptions . WithDocumentationMode ( documentationMode ) ) ;
65+ } ,
66+ } ,
67+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
6468 }
6569 }
6670}
0 commit comments