@@ -7,6 +7,8 @@ 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 ;
@@ -228,6 +230,120 @@ public static explicit operator TestClass(int value)
228230 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
229231 }
230232
233+ /// <summary>
234+ /// Verifies that included documentation with valid documentation does not produce diagnostics.
235+ /// </summary>
236+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
237+ [ Fact ]
238+ public async Task VerifyIncludedDocumentationAsync ( )
239+ {
240+ var testCode = @"
241+ /// <summary>
242+ /// Foo
243+ /// </summary>
244+ public class ClassName
245+ {
246+ /// <include file='WithElementDocumentation.xml' path='/TestClass/TestMethod/*' />
247+ public void TestMethod(string param1, string param2, string param3)
248+ {
249+ }
250+ }" ;
251+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
252+ }
253+
254+ /// <summary>
255+ /// Verifies that included documentation with missing elements produces the expected diagnostics.
256+ /// </summary>
257+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
258+ [ Fact ]
259+ public async Task VerifyIncludedDocumentationMissingElementsAsync ( )
260+ {
261+ var testCode = @"
262+ /// <summary>
263+ /// Foo
264+ /// </summary>
265+ public class ClassName
266+ {
267+ /// <include file='MissingElementDocumentation.xml' path='/TestClass/TestMethod/*' />
268+ public void TestMethod(string param1, string param2, string param3)
269+ {
270+ }
271+ }" ;
272+ DiagnosticResult [ ] expected =
273+ {
274+ this . CSharpDiagnostic ( ) . WithLocation ( 8 , 35 ) . WithArguments ( "param1" ) ,
275+ this . CSharpDiagnostic ( ) . WithLocation ( 8 , 50 ) . WithArguments ( "param2" ) ,
276+ this . CSharpDiagnostic ( ) . WithLocation ( 8 , 65 ) . WithArguments ( "param3" ) ,
277+ } ;
278+
279+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
280+ }
281+
282+ /// <summary>
283+ /// Verifies that included documentation with an <c><inheritdoc></c> tag is ignored.
284+ /// </summary>
285+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
286+ [ Fact ]
287+ public async Task VerifyIncludedInheritedDocumentationAsync ( )
288+ {
289+ var testCode = @"
290+ /// <summary>
291+ /// Foo
292+ /// </summary>
293+ public class ClassName
294+ {
295+ /// <include file='InheritedDocumentation.xml' path='/TestClass/TestMethod/*' />
296+ public void TestMethod(string param1, string param2, string param3)
297+ {
298+ }
299+ }" ;
300+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
301+ }
302+
303+ /// <inheritdoc/>
304+ protected override Project ApplyCompilationOptions ( Project project )
305+ {
306+ var resolver = new TestXmlReferenceResolver ( ) ;
307+
308+ string contentWithoutElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
309+ <TestClass>
310+ <TestMethod>
311+ <summary>
312+ Foo
313+ </summary>
314+ </TestMethod>
315+ </TestClass>
316+ " ;
317+ resolver . XmlReferences . Add ( "MissingElementDocumentation.xml" , contentWithoutElementDocumentation ) ;
318+
319+ string contentWithElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
320+ <TestClass>
321+ <TestMethod>
322+ <summary>
323+ Foo
324+ </summary>
325+ <param name=""param1"">Param 1</param>
326+ <param name=""param2"">Param 2</param>
327+ <param name=""param3"">Param 3</param>
328+ </TestMethod>
329+ </TestClass>
330+ " ;
331+ resolver . XmlReferences . Add ( "WithElementDocumentation.xml" , contentWithElementDocumentation ) ;
332+
333+ string contentWithInheritedDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
334+ <TestClass>
335+ <TestMethod>
336+ <inheritdoc />
337+ </TestMethod>
338+ </TestClass>
339+ " ;
340+ resolver . XmlReferences . Add ( "InheritedDocumentation.xml" , contentWithInheritedDocumentation ) ;
341+
342+ project = base . ApplyCompilationOptions ( project ) ;
343+ project = project . WithCompilationOptions ( project . CompilationOptions . WithXmlReferenceResolver ( resolver ) ) ;
344+ return project ;
345+ }
346+
231347 /// <inheritdoc/>
232348 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
233349 {
0 commit comments