|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.DocumentationRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp7.DocumentationRules; |
| 10 | + using Xunit; |
| 11 | + using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1649FileNameMustMatchTypeName>; |
7 | 12 |
|
8 | 13 | public partial class SA1649CSharp8UnitTests : SA1649CSharp7UnitTests |
9 | 14 | { |
| 15 | + [Fact] |
| 16 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 17 | + public async Task VerifyReadonlyMembersDoNotAffectCorrectFileNameAsync() |
| 18 | + { |
| 19 | + var testCode = @" |
| 20 | +namespace TestNamespace |
| 21 | +{ |
| 22 | + public readonly struct TestType |
| 23 | + { |
| 24 | + private readonly int value; |
| 25 | +
|
| 26 | + public TestType(int value) |
| 27 | + { |
| 28 | + this.value = value; |
| 29 | + } |
| 30 | +
|
| 31 | + public readonly int GetValue() => this.value; |
| 32 | +
|
| 33 | + public int Property |
| 34 | + { |
| 35 | + readonly get => this.value; |
| 36 | + set => _ = value; |
| 37 | + } |
| 38 | +
|
| 39 | + public int this[int index] |
| 40 | + { |
| 41 | + readonly get => this.value + index; |
| 42 | + set => _ = value - index; |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +"; |
| 47 | + |
| 48 | + await VerifyCSharpDiagnosticAsync(fileName: "TestType.cs", testCode, testSettings: null, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 53 | + public async Task VerifyWrongFileNameWithReadonlyMembersAsync() |
| 54 | + { |
| 55 | + var testCode = @" |
| 56 | +namespace TestNamespace |
| 57 | +{ |
| 58 | + public readonly struct {|#0:TestType|} |
| 59 | + { |
| 60 | + private readonly int value; |
| 61 | +
|
| 62 | + public TestType(int value) |
| 63 | + { |
| 64 | + this.value = value; |
| 65 | + } |
| 66 | +
|
| 67 | + public readonly int GetValue() => this.value; |
| 68 | +
|
| 69 | + public int Property |
| 70 | + { |
| 71 | + readonly get => this.value; |
| 72 | + set => _ = value; |
| 73 | + } |
| 74 | +
|
| 75 | + public int this[int index] |
| 76 | + { |
| 77 | + readonly get => this.value + index; |
| 78 | + set => _ = value - index; |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +"; |
| 83 | + var fixedCode = @" |
| 84 | +namespace TestNamespace |
| 85 | +{ |
| 86 | + public readonly struct TestType |
| 87 | + { |
| 88 | + private readonly int value; |
| 89 | +
|
| 90 | + public TestType(int value) |
| 91 | + { |
| 92 | + this.value = value; |
| 93 | + } |
| 94 | +
|
| 95 | + public readonly int GetValue() => this.value; |
| 96 | +
|
| 97 | + public int Property |
| 98 | + { |
| 99 | + readonly get => this.value; |
| 100 | + set => _ = value; |
| 101 | + } |
| 102 | +
|
| 103 | + public int this[int index] |
| 104 | + { |
| 105 | + readonly get => this.value + index; |
| 106 | + set => _ = value - index; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | +"; |
| 111 | + |
| 112 | + var expectedDiagnostic = Diagnostic().WithLocation(0); |
| 113 | + await VerifyCSharpFixAsync(oldFileName: "WrongFileName.cs", testCode, StyleCopSettings, expectedDiagnostic, newFileName: "TestType.cs", fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 114 | + } |
10 | 115 | } |
11 | 116 | } |
0 commit comments