@@ -18,6 +18,8 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1818 /// </summary>
1919 public class SA1612UnitTests : DiagnosticVerifier
2020 {
21+ private string currentTestSettings ;
22+
2123 public static IEnumerable < object [ ] > Declarations
2224 {
2325 get
@@ -81,6 +83,68 @@ public class ClassName
8183 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
8284 }
8385
86+ [ Theory ]
87+ [ MemberData ( nameof ( Declarations ) ) ]
88+ [ WorkItem ( 2452 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2452" ) ]
89+ public async Task TestMemberWithMissingNotRequiredParamAsync ( string declaration )
90+ {
91+ var testCode = @"
92+ /// <summary>
93+ /// Foo
94+ /// </summary>
95+ public class ClassName
96+ {
97+ /// <summary>
98+ /// Foo
99+ /// </summary>
100+ ///<param name=""foo"">Test</param>
101+ ///<param name=""new"">Test</param>
102+ $$
103+ }" ;
104+
105+ this . currentTestSettings = @"
106+ {
107+ ""settings"": {
108+ ""documentationRules"": {
109+ ""documentExposedElements"": false
110+ }
111+ }
112+ }
113+ " ;
114+ await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
115+ }
116+
117+ [ Theory ]
118+ [ MemberData ( nameof ( Declarations ) ) ]
119+ [ WorkItem ( 2452 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2452" ) ]
120+ public async Task TestMemberWithMissingNotRequiredReorderedParamAsync ( string declaration )
121+ {
122+ var testCode = @"
123+ /// <summary>
124+ /// Foo
125+ /// </summary>
126+ public class ClassName
127+ {
128+ /// <summary>
129+ /// Foo
130+ /// </summary>
131+ ///<param name=""new"">Test</param>
132+ ///<param name=""foo"">Test</param>
133+ $$
134+ }" ;
135+
136+ var diagnostic = this . CSharpDiagnostic ( )
137+ . WithMessageFormat ( "The parameter documentation for '{0}' should be at position {1}." ) ;
138+
139+ var expected = new [ ]
140+ {
141+ diagnostic . WithLocation ( 10 , 21 ) . WithArguments ( "new" , 3 ) ,
142+ diagnostic . WithLocation ( 11 , 21 ) . WithArguments ( "foo" , 1 ) ,
143+ } ;
144+
145+ await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
146+ }
147+
84148 [ Theory ]
85149 [ MemberData ( nameof ( Declarations ) ) ]
86150 public async Task TestMemberWithInvalidParamsAsync ( string declaration )
@@ -301,6 +365,27 @@ public class ClassName
301365 } ;
302366
303367 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
368+
369+ // This is even reported if the documentation is not required, except that no warning is reported for the
370+ // first param element (which is actually the last parameter) since it would otherwise be allowed to skip
371+ // the documentation for the first two parameters.
372+ this . currentTestSettings = @"
373+ {
374+ ""settings"": {
375+ ""documentationRules"": {
376+ ""documentExposedElements"": false
377+ }
378+ }
379+ }
380+ " ;
381+
382+ expected = new [ ]
383+ {
384+ diagnostic . WithLocation ( 8 , 22 ) . WithArguments ( "bar" , 1 ) ,
385+ diagnostic . WithLocation ( 8 , 22 ) . WithArguments ( "new" , 2 ) ,
386+ } ;
387+
388+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
304389 }
305390
306391 [ Fact ]
@@ -428,6 +513,11 @@ protected override Project ApplyCompilationOptions(Project project)
428513 return project ;
429514 }
430515
516+ protected override string GetSettings ( )
517+ {
518+ return this . currentTestSettings ?? base . GetSettings ( ) ;
519+ }
520+
431521 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
432522 {
433523 yield return new SA1612ElementParameterDocumentationMustMatchElementParameters ( ) ;
0 commit comments