@@ -7,12 +7,14 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
77 using System . Threading ;
88 using System . Threading . Tasks ;
99 using Analyzers . DocumentationRules ;
10+ using Helpers ;
11+ using Microsoft . CodeAnalysis ;
1012 using Microsoft . CodeAnalysis . Diagnostics ;
1113 using TestHelper ;
1214 using Xunit ;
1315
1416 /// <summary>
15- /// This class contains unit tests for <see cref="SA1622GenericTypeParameterDocumentationMustHaveText"/> .
17+ /// This class contains unit tests for SA1622 .
1618 /// </summary>
1719 public class SA1622UnitTests : DiagnosticVerifier
1820 {
@@ -217,6 +219,142 @@ public async Task TestTypesWithEmptyParams2Async(string declaration)
217219 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "$$" , declaration ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
218220 }
219221
222+ /// <summary>
223+ /// Verifies that a class with valid typeparameter tags in included documentation will not produce diagnostics.
224+ /// </summary>
225+ /// <param name="typeText">The type specific test text.</param>
226+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
227+ [ Theory ]
228+ [ MemberData ( nameof ( Types ) ) ]
229+ public async Task TestTypesWithValidTypeparameterInIncludedDocumentationAsync ( string typeText )
230+ {
231+ var testCode = @"
232+ /// <include file='TypeWithTypeparamsDoc.xml' path='/Foo/*'/>
233+ public ##
234+ " ;
235+
236+ await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "##" , typeText ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
237+ }
238+
239+ /// <summary>
240+ /// Verifies that a class with empty typeparameter tags in included documentation will produce diagnostics.
241+ /// </summary>
242+ /// <param name="typeText">The type specific test text.</param>
243+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
244+ [ Theory ]
245+ [ MemberData ( nameof ( Types ) ) ]
246+ public async Task TestTypesWithEmptyTypeparameterInIncludedDocumentationAsync ( string typeText )
247+ {
248+ var testCode = @"
249+ /// <include file='TypeWithEmptyTypeparamsDoc.xml' path='/Foo/*'/>
250+ public ##
251+ " ;
252+ DiagnosticResult [ ] expected =
253+ {
254+ this . CSharpDiagnostic ( GenericTypeParameterDocumentationAnalyzer . SA1622Descriptor ) . WithLocation ( 2 , 5 ) ,
255+ this . CSharpDiagnostic ( GenericTypeParameterDocumentationAnalyzer . SA1622Descriptor ) . WithLocation ( 2 , 5 ) ,
256+ } ;
257+
258+ await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "##" , typeText ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
259+ }
260+
261+ /// <summary>
262+ /// Verifies that a method with valid typeparameter tags in the included documentation will produce no diagnostics.
263+ /// </summary>
264+ /// <param name="memberText">The member declaration text that will be used.</param>
265+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
266+ [ Theory ]
267+ [ MemberData ( nameof ( Members ) ) ]
268+ public async Task TestMemberWithValidTypeparameterInIncludedDocumentationAsync ( string memberText )
269+ {
270+ var testCode = @"
271+ /// <summary>Test class</summary>
272+ public class TestClass
273+ {
274+ /// <include file='MethodWithTypeparamsDoc.xml' path='/TestClass/Foo/*'/>
275+ public ##
276+ }
277+ " ;
278+
279+ await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "##" , memberText ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
280+ }
281+
282+ /// <summary>
283+ /// Verifies that a method with empty typeparameter tags in the included documentation will produce no diagnostics.
284+ /// </summary>
285+ /// <param name="memberText">The member declaration text that will be used.</param>
286+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
287+ [ Theory ]
288+ [ MemberData ( nameof ( Members ) ) ]
289+ public async Task TestMemberWithEmptyTypeparameterInIncludedDocumentationAsync ( string memberText )
290+ {
291+ var testCode = @"
292+ /// <summary>Test class</summary>
293+ public class TestClass
294+ {
295+ /// <include file='MethodWithEmptyTypeparamsDoc.xml' path='/TestClass/Foo/*'/>
296+ public ##
297+ }
298+ " ;
299+
300+ DiagnosticResult [ ] expected =
301+ {
302+ this . CSharpDiagnostic ( GenericTypeParameterDocumentationAnalyzer . SA1622Descriptor ) . WithLocation ( 5 , 9 ) ,
303+ this . CSharpDiagnostic ( GenericTypeParameterDocumentationAnalyzer . SA1622Descriptor ) . WithLocation ( 5 , 9 ) ,
304+ } ;
305+
306+ await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "##" , memberText ) , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
307+ }
308+
309+ protected override Project ApplyCompilationOptions ( Project project )
310+ {
311+ var resolver = new TestXmlReferenceResolver ( ) ;
312+
313+ string contentTypeWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
314+ <Foo>
315+ <summary>Test class</summary>
316+ <typeparam name=""Ta"">Param 1</typeparam>
317+ <typeparam name=""Tb"">Param 2</typeparam>
318+ </Foo>
319+ " ;
320+ resolver . XmlReferences . Add ( "TypeWithTypeparamsDoc.xml" , contentTypeWithTypeparamDoc ) ;
321+
322+ string contentTypeWithEmptyTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
323+ <Foo>
324+ <summary>Test class</summary>
325+ <typeparam name=""Ta""></typeparam>
326+ <typeparam name=""Tb""/>
327+ </Foo>
328+ " ;
329+ resolver . XmlReferences . Add ( "TypeWithEmptyTypeparamsDoc.xml" , contentTypeWithEmptyTypeparamDoc ) ;
330+
331+ string contentMethodWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
332+ <TestClass>
333+ <Foo>
334+ <summary>Test class</summary>
335+ <typeparam name=""Ta"">Param 1</typeparam>
336+ <typeparam name=""Tb"">Param 2</typeparam>
337+ </Foo>
338+ </TestClass>
339+ " ;
340+ resolver . XmlReferences . Add ( "MethodWithTypeparamsDoc.xml" , contentMethodWithTypeparamDoc ) ;
341+
342+ string contentMethodWithEmptyTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
343+ <TestClass>
344+ <Foo>
345+ <summary>Test class</summary>
346+ <typeparam name=""Ta""/>
347+ <typeparam name=""Tb""></typeparam>
348+ </Foo>
349+ </TestClass>
350+ " ;
351+ resolver . XmlReferences . Add ( "MethodWithEmptyTypeparamsDoc.xml" , contentMethodWithEmptyTypeparamDoc ) ;
352+
353+ project = base . ApplyCompilationOptions ( project ) ;
354+ project = project . WithCompilationOptions ( project . CompilationOptions . WithXmlReferenceResolver ( resolver ) ) ;
355+ return project ;
356+ }
357+
220358 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
221359 {
222360 yield return new GenericTypeParameterDocumentationAnalyzer ( ) ;
0 commit comments