@@ -7,12 +7,13 @@ namespace StyleCop.Analyzers.Test.OrderingRules
77 using System . Threading ;
88 using System . Threading . Tasks ;
99 using Microsoft . CodeAnalysis ;
10+ using Microsoft . CodeAnalysis . CodeFixes ;
1011 using Microsoft . CodeAnalysis . Diagnostics ;
1112 using StyleCop . Analyzers . OrderingRules ;
1213 using TestHelper ;
1314 using Xunit ;
1415
15- public class SA1201UnitTests : DiagnosticVerifier
16+ public class SA1201UnitTests : CodeFixVerifier
1617 {
1718 [ Fact ]
1819 public async Task TestOuterOrderCorrectOrderAsync ( )
@@ -146,6 +147,28 @@ public class TestClass { }
146147 } ;
147148
148149 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
150+
151+ string fixedCode = @"public class OuterType
152+ {
153+ public string TestField;
154+ public OuterType() { }
155+ ~OuterType() { }
156+ public delegate void TestDelegate();
157+ public event TestDelegate TestEvent { add { } remove { } }
158+ public enum TestEnum { }
159+ public interface ITest { }
160+ public string TestProperty { get; set; }
161+ public string this[string arg] { get { return ""foo""; } set { } }
162+ public static explicit operator bool(OuterType t1) { return t1.TestField != null; }
163+ public static OuterType operator +(OuterType t1, OuterType t2) { return t1; }
164+ public void TestMethod () { }
165+ public struct TestStruct { }
166+ public class TestClass { }
167+ }
168+ " ;
169+
170+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
171+ await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
149172 }
150173
151174 [ Fact ]
@@ -178,6 +201,27 @@ public class TestClass { }
178201 } ;
179202
180203 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
204+
205+ string fixedCode = @"public struct OuterType
206+ {
207+ public string TestField;
208+ public OuterType(int argument) { TestField = ""foo""; TestProperty = ""bar""; }
209+ public delegate void TestDelegate();
210+ public event TestDelegate TestEvent { add { } remove { } }
211+ public enum TestEnum { }
212+ public interface ITest { }
213+ public string TestProperty { get; set; }
214+ public string this[string arg] { get { return ""foo""; } set { } }
215+ public static explicit operator bool(OuterType t1) { return t1.TestField != null; }
216+ public static OuterType operator +(OuterType t1, OuterType t2) { return t1; }
217+ public void TestMethod () { }
218+ public struct TestStruct { }
219+ public class TestClass { }
220+ }
221+ " ;
222+
223+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
224+ await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
181225 }
182226
183227 [ Fact ]
@@ -191,12 +235,22 @@ public async Task TestTypeMemberOrderWrongOrderInterfaceAsync()
191235 string this[string arg] { get; set; }
192236}
193237" ;
194- var expected = new [ ]
195- {
196- this . CSharpDiagnostic ( ) . WithLocation ( 6 , 12 ) . WithArguments ( "indexer" , "method" )
197- } ;
238+
239+ var expected = this . CSharpDiagnostic ( ) . WithLocation ( 6 , 12 ) . WithArguments ( "indexer" , "method" ) ;
198240
199241 await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
242+
243+ string fixedCode = @"public interface OuterType
244+ {
245+ event System.Action TestEvent;
246+ string TestProperty { get; set; }
247+ string this[string arg] { get; set; }
248+ void TestMethod ();
249+ }
250+ " ;
251+
252+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
253+ await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
200254 }
201255
202256 [ Fact ]
@@ -248,9 +302,16 @@ public event System.Action TestEvent4 { add { } remove { } }
248302 await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
249303 }
250304
305+ /// <inheritdoc/>
251306 protected override IEnumerable < DiagnosticAnalyzer > GetCSharpDiagnosticAnalyzers ( )
252307 {
253308 yield return new SA1201ElementsMustAppearInTheCorrectOrder ( ) ;
254309 }
310+
311+ /// <inheritdoc/>
312+ protected override CodeFixProvider GetCSharpCodeFixProvider ( )
313+ {
314+ return new ElementOrderCodeFixProvider ( ) ;
315+ }
255316 }
256317}
0 commit comments