@@ -6,7 +6,6 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
66 using System . Collections . Generic ;
77 using System . Threading ;
88 using System . Threading . Tasks ;
9- using Microsoft . CodeAnalysis ;
109 using Microsoft . CodeAnalysis . Diagnostics ;
1110 using StyleCop . Analyzers . DocumentationRules ;
1211 using TestHelper ;
@@ -17,6 +16,8 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1716 /// </summary>
1817 public class SA1600UnitTests : DiagnosticVerifier
1918 {
19+ private string currentTestSettings ;
20+
2021 [ Theory ]
2122 [ InlineData ( "public string TestMember;" , 15 ) ]
2223 [ InlineData ( "public string TestMember { get; set; }" , 15 ) ]
@@ -189,6 +190,42 @@ public async Task TestFieldWithoutDocumentationAsync()
189190 await this . TestFieldDeclarationDocumentationAsync ( "internal" , true , false ) . ConfigureAwait ( false ) ;
190191 await this . TestFieldDeclarationDocumentationAsync ( "protected internal" , true , false ) . ConfigureAwait ( false ) ;
191192 await this . TestFieldDeclarationDocumentationAsync ( "public" , true , false ) . ConfigureAwait ( false ) ;
193+
194+ // Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
195+ this . currentTestSettings = @"
196+ {
197+ ""settings"": {
198+ ""documentationRules"": {
199+ ""documentPrivateElements"": true
200+ }
201+ }
202+ }
203+ " ;
204+
205+ await this . TestFieldDeclarationDocumentationAsync ( string . Empty , false , false ) . ConfigureAwait ( false ) ;
206+ await this . TestFieldDeclarationDocumentationAsync ( "private" , false , false ) . ConfigureAwait ( false ) ;
207+ await this . TestFieldDeclarationDocumentationAsync ( "protected" , true , false ) . ConfigureAwait ( false ) ;
208+ await this . TestFieldDeclarationDocumentationAsync ( "internal" , true , false ) . ConfigureAwait ( false ) ;
209+ await this . TestFieldDeclarationDocumentationAsync ( "protected internal" , true , false ) . ConfigureAwait ( false ) ;
210+ await this . TestFieldDeclarationDocumentationAsync ( "public" , true , false ) . ConfigureAwait ( false ) ;
211+
212+ // Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
213+ this . currentTestSettings = @"
214+ {
215+ ""settings"": {
216+ ""documentationRules"": {
217+ ""documentPrivateFields"": true
218+ }
219+ }
220+ }
221+ " ;
222+
223+ await this . TestFieldDeclarationDocumentationAsync ( string . Empty , true , false ) . ConfigureAwait ( false ) ;
224+ await this . TestFieldDeclarationDocumentationAsync ( "private" , true , false ) . ConfigureAwait ( false ) ;
225+ await this . TestFieldDeclarationDocumentationAsync ( "protected" , true , false ) . ConfigureAwait ( false ) ;
226+ await this . TestFieldDeclarationDocumentationAsync ( "internal" , true , false ) . ConfigureAwait ( false ) ;
227+ await this . TestFieldDeclarationDocumentationAsync ( "protected internal" , true , false ) . ConfigureAwait ( false ) ;
228+ await this . TestFieldDeclarationDocumentationAsync ( "public" , true , false ) . ConfigureAwait ( false ) ;
192229 }
193230
194231 [ Fact ]
@@ -200,6 +237,42 @@ public async Task TestFieldWithDocumentationAsync()
200237 await this . TestFieldDeclarationDocumentationAsync ( "internal" , false , true ) . ConfigureAwait ( false ) ;
201238 await this . TestFieldDeclarationDocumentationAsync ( "protected internal" , false , true ) . ConfigureAwait ( false ) ;
202239 await this . TestFieldDeclarationDocumentationAsync ( "public" , false , true ) . ConfigureAwait ( false ) ;
240+
241+ // Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
242+ this . currentTestSettings = @"
243+ {
244+ ""settings"": {
245+ ""documentationRules"": {
246+ ""documentPrivateElements"": true
247+ }
248+ }
249+ }
250+ " ;
251+
252+ await this . TestFieldDeclarationDocumentationAsync ( string . Empty , false , true ) . ConfigureAwait ( false ) ;
253+ await this . TestFieldDeclarationDocumentationAsync ( "private" , false , true ) . ConfigureAwait ( false ) ;
254+ await this . TestFieldDeclarationDocumentationAsync ( "protected" , false , true ) . ConfigureAwait ( false ) ;
255+ await this . TestFieldDeclarationDocumentationAsync ( "internal" , false , true ) . ConfigureAwait ( false ) ;
256+ await this . TestFieldDeclarationDocumentationAsync ( "protected internal" , false , true ) . ConfigureAwait ( false ) ;
257+ await this . TestFieldDeclarationDocumentationAsync ( "public" , false , true ) . ConfigureAwait ( false ) ;
258+
259+ // Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
260+ this . currentTestSettings = @"
261+ {
262+ ""settings"": {
263+ ""documentationRules"": {
264+ ""documentPrivateFields"": true
265+ }
266+ }
267+ }
268+ " ;
269+
270+ await this . TestFieldDeclarationDocumentationAsync ( string . Empty , false , true ) . ConfigureAwait ( false ) ;
271+ await this . TestFieldDeclarationDocumentationAsync ( "private" , false , true ) . ConfigureAwait ( false ) ;
272+ await this . TestFieldDeclarationDocumentationAsync ( "protected" , false , true ) . ConfigureAwait ( false ) ;
273+ await this . TestFieldDeclarationDocumentationAsync ( "internal" , false , true ) . ConfigureAwait ( false ) ;
274+ await this . TestFieldDeclarationDocumentationAsync ( "protected internal" , false , true ) . ConfigureAwait ( false ) ;
275+ await this . TestFieldDeclarationDocumentationAsync ( "public" , false , true ) . ConfigureAwait ( false ) ;
203276 }
204277
205278 [ Fact ]
@@ -430,6 +503,11 @@ public void SomeMethod() { }
430503 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
431504 }
432505
506+ protected override string GetSettings ( )
507+ {
508+ return this . currentTestSettings ?? base . GetSettings ( ) ;
509+ }
510+
433511 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
434512 {
435513 yield return new SA1600ElementsMustBeDocumented ( ) ;
0 commit comments