@@ -6,6 +6,8 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
66 using System . Collections . Generic ;
77 using System . Threading ;
88 using System . Threading . Tasks ;
9+ using Helpers ;
10+ using Microsoft . CodeAnalysis ;
911 using Microsoft . CodeAnalysis . CodeFixes ;
1012 using Microsoft . CodeAnalysis . Diagnostics ;
1113 using StyleCop . Analyzers . DocumentationRules ;
@@ -280,6 +282,141 @@ public class ClassName
280282 await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
281283 }
282284
285+ /// <summary>
286+ /// Verifies that included property documentation will be accepted.
287+ /// </summary>
288+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
289+ [ Fact ]
290+ public async Task TestPropertyWithValidIncludeAsync ( )
291+ {
292+ var testCode = @"
293+ public class ClassName
294+ {
295+ /// <include file='PropertyWithValue.xml' path='/ClassName/Property/*'/>
296+ public int Property
297+ {
298+ get;
299+ }
300+ }" ;
301+
302+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
303+ }
304+
305+ /// <summary>
306+ /// Verifies that included property documentation without a value tag will be accepted (this is handled by SA1609).
307+ /// </summary>
308+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
309+ [ Fact ]
310+ public async Task TestPropertyWithoutValueInIncludeAsync ( )
311+ {
312+ var testCode = @"
313+ public class ClassName
314+ {
315+ /// <include file='PropertyWithoutValue.xml' path='/ClassName/Property/*'/>
316+ public int Property
317+ {
318+ get;
319+ }
320+ }" ;
321+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
322+ }
323+
324+ /// <summary>
325+ /// Verifies that included property documentation with an empty value tag will be flagged.
326+ /// </summary>
327+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
328+ [ Fact ]
329+ public async Task TestPropertyWithEmptyValueInIncludeAsync ( )
330+ {
331+ var testCode = @"
332+ public class ClassName
333+ {
334+ /// <include file='PropertyWithEmptyValue.xml' path='/ClassName/Property/*'/>
335+ public int Property
336+ {
337+ get;
338+ }
339+ }" ;
340+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 5 , 16 ) ;
341+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
342+ }
343+
344+ /// <summary>
345+ /// Verifies that included property documentation containing >inheritdoc/< will be accepted.
346+ /// </summary>
347+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
348+ [ Fact ]
349+ public async Task TestPropertyWithInheritdocInIncludeAsync ( )
350+ {
351+ var testCode = @"
352+ public interface ITestInterface
353+ {
354+ /// <summary>
355+ /// Gets the test property value.
356+ /// </summary>
357+ /// <value>Test number.</value>
358+ int Property { get; }
359+ }
360+
361+ public class ClassName : ITestInterface
362+ {
363+ /// <include file='PropertyWithInheritdoc.xml' path='/ClassName/Property/*'/>
364+ public int Property
365+ {
366+ get;
367+ }
368+ }" ;
369+
370+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
371+ }
372+
373+ protected override Project ApplyCompilationOptions ( Project project )
374+ {
375+ var resolver = new TestXmlReferenceResolver ( ) ;
376+
377+ string contentWithValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
378+ <ClassName>
379+ <Property>
380+ <summary>Foo</summary>
381+ <value>Bar</value>
382+ </Property>
383+ </ClassName>
384+ " ;
385+ resolver . XmlReferences . Add ( "PropertyWithValue.xml" , contentWithValue ) ;
386+
387+ string contentWithoutValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
388+ <ClassName>
389+ <Property>
390+ <summary>Foo</summary>
391+ </Property>
392+ </ClassName>
393+ " ;
394+ resolver . XmlReferences . Add ( "PropertyWithoutValue.xml" , contentWithoutValue ) ;
395+
396+ string contentWithEmptyValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
397+ <ClassName>
398+ <Property>
399+ <summary>Foo</summary>
400+ <value> </value>
401+ </Property>
402+ </ClassName>
403+ " ;
404+ resolver . XmlReferences . Add ( "PropertyWithEmptyValue.xml" , contentWithEmptyValue ) ;
405+
406+ string contentWithInheritdocValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
407+ <ClassName>
408+ <Property>
409+ <inheritdoc/>
410+ </Property>
411+ </ClassName>
412+ " ;
413+ resolver . XmlReferences . Add ( "PropertyWithInheritdoc.xml" , contentWithInheritdocValue ) ;
414+
415+ project = base . ApplyCompilationOptions ( project ) ;
416+ project = project . WithCompilationOptions ( project . CompilationOptions . WithXmlReferenceResolver ( resolver ) ) ;
417+ return project ;
418+ }
419+
283420 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
284421 {
285422 yield return new SA1610PropertyDocumentationMustHaveValueText ( ) ;
0 commit comments