|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp12.ReadabilityRules
|
5 | 5 | {
|
| 6 | + using System.Collections.Generic; |
| 7 | + using System.Threading; |
| 8 | + using System.Threading.Tasks; |
| 9 | + using Microsoft.CodeAnalysis.Testing; |
6 | 10 | using StyleCop.Analyzers.Test.CSharp11.ReadabilityRules;
|
| 11 | + using Xunit; |
| 12 | + |
| 13 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 14 | + StyleCop.Analyzers.ReadabilityRules.SA1135UsingDirectivesMustBeQualified, |
| 15 | + StyleCop.Analyzers.ReadabilityRules.SA1135CodeFixProvider>; |
7 | 16 |
|
8 | 17 | public partial class SA1135CSharp12UnitTests : SA1135CSharp11UnitTests
|
9 | 18 | {
|
| 19 | + public static IEnumerable<object[]> CorrectAliasableTypes => new[] |
| 20 | + { |
| 21 | + new[] { "string" }, |
| 22 | + new[] { "(string, int)" }, |
| 23 | + new[] { "(System.String, System.Int32)" }, |
| 24 | + new[] { "bool[]" }, |
| 25 | + new[] { "System.Boolean[]" }, |
| 26 | + }; |
| 27 | + |
| 28 | + [Theory] |
| 29 | + [MemberData(nameof(CorrectAliasableTypes))] |
| 30 | + [WorkItem(3882, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3882")] |
| 31 | + public async Task TestUsingTypeAliasOutsideNamespaceAsync(string type) |
| 32 | + { |
| 33 | + var testCode = $@" |
| 34 | +using MyType = {type}; |
| 35 | +
|
| 36 | +namespace TestNamespace |
| 37 | +{{ |
| 38 | +}}"; |
| 39 | + |
| 40 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 41 | + } |
| 42 | + |
| 43 | + [Theory] |
| 44 | + [MemberData(nameof(CorrectAliasableTypes))] |
| 45 | + [WorkItem(3882, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3882")] |
| 46 | + public async Task TestUsingTypeAliasInsideNamespaceAsync(string type) |
| 47 | + { |
| 48 | + var testCode = $@" |
| 49 | +namespace TestNamespace |
| 50 | +{{ |
| 51 | + using MyType = {type}; |
| 52 | +}}"; |
| 53 | + |
| 54 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 55 | + } |
10 | 56 | }
|
11 | 57 | }
|
0 commit comments