|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp12.DocumentationRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp11.DocumentationRules; |
| 10 | + using Xunit; |
| 11 | + using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1611ElementParametersMustBeDocumented>; |
7 | 12 |
|
8 | 13 | public partial class SA1611CSharp12UnitTests : SA1611CSharp11UnitTests |
9 | 14 | { |
| 15 | + public static TheoryData<string> NonRecordDeclarationKeywords { get; } = new TheoryData<string>() { "class", "struct" }; |
| 16 | + |
| 17 | + [Theory] |
| 18 | + [MemberData(nameof(NonRecordDeclarationKeywords))] |
| 19 | + [WorkItem(3770, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3770")] |
| 20 | + public async Task TestPrimaryConstructorMissingParametersAsync(string keyword) |
| 21 | + { |
| 22 | + var testCode = $@" |
| 23 | +/// <summary> |
| 24 | +/// Type. |
| 25 | +/// </summary> |
| 26 | +public {keyword} C(int {{|#0:param1|}}, string {{|#1:param2|}}) {{ }}"; |
| 27 | + |
| 28 | + DiagnosticResult[] expectedResults = new[] |
| 29 | + { |
| 30 | + Diagnostic().WithLocation(0).WithArguments("param1"), |
| 31 | + Diagnostic().WithLocation(1).WithArguments("param2"), |
| 32 | + }; |
| 33 | + |
| 34 | + await VerifyCSharpDiagnosticAsync(testCode, expectedResults, CancellationToken.None).ConfigureAwait(false); |
| 35 | + } |
| 36 | + |
| 37 | + [Theory] |
| 38 | + [MemberData(nameof(NonRecordDeclarationKeywords))] |
| 39 | + [WorkItem(3770, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3770")] |
| 40 | + public async Task TestPrimaryConstructorPartiallyMissingParametersAsync(string keyword) |
| 41 | + { |
| 42 | + var testCode = $@" |
| 43 | +/// <summary> |
| 44 | +/// Type. |
| 45 | +/// </summary> |
| 46 | +/// <param name=""param1"">Parameter one.</param> |
| 47 | +public {keyword} C(int param1, string {{|#0:param2|}}) {{ }}"; |
| 48 | + |
| 49 | + await VerifyCSharpDiagnosticAsync(testCode, new[] { Diagnostic().WithLocation(0).WithArguments("param2") }, CancellationToken.None).ConfigureAwait(false); |
| 50 | + } |
| 51 | + |
| 52 | + [Theory] |
| 53 | + [MemberData(nameof(NonRecordDeclarationKeywords))] |
| 54 | + [WorkItem(3770, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3770")] |
| 55 | + public async Task TestPrimaryConstructorNoMissingParametersAsync(string keyword) |
| 56 | + { |
| 57 | + var testCode = $@" |
| 58 | +/// <summary> |
| 59 | +/// Type. |
| 60 | +/// </summary> |
| 61 | +/// <param name=""param1"">Parameter one.</param> |
| 62 | +/// <param name=""param2"">Parameter two.</param> |
| 63 | +public {keyword} C(int param1, string param2) {{ }}"; |
| 64 | + |
| 65 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 66 | + } |
| 67 | + |
| 68 | + [Theory] |
| 69 | + [MemberData(nameof(NonRecordDeclarationKeywords))] |
| 70 | + [WorkItem(3770, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3770")] |
| 71 | + public async Task TestPrimaryConstructorIncludeMissingParametersAsync(string keyword) |
| 72 | + { |
| 73 | + var testCode = $@" |
| 74 | +/// <include file='MissingClassDocumentation.xml' path='/TestType/*' /> |
| 75 | +public {keyword} C(int {{|#0:param1|}}, string {{|#1:param2|}}, bool {{|#2:param3|}}) {{ }}"; |
| 76 | + |
| 77 | + DiagnosticResult[] expectedResults = new[] |
| 78 | + { |
| 79 | + Diagnostic().WithLocation(0).WithArguments("param1"), |
| 80 | + Diagnostic().WithLocation(1).WithArguments("param2"), |
| 81 | + Diagnostic().WithLocation(2).WithArguments("param3"), |
| 82 | + }; |
| 83 | + |
| 84 | + await VerifyCSharpDiagnosticAsync(testCode, expectedResults, CancellationToken.None).ConfigureAwait(false); |
| 85 | + } |
| 86 | + |
| 87 | + [Theory] |
| 88 | + [MemberData(nameof(NonRecordDeclarationKeywords))] |
| 89 | + [WorkItem(3770, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3770")] |
| 90 | + public async Task TestPrimaryConstructorIncludePartiallyMissingParametersAsync(string keyword) |
| 91 | + { |
| 92 | + var testCode = $@" |
| 93 | +/// <include file='WithPartialClassDocumentation.xml' path='/TestType/*' /> |
| 94 | +public {keyword} C(int {{|#0:param1|}}, string param2, bool param3) {{ }}"; |
| 95 | + |
| 96 | + await VerifyCSharpDiagnosticAsync(testCode, new[] { Diagnostic().WithLocation(0).WithArguments("param1") }, CancellationToken.None).ConfigureAwait(false); |
| 97 | + } |
| 98 | + |
| 99 | + [Theory] |
| 100 | + [MemberData(nameof(NonRecordDeclarationKeywords))] |
| 101 | + [WorkItem(3770, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3770")] |
| 102 | + public async Task TestPrimaryConstructorIncludeNoMissingParametersAsync(string keyword) |
| 103 | + { |
| 104 | + var testCode = $@" |
| 105 | +/// <include file='WithClassDocumentation.xml' path='/TestType/*' /> |
| 106 | +public {keyword} C(int param1, string param2, bool param3) {{ }}"; |
| 107 | + |
| 108 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 109 | + } |
10 | 110 | } |
11 | 111 | } |
0 commit comments