@@ -7,7 +7,9 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
77 using System . Threading ;
88 using System . Threading . Tasks ;
99 using Analyzers . DocumentationRules ;
10+ using Microsoft . CodeAnalysis ;
1011 using Microsoft . CodeAnalysis . Diagnostics ;
12+ using StyleCop . Analyzers . Test . Helpers ;
1113 using TestHelper ;
1214 using Xunit ;
1315
@@ -146,6 +148,89 @@ public async Task TestPartialTypesWithContentDocumentationAsync(string p)
146148 await this . VerifyCSharpDiagnosticAsync ( testCode . Replace ( "##" , p ) , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
147149 }
148150
151+ /// <summary>
152+ /// Verifies that a generic partial type with included documentation will work.
153+ /// </summary>
154+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
155+ [ Fact ]
156+ public async Task TestGenericPartialTypeWithIncludedDocumentationAsync ( )
157+ {
158+ var testCode = @"
159+ /// <include file='ClassWithTypeparamDoc.xml' path='/TestClass/*'/>
160+ public partial class TestClass<T>
161+ {
162+ }
163+ " ;
164+
165+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
166+ }
167+
168+ /// <summary>
169+ /// Verifies that a generic partial type without a typeparam in included documentation will flag.
170+ /// </summary>
171+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
172+ [ Fact ]
173+ public async Task TestGenericPartialTypeWithoutTypeparamInIncludedDocumentationAsync ( )
174+ {
175+ var testCode = @"
176+ /// <include file='ClassWithoutTypeparamDoc.xml' path='/TestClass/*'/>
177+ public partial class TestClass<T>
178+ {
179+ }
180+ " ;
181+
182+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 3 , 32 ) . WithArguments ( "T" ) ;
183+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
184+ }
185+
186+ /// <summary>
187+ /// Verifies that a generic partial type with <inheritdoc> in included documentation will work.
188+ /// </summary>
189+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
190+ [ Fact ]
191+ public async Task TestGenericPartialTypeWithInheritdocInIncludedDocumentationAsync ( )
192+ {
193+ var testCode = @"
194+ /// <include file='ClassWithIneheritdoc.xml' path='/TestClass/*'/>
195+ public partial class TestClass<T>
196+ {
197+ }
198+ " ;
199+
200+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
201+ }
202+
203+ protected override Project ApplyCompilationOptions ( Project project )
204+ {
205+ var resolver = new TestXmlReferenceResolver ( ) ;
206+
207+ string contentClassWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
208+ <TestClass>
209+ <summary>Test class</summary>
210+ <typeparam name=""T"">Param 1</typeparam>
211+ </TestClass>
212+ " ;
213+ resolver . XmlReferences . Add ( "ClassWithTypeparamDoc.xml" , contentClassWithTypeparamDoc ) ;
214+
215+ string contentClassWithoutTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
216+ <TestClass>
217+ <summary>Test class</summary>
218+ </TestClass>
219+ " ;
220+ resolver . XmlReferences . Add ( "ClassWithoutTypeparamDoc.xml" , contentClassWithoutTypeparamDoc ) ;
221+
222+ string contentClassInheritdoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
223+ <TestClass>
224+ <inheritdoc/>
225+ </TestClass>
226+ " ;
227+ resolver . XmlReferences . Add ( "ClassWithIneheritdoc.xml" , contentClassInheritdoc ) ;
228+
229+ project = base . ApplyCompilationOptions ( project ) ;
230+ project = project . WithCompilationOptions ( project . CompilationOptions . WithXmlReferenceResolver ( resolver ) ) ;
231+ return project ;
232+ }
233+
149234 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
150235 {
151236 yield return new SA1619GenericTypeParametersMustBeDocumentedPartialClass ( ) ;
0 commit comments