Skip to content

Commit fa4d574

Browse files
committed
Update SA1202 for partial methods
1 parent 0bb080b commit fa4d574

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/OrderingRules/SA1202CSharp9UnitTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,65 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.OrderingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.OrderingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.OrderingRules.SA1202ElementsMustBeOrderedByAccess,
13+
StyleCop.Analyzers.OrderingRules.ElementOrderCodeFixProvider>;
714

815
public partial class SA1202CSharp9UnitTests : SA1202CSharp8UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3971, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3971")]
19+
public async Task TestPartialMethodExplicitAccessibilityDeclarationOrderingAsync()
20+
{
21+
var testCode = @"
22+
public partial class TestClass
23+
{
24+
private void Helper() { }
25+
26+
public partial void {|#0:TestMethod|}();
27+
}
28+
29+
public partial class TestClass
30+
{
31+
public partial void TestMethod()
32+
{
33+
}
34+
}
35+
";
36+
37+
var expected = Diagnostic().WithLocation(0).WithArguments("public", "private");
38+
39+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
40+
}
41+
42+
[Fact]
43+
[WorkItem(3971, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3971")]
44+
public async Task TestPartialMethodExplicitAccessibilityImplementationOrderingAsync()
45+
{
46+
var testCode = @"
47+
public partial class TestClass
48+
{
49+
public partial void TestMethod();
50+
}
51+
52+
public partial class TestClass
53+
{
54+
private void Helper() { }
55+
56+
public partial void {|#0:TestMethod|}()
57+
{
58+
}
59+
}
60+
";
61+
62+
var expected = Diagnostic().WithLocation(0).WithArguments("public", "private");
63+
64+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
65+
}
1066
}
1167
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,5 +989,23 @@ public string
989989

990990
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
991991
}
992+
993+
[Fact]
994+
[WorkItem(3971, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3971")]
995+
public async Task TestPartialMethodImplicitPrivateOrderingAsync()
996+
{
997+
var testCode = @"
998+
public partial class TestClass
999+
{
1000+
partial void TestMethod();
1001+
1002+
public void {|#0:PublicMethod|}() { }
1003+
}
1004+
";
1005+
1006+
var expected = Diagnostic().WithLocation(0).WithArguments("public", "private");
1007+
1008+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
1009+
}
9921010
}
9931011
}

0 commit comments

Comments
 (0)