@@ -5,7 +5,9 @@ namespace StyleCop.Analyzers.Test.CSharp8.OrderingRules
55{
66 using System . Threading ;
77 using System . Threading . Tasks ;
8+ using Microsoft . CodeAnalysis . Testing ;
89 using StyleCop . Analyzers . Test . CSharp7 . OrderingRules ;
10+ using StyleCop . Analyzers . Test . Helpers ;
911 using Xunit ;
1012 using static StyleCop . Analyzers . Test . Verifiers . StyleCopCodeFixVerifier <
1113 StyleCop . Analyzers . OrderingRules . SA1202ElementsMustBeOrderedByAccess ,
@@ -57,5 +59,70 @@ public async Task TestPropertiesOfInterfaceAsync()
5759 NumberOfFixAllIterations = 2 ,
5860 } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
5961 }
62+
63+ [ Fact ]
64+ [ WorkItem ( 3002 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3002" ) ]
65+ public async Task TestDefaultInterfaceMembersRequireAccessOrderingAsync ( )
66+ {
67+ var testCode = @"public interface ITest
68+ {
69+ private void Helper() { }
70+ public void {|#0:DoWork|}() { }
71+ }
72+ " ;
73+
74+ var fixedCode = @"public interface ITest
75+ {
76+ public void DoWork() { }
77+ private void Helper() { }
78+ }
79+ " ;
80+
81+ await VerifyCSharpFixAsync ( testCode , Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( "public" , "private" ) , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
82+ }
83+
84+ [ Fact ]
85+ [ WorkItem ( 3002 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3002" ) ]
86+ public async Task TestDefaultInterfaceMembersCorrectOrderingAsync ( )
87+ {
88+ var testCode = @"public interface ITest
89+ {
90+ public void DoWork() { }
91+ private void Helper() { }
92+ }
93+ " ;
94+
95+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
96+ }
97+
98+ [ Fact ]
99+ [ WorkItem ( 3002 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3002" ) ]
100+ public async Task TestInterfaceMembersMixingImplicitAndExplicitAccessibilityAsync ( )
101+ {
102+ var testCode = @"public interface ITest
103+ {
104+ private void Helper() { }
105+ void {|#0:ImplicitPublic|}() { }
106+ public void ExplicitPublic() { }
107+ }
108+ " ;
109+
110+ var fixedCode = @"public interface ITest
111+ {
112+ void ImplicitPublic() { }
113+ public void ExplicitPublic() { }
114+ private void Helper() { }
115+ }
116+ " ;
117+
118+ await new CSharpTest
119+ {
120+ TestCode = testCode ,
121+ ExpectedDiagnostics = { Diagnostic ( ) . WithLocation ( 0 ) . WithArguments ( "public" , "private" ) } ,
122+ FixedCode = fixedCode ,
123+ NumberOfIncrementalIterations = 2 ,
124+ NumberOfFixAllIterations = 2 ,
125+ } . RunAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
126+ }
60127 }
61128}
0 commit comments