@@ -348,7 +348,7 @@ public void Test_ICommandAttribute_ViewModelRightAfterRegion()
348
348
}
349
349
350
350
[ TestMethod ]
351
- public async void Test_ICommandAttribute_CancelCommands ( )
351
+ public async Task Test_ICommandAttribute_CancelCommands ( )
352
352
{
353
353
CancelCommandViewModel model = new ( ) ;
354
354
@@ -360,19 +360,19 @@ public async void Test_ICommandAttribute_CancelCommands()
360
360
361
361
await Task . Yield ( ) ;
362
362
363
- Assert . IsTrue ( model . Tcs1 . Task . IsCompleted ) ;
364
- Assert . IsTrue ( model . Tcs1 . Task . Result is OperationCanceledException ) ;
363
+ Assert . IsTrue ( model . Tcs1 . Task . IsCanceled ) ;
364
+ Assert . IsTrue ( model . Result1 is OperationCanceledException ) ;
365
365
366
- model . DoWorkWithParameterCommand . Execute ( null ) ;
366
+ model . DoWorkWithParameterCommand . Execute ( 42 ) ;
367
367
368
368
Assert . IsTrue ( model . DoWorkWithParameterCancelCommand . CanExecute ( null ) ) ;
369
369
370
- model . DoWorkWithParameterCancelCommand . Execute ( 42 ) ;
370
+ model . DoWorkWithParameterCancelCommand . Execute ( null ) ;
371
371
372
372
await Task . Yield ( ) ;
373
373
374
- Assert . IsTrue ( model . Tcs2 . Task . IsCompleted ) ;
375
- Assert . IsTrue ( model . Tcs2 . Task . Result is 42 ) ;
374
+ Assert . IsTrue ( model . Tcs2 . Task . IsCanceled ) ;
375
+ Assert . IsTrue ( model . Result2 is OperationCanceledException ) ;
376
376
}
377
377
378
378
#region Region
@@ -621,8 +621,12 @@ public partial class CancelCommandViewModel
621
621
{
622
622
public TaskCompletionSource < object ? > Tcs1 { get ; } = new ( ) ;
623
623
624
+ public object ? Result1 { get ; private set ; }
625
+
624
626
public TaskCompletionSource < object ? > Tcs2 { get ; } = new ( ) ;
625
627
628
+ public object ? Result2 { get ; private set ; }
629
+
626
630
[ ICommand ( IncludeCancelCommand = true ) ]
627
631
private async Task DoWorkAsync ( CancellationToken token )
628
632
{
@@ -632,11 +636,11 @@ private async Task DoWorkAsync(CancellationToken token)
632
636
{
633
637
_ = await Tcs1 . Task ;
634
638
635
- _ = Tcs1 . TrySetResult ( null ) ;
639
+ Result1 = 42 ;
636
640
}
637
641
catch ( OperationCanceledException e )
638
642
{
639
- _ = Tcs1 . TrySetResult ( e ) ;
643
+ Result1 = e ;
640
644
}
641
645
}
642
646
@@ -649,11 +653,11 @@ private async Task DoWorkWithParameterAsync(int number, CancellationToken token)
649
653
{
650
654
_ = await Tcs2 . Task ;
651
655
652
- _ = Tcs2 . TrySetResult ( null ) ;
656
+ Result2 = 42 ;
653
657
}
654
- catch ( OperationCanceledException )
658
+ catch ( OperationCanceledException e )
655
659
{
656
- _ = Tcs2 . TrySetResult ( number ) ;
660
+ Result2 = e ;
657
661
}
658
662
}
659
663
}
0 commit comments