|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp10.NamingRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp9.NamingRules; |
| 10 | + using Xunit; |
| 11 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 12 | + StyleCop.Analyzers.NamingRules.SA1300ElementMustBeginWithUpperCaseLetter, |
| 13 | + StyleCop.Analyzers.NamingRules.RenameToUpperCaseCodeFixProvider>; |
7 | 14 |
|
8 | 15 | public class SA1300CSharp10UnitTests : SA1300CSharp9UnitTests |
9 | 16 | { |
| 17 | + [Fact] |
| 18 | + public async Task TestUpperCaseFileScopedNamespaceAsync() |
| 19 | + { |
| 20 | + var testCode = @"namespace Test;"; |
| 21 | + |
| 22 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public async Task TestLowerCaseFileScopedNamespaceAsync() |
| 27 | + { |
| 28 | + var testCode = @"namespace {|#0:test|};"; |
| 29 | + |
| 30 | + var fixedCode = @"namespace Test;"; |
| 31 | + |
| 32 | + DiagnosticResult expected = Diagnostic().WithArguments("test").WithLocation(0); |
| 33 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 34 | + } |
| 35 | + |
| 36 | + [Fact] |
| 37 | + public async Task TestAllowedLowerCaseFileScopedNamespaceIsNotReportedAsync() |
| 38 | + { |
| 39 | + var customTestSettings = @" |
| 40 | +{ |
| 41 | + ""settings"": { |
| 42 | + ""namingRules"": { |
| 43 | + ""allowedNamespaceComponents"": [ ""eBay"" ] |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | +"; |
| 48 | + |
| 49 | + var testCode = @"namespace eBay;"; |
| 50 | + |
| 51 | + await new CSharpTest |
| 52 | + { |
| 53 | + TestCode = testCode, |
| 54 | + Settings = customTestSettings, |
| 55 | + }.RunAsync(CancellationToken.None).ConfigureAwait(false); |
| 56 | + } |
| 57 | + |
| 58 | + [Fact] |
| 59 | + public async Task TestLowerCaseComlicatedFileScopedNamespaceAsync() |
| 60 | + { |
| 61 | + var testCode = @"namespace {|#0:test|}.{|#1:foo|}.{|#2:bar|};"; |
| 62 | + |
| 63 | + var fixedCode = @"namespace Test.Foo.Bar;"; |
| 64 | + |
| 65 | + DiagnosticResult[] expected = new[] |
| 66 | + { |
| 67 | + Diagnostic().WithArguments("test").WithLocation(0), |
| 68 | + Diagnostic().WithArguments("foo").WithLocation(1), |
| 69 | + Diagnostic().WithArguments("bar").WithLocation(2), |
| 70 | + }; |
| 71 | + |
| 72 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 73 | + } |
| 74 | + |
| 75 | + [Fact] |
| 76 | + public async Task TestAllowedLowerCaseComplicatedFileScopedNamespaceIsNotReportedAsync() |
| 77 | + { |
| 78 | + var customTestSettings = @" |
| 79 | +{ |
| 80 | + ""settings"": { |
| 81 | + ""namingRules"": { |
| 82 | + ""allowedNamespaceComponents"": [ ""iPod"" ] |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +"; |
| 87 | + |
| 88 | + var testCode = @"namespace Apple.iPod.Library;"; |
| 89 | + |
| 90 | + await new CSharpTest |
| 91 | + { |
| 92 | + TestCode = testCode, |
| 93 | + Settings = customTestSettings, |
| 94 | + }.RunAsync(CancellationToken.None).ConfigureAwait(false); |
| 95 | + } |
10 | 96 | } |
11 | 97 | } |
0 commit comments