@@ -22,6 +22,7 @@ public void EmptyNoAction()
2222 {
2323 Verifier . VerifyCodeFixAsync ( string . Empty , string . Empty ) ;
2424 }
25+
2526 [ TestMethod ]
2627 public async Task CanFixTask ( )
2728 {
@@ -81,11 +82,137 @@ public Task Method1(object p1)
8182 {
8283 // Test0.cs(20,21): info ACA0001: Forward execution of "Method1" to member "_disposables"
8384 Verifier . Diagnostic ( ) . WithSpan ( 20 , 21 , 20 , 28 ) . WithArguments ( "Method1" , "_disposables" )
84- } ;
85+ } ;
86+
87+ await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
88+ }
89+
90+ [ TestMethod ]
91+ public async Task CanFixEmptyExpression ( )
92+ {
93+ var test = @"
94+ using System;
95+ using System.Collections.Generic;
96+ using System.Linq;
97+ using System.Linq.Expressions;
98+ using System.Text;
99+ using System.Threading.Tasks;
100+ using System.Diagnostics;
101+
102+ namespace ConsoleApplication1
103+ {
104+ public interface ICustomInterface
105+ {
106+ Task Method1(object p1);
107+ }
108+
109+ class TypeName : ICustomInterface
110+ {
111+ private ICollection<ICustomInterface> _disposables;
112+
113+ public async Task Method1(object p1) => Expression.Empty();
114+ }
115+ }" ;
116+ var fixtest = @"
117+ using System;
118+ using System.Collections.Generic;
119+ using System.Linq;
120+ using System.Linq.Expressions;
121+ using System.Text;
122+ using System.Threading.Tasks;
123+ using System.Diagnostics;
124+
125+ namespace ConsoleApplication1
126+ {
127+ public interface ICustomInterface
128+ {
129+ Task Method1(object p1);
130+ }
131+
132+ class TypeName : ICustomInterface
133+ {
134+ private ICollection<ICustomInterface> _disposables;
135+
136+ public async Task Method1(object p1)
137+ {
138+ await Task.WhenAll(_disposables.Select(item => item.Method1(p1)));
139+ }
140+ }
141+ }" ;
142+
143+ var expected = new DiagnosticResult [ ]
144+ {
145+ // Test0.cs(21,27): info ACA0001: Forward execution of "Method1" to member "_disposables"
146+ Verifier . Diagnostic ( ) . WithSpan ( 21 , 27 , 21 , 34 ) . WithArguments ( "Method1" , "_disposables" )
147+ } ;
148+
149+ await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
150+ }
151+
152+
153+ [ TestMethod ]
154+ public async Task CanFixArrowThrow ( )
155+ {
156+ var test = @"
157+ using System;
158+ using System.Collections.Generic;
159+ using System.Linq;
160+ using System.Linq.Expressions;
161+ using System.Text;
162+ using System.Threading.Tasks;
163+ using System.Diagnostics;
164+
165+ namespace ConsoleApplication1
166+ {
167+ public interface ICustomInterface
168+ {
169+ Task Method1(object p1);
170+ }
171+
172+ class TypeName : ICustomInterface
173+ {
174+ private ICollection<ICustomInterface> _disposables;
175+
176+ public async Task Method1(object p1) => throw new NotImplementedException();
177+ }
178+ }" ;
179+ var fixtest = @"
180+ using System;
181+ using System.Collections.Generic;
182+ using System.Linq;
183+ using System.Linq.Expressions;
184+ using System.Text;
185+ using System.Threading.Tasks;
186+ using System.Diagnostics;
187+
188+ namespace ConsoleApplication1
189+ {
190+ public interface ICustomInterface
191+ {
192+ Task Method1(object p1);
193+ }
194+
195+ class TypeName : ICustomInterface
196+ {
197+ private ICollection<ICustomInterface> _disposables;
198+
199+ public async Task Method1(object p1)
200+ {
201+ await Task.WhenAll(_disposables.Select(item => item.Method1(p1)));
202+ }
203+ }
204+ }" ;
205+
206+ var expected = new DiagnosticResult [ ]
207+ {
208+ // Test0.cs(21,27): info ACA0001: Forward execution of "Method1" to member "_disposables"
209+ Verifier . Diagnostic ( ) . WithSpan ( 21 , 27 , 21 , 34 ) . WithArguments ( "Method1" , "_disposables" )
210+ } ;
85211
86212 await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
87213 }
88214
215+
89216 [ TestMethod ]
90217 public async Task CanFixAsyncTask ( )
91218 {
@@ -144,12 +271,12 @@ public async Task Method1(object p1)
144271 {
145272 // Test0.cs(20,27): info ACA0001: Forward execution of "Method1" to member "_disposables"
146273 Verifier . Diagnostic ( ) . WithSpan ( 20 , 27 , 20 , 34 ) . WithArguments ( "Method1" , "_disposables" )
147- } ;
274+ } ;
148275
149276 await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
150277 }
151278
152- [ TestMethod ]
279+ [ TestMethod ]
153280 public async Task CanFixBool ( )
154281 {
155282 var test = @"
@@ -213,8 +340,8 @@ public bool Method1(object p1)
213340
214341 await Verifier . VerifyCodeFixAsync ( test , expectedDiagnostics , fixtest ) ;
215342 }
216-
217- [ TestMethod ]
343+
344+ [ TestMethod ]
218345 public async Task VerifyFullRewrite ( )
219346 {
220347 var test = @"
@@ -530,7 +657,7 @@ public void Method3()
530657// Test0.cs(43,21): info ACA0001: Forward execution of "Method3" to member "_disposables"
531658 Verifier . Diagnostic ( ) . WithSpan ( 43 , 21 , 43 , 28 ) . WithArguments ( "Method3" , "_disposables" )
532659 } ;
533- await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
660+ await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
534661
535662 await new CodeFixTest < Analyzer , FixByForwardingToCollectionChildren > ( )
536663 {
@@ -540,22 +667,22 @@ public void Method3()
540667 {
541668 Sources = { test } ,
542669 ExpectedDiagnostics =
543- {
544- // Test0.cs(24,21): info ACA0001: Forward execution of "Method1" to member "_disposables"
545- Verifier . Diagnostic ( ) . WithSpan ( 24 , 21 , 24 , 28 ) . WithArguments ( "Method1" , "_disposables" ) ,
670+ {
671+ // Test0.cs(24,21): info ACA0001: Forward execution of "Method1" to member "_disposables"
672+ Verifier . Diagnostic ( ) . WithSpan ( 24 , 21 , 24 , 28 ) . WithArguments ( "Method1" , "_disposables" ) ,
546673// Test0.cs(33,21): info ACA0001: Forward execution of "Method2" to member "_disposables"
547- Verifier . Diagnostic ( ) . WithSpan ( 33 , 21 , 33 , 28 ) . WithArguments ( "Method2" , "_disposables" ) ,
674+ Verifier . Diagnostic ( ) . WithSpan ( 33 , 21 , 33 , 28 ) . WithArguments ( "Method2" , "_disposables" ) ,
548675// Test0.cs(38,21): info ACA0001: Forward execution of "Method2" to member "_disposables"
549- Verifier . Diagnostic ( ) . WithSpan ( 38 , 21 , 38 , 28 ) . WithArguments ( "Method2" , "_disposables" ) ,
676+ Verifier . Diagnostic ( ) . WithSpan ( 38 , 21 , 38 , 28 ) . WithArguments ( "Method2" , "_disposables" ) ,
550677// Test0.cs(43,21): info ACA0001: Forward execution of "Method3" to member "_disposables"
551- Verifier . Diagnostic ( ) . WithSpan ( 43 , 21 , 43 , 28 ) . WithArguments ( "Method3" , "_disposables" )
552- } ,
678+ Verifier . Diagnostic ( ) . WithSpan ( 43 , 21 , 43 , 28 ) . WithArguments ( "Method3" , "_disposables" )
679+ } ,
553680 } ,
554681 FixedState =
555682 {
556683 ExpectedDiagnostics =
557684 {
558- } ,
685+ } ,
559686 Sources = { fixtest }
560687 } ,
561688 } . RunAsync ( ) ;
@@ -889,7 +1016,7 @@ public void Method3()
8891016 Verifier . Diagnostic ( ) . WithSpan ( 38 , 21 , 38 , 28 ) . WithArguments ( "Method2" , "Disposables" ) ,
8901017// Test0.cs(43,21): info ACA0001: Forward execution of "Method3" to member "Disposables"
8911018 Verifier . Diagnostic ( ) . WithSpan ( 43 , 21 , 43 , 28 ) . WithArguments ( "Method3" , "Disposables" )
892- } ;
1019+ } ;
8931020
8941021 await Verifier . VerifyCodeFixAsync ( test , expected , fixtest ) ;
8951022 }
@@ -1073,8 +1200,7 @@ public void Method3()
10731200 }
10741201 }
10751202}" ;
1076-
10771203 }
10781204#pragma warning restore 219
1079- }
1205+ }
10801206}
0 commit comments