@@ -202,37 +202,47 @@ private void OperationState_StateChanged(object sender, OperationStateChangedEve
202202 {
203203 RunAsync ( async ( ) =>
204204 {
205- try
206- {
207- if ( e . State == TestOperationStates . TestExecutionCanceling )
208- {
209- cancelling = true ;
210- await CoverageCancelledAsync ( "Test execution cancelling - running coverage will be cancelled." , e . Operation ) ;
211- }
205+ await TryAndLogExceptionAsync ( ( ) => OperationState_StateChangedAsync ( e ) ) ;
206+ } ) ;
207+ }
212208
209+ private async Task OperationState_StateChangedAsync ( OperationStateChangedEventArgs e )
210+ {
211+ if ( e . State == TestOperationStates . TestExecutionCanceling )
212+ {
213+ cancelling = true ;
214+ await CoverageCancelledAsync ( "Test execution cancelling - running coverage will be cancelled." , e . Operation ) ;
215+ }
213216
214- if ( e . State == TestOperationStates . TestExecutionStarting )
215- {
216- await TestExecutionStartingAsync ( e . Operation ) ;
217- cancelling = false ;
218- }
219217
220- if ( e . State == TestOperationStates . TestExecutionFinished )
221- {
222- await TestExecutionFinishedAsync ( e . Operation ) ;
223- }
218+ if ( e . State == TestOperationStates . TestExecutionStarting )
219+ {
220+ await TestExecutionStartingAsync ( e . Operation ) ;
221+ cancelling = false ;
222+ }
224223
225- if ( e . State == TestOperationStates . TestExecutionCancelAndFinished && ! cancelling )
226- {
227- await CoverageCancelledAsync ( "There has been an issue running tests. See the Tests output window pane." , e . Operation ) ;
228- }
224+ if ( e . State == TestOperationStates . TestExecutionFinished )
225+ {
226+ await TestExecutionFinishedAsync ( e . Operation ) ;
227+ }
229228
230- }
231- catch ( Exception exception )
232- {
233- logger . Log ( "Error processing unit test events" , exception ) ;
234- }
235- } ) ;
229+ if ( e . State == TestOperationStates . TestExecutionCancelAndFinished && ! cancelling )
230+ {
231+ await CoverageCancelledAsync ( "There has been an issue running tests. See the Tests output window pane." , e . Operation ) ;
232+ }
233+ }
234+
235+ private async Task TryAndLogExceptionAsync ( Func < Task > action )
236+ {
237+ try
238+ {
239+ await action ( ) ;
240+
241+ }
242+ catch ( Exception exception )
243+ {
244+ logger . Log ( "Error processing unit test events" , exception ) ;
245+ }
236246 }
237247 }
238248}
0 commit comments