@@ -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 . CodeFixes ;
1113 using Microsoft . CodeAnalysis . Diagnostics ;
1214 using TestHelper ;
@@ -449,6 +451,193 @@ internal sealed class ##Attribute : System.Attribute { }
449451 await this . VerifyCSharpFixAsync ( testCode . Replace ( "$$" , declaration ) . Replace ( "##" , testAttribute ) , fixedCode . Replace ( "$$" , declaration ) . Replace ( "##" , testAttribute ) , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
450452 }
451453
454+ [ Fact ]
455+ public async Task VerifyMemberIncludedDocumentationNoDocumentationAsync ( )
456+ {
457+ var testCode = @"
458+ /// <summary>
459+ /// Foo
460+ /// </summary>
461+ public class ClassName
462+ {
463+ /// <include file='NoDocumentation.xml' path='/ClassName/Method/*' />
464+ public ClassName Method(string foo, string bar) { return null; }
465+ }" ;
466+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
467+ }
468+
469+ [ Fact ]
470+ public async Task VerifyMemberIncludedDocumentationWithoutReturnsAsync ( )
471+ {
472+ var testCode = @"
473+ /// <summary>
474+ /// Foo
475+ /// </summary>
476+ public class ClassName
477+ {
478+ /// <include file='WithoutReturns.xml' path='/ClassName/Method/*' />
479+ public ClassName Method(string foo, string bar) { return null; }
480+ }" ;
481+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
482+ }
483+
484+ [ Fact ]
485+ public async Task VerifyMemberIncludedDocumentationWithValidReturnsAsync ( )
486+ {
487+ var testCode = @"
488+ /// <summary>
489+ /// Foo
490+ /// </summary>
491+ public class ClassName
492+ {
493+ /// <include file='WithReturns.xml' path='/ClassName/Method/*' />
494+ public ClassName Method(string foo, string bar) { return null; }
495+ }" ;
496+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
497+ }
498+
499+ [ Fact ]
500+ public async Task VerifyMemberIncludedDocumentationWithEmptyReturnsAsync ( )
501+ {
502+ var testCode = @"
503+ /// <summary>
504+ /// Foo
505+ /// </summary>
506+ public class ClassName
507+ {
508+ /// <include file='WithEmptyReturns.xml' path='/ClassName/Method/*' />
509+ public ClassName Method(string foo, string bar) { return null; }
510+ }" ;
511+
512+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 8 , 22 ) ;
513+
514+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
515+
516+ // The code fix does not alter this case.
517+ await this . VerifyCSharpFixAsync ( testCode , testCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
518+ }
519+
520+ [ Fact ]
521+ public async Task VerifyMemberIncludedDocumentationWithEmptyReturns2Async ( )
522+ {
523+ var testCode = @"
524+ /// <summary>
525+ /// Foo
526+ /// </summary>
527+ public class ClassName
528+ {
529+ /// <include file='WithEmptyReturns2.xml' path='/ClassName/Method/*' />
530+ public ClassName Method(string foo, string bar) { return null; }
531+ }" ;
532+
533+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 8 , 22 ) ;
534+
535+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
536+
537+ // The code fix does not alter this case.
538+ await this . VerifyCSharpFixAsync ( testCode , testCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
539+ }
540+
541+ [ Fact ]
542+ public async Task VerifyMemberIncludedDocumentationWithEmptyReturns3Async ( )
543+ {
544+ var testCode = @"
545+ /// <summary>
546+ /// Foo
547+ /// </summary>
548+ public class ClassName
549+ {
550+ /// <include file='WithEmptyReturns3.xml' path='/ClassName/Method/*' />
551+ public ClassName Method(string foo, string bar) { return null; }
552+ }" ;
553+
554+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 8 , 22 ) ;
555+
556+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
557+
558+ // The code fix does not alter this case.
559+ await this . VerifyCSharpFixAsync ( testCode , testCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
560+ }
561+
562+ /// <inheritdoc/>
563+ protected override Project ApplyCompilationOptions ( Project project )
564+ {
565+ var resolver = new TestXmlReferenceResolver ( ) ;
566+
567+ string contentWithoutDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
568+ <ClassName>
569+ <Method>
570+ </Method>
571+ </ClassName>
572+ " ;
573+ resolver . XmlReferences . Add ( "NoDocumentation.xml" , contentWithoutDocumentation ) ;
574+
575+ string contentWithoutReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
576+ <ClassName>
577+ <Method>
578+ <summary>
579+ Foo
580+ </summary>
581+ </Method>
582+ </ClassName>
583+ " ;
584+ resolver . XmlReferences . Add ( "WithoutReturns.xml" , contentWithoutReturns ) ;
585+
586+ string contentWithReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
587+ <ClassName>
588+ <Method>
589+ <summary>
590+ Foo
591+ </summary>
592+ <returns>Test</returns>
593+ </Method>
594+ </ClassName>
595+ " ;
596+ resolver . XmlReferences . Add ( "WithReturns.xml" , contentWithReturns ) ;
597+
598+ string contentWithEmptyReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
599+ <ClassName>
600+ <Method>
601+ <summary>
602+ Foo
603+ </summary>
604+ <returns>
605+
606+ </returns>
607+ </Method>
608+ </ClassName>
609+ " ;
610+ resolver . XmlReferences . Add ( "WithEmptyReturns.xml" , contentWithEmptyReturns ) ;
611+
612+ string contentWithEmptyReturns2 = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
613+ <ClassName>
614+ <Method>
615+ <summary>
616+ Foo
617+ </summary>
618+ <returns />
619+ </Method>
620+ </ClassName>
621+ " ;
622+ resolver . XmlReferences . Add ( "WithEmptyReturns2.xml" , contentWithEmptyReturns2 ) ;
623+
624+ string contentWithEmptyReturns3 = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
625+ <ClassName>
626+ <Method>
627+ <summary>
628+ Foo
629+ </summary>
630+ <returns></returns>
631+ </Method>
632+ </ClassName>
633+ " ;
634+ resolver . XmlReferences . Add ( "WithEmptyReturns3.xml" , contentWithEmptyReturns3 ) ;
635+
636+ project = base . ApplyCompilationOptions ( project ) ;
637+ project = project . WithCompilationOptions ( project . CompilationOptions . WithXmlReferenceResolver ( resolver ) ) ;
638+ return project ;
639+ }
640+
452641 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
453642 {
454643 yield return new SA1616ElementReturnValueDocumentationMustHaveText ( ) ;
0 commit comments