|
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.SA1307AccessibleFieldsMustBeginWithUpperCaseLetter, |
| 13 | + StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>; |
7 | 14 |
|
8 | 15 | public partial class SA1307CSharp8UnitTests : SA1307CSharp7UnitTests |
9 | 16 | { |
| 17 | + [Fact] |
| 18 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 19 | + public async Task TestReadonlyFieldInStructAsync() |
| 20 | + { |
| 21 | + var testCode = @"public struct TestStruct |
| 22 | +{ |
| 23 | + public readonly int {|#0:bar|}; |
| 24 | + public readonly void Method() { } |
| 25 | +}"; |
| 26 | + |
| 27 | + var fixedCode = @"public struct TestStruct |
| 28 | +{ |
| 29 | + public readonly int Bar; |
| 30 | + public readonly void Method() { } |
| 31 | +}"; |
| 32 | + |
| 33 | + DiagnosticResult expected = Diagnostic().WithLocation(0).WithArguments("bar"); |
| 34 | + |
| 35 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 40 | + public async Task TestStaticReadonlyFieldInStructAsync() |
| 41 | + { |
| 42 | + var testCode = @"public struct TestStruct |
| 43 | +{ |
| 44 | + public static readonly int {|#0:bar|}; |
| 45 | + public readonly void Method() { } |
| 46 | +}"; |
| 47 | + |
| 48 | + var fixedCode = @"public struct TestStruct |
| 49 | +{ |
| 50 | + public static readonly int Bar; |
| 51 | + public readonly void Method() { } |
| 52 | +}"; |
| 53 | + |
| 54 | + DiagnosticResult expected = Diagnostic().WithLocation(0).WithArguments("bar"); |
| 55 | + |
| 56 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + [WorkItem(3001, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3001")] |
| 61 | + public async Task TestReadonlyMembersWithoutFieldsAsync() |
| 62 | + { |
| 63 | + var testCode = @"public struct TestStruct |
| 64 | +{ |
| 65 | + public readonly void Method() { } |
| 66 | + public int Property { readonly get; set; } |
| 67 | +}"; |
| 68 | + |
| 69 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 70 | + } |
10 | 71 | } |
11 | 72 | } |
0 commit comments