|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.NamingRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp7.NamingRules; |
| 10 | + using Xunit; |
| 11 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 12 | + StyleCop.Analyzers.NamingRules.SX1309SStaticFieldNamesMustBeginWithUnderscore, |
| 13 | + StyleCop.Analyzers.NamingRules.SX1309CodeFixProvider>; |
7 | 14 |
|
8 | 15 | public partial class SX1309SCSharp8UnitTests : SX1309SCSharp7UnitTests |
9 | 16 | { |
| 17 | + [Fact] |
| 18 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 19 | + public async Task TestReadonlyMembersDoNotTriggerAsync() |
| 20 | + { |
| 21 | + var testCode = @"public struct TestStruct |
| 22 | +{ |
| 23 | + public readonly void Method() { } |
| 24 | + public int Property { readonly get; set; } |
| 25 | +}"; |
| 26 | + |
| 27 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 28 | + } |
| 29 | + |
| 30 | + [Fact] |
| 31 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 32 | + public async Task TestPrivateStaticFieldRequiresUnderscoreAsync() |
| 33 | + { |
| 34 | + var testCode = @"public struct TestStruct |
| 35 | +{ |
| 36 | + private static int {|#0:value|}; |
| 37 | + public readonly void Method() { } |
| 38 | +}"; |
| 39 | + |
| 40 | + var fixedCode = @"public struct TestStruct |
| 41 | +{ |
| 42 | + private static int _value; |
| 43 | + public readonly void Method() { } |
| 44 | +}"; |
| 45 | + |
| 46 | + DiagnosticResult expected = Diagnostic().WithLocation(0).WithArguments("value"); |
| 47 | + |
| 48 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 53 | + public async Task TestStaticReadonlyFieldIgnoredAsync() |
| 54 | + { |
| 55 | + var testCode = @"public struct TestStruct |
| 56 | +{ |
| 57 | + private static readonly int value = 0; |
| 58 | + public readonly void Method() { } |
| 59 | +}"; |
| 60 | + |
| 61 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 62 | + } |
10 | 63 | } |
11 | 64 | } |
0 commit comments