Skip to content

Commit 5cea66b

Browse files
committed
Fix invalid unit tests
1 parent 81e99a9 commit 5cea66b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tests/CommunityToolkit.Mvvm.UnitTests/Test_ICommandAttribute.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public void Test_ICommandAttribute_ViewModelRightAfterRegion()
348348
}
349349

350350
[TestMethod]
351-
public async void Test_ICommandAttribute_CancelCommands()
351+
public async Task Test_ICommandAttribute_CancelCommands()
352352
{
353353
CancelCommandViewModel model = new();
354354

@@ -360,19 +360,19 @@ public async void Test_ICommandAttribute_CancelCommands()
360360

361361
await Task.Yield();
362362

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);
365365

366-
model.DoWorkWithParameterCommand.Execute(null);
366+
model.DoWorkWithParameterCommand.Execute(42);
367367

368368
Assert.IsTrue(model.DoWorkWithParameterCancelCommand.CanExecute(null));
369369

370-
model.DoWorkWithParameterCancelCommand.Execute(42);
370+
model.DoWorkWithParameterCancelCommand.Execute(null);
371371

372372
await Task.Yield();
373373

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);
376376
}
377377

378378
#region Region
@@ -621,8 +621,12 @@ public partial class CancelCommandViewModel
621621
{
622622
public TaskCompletionSource<object?> Tcs1 { get; } = new();
623623

624+
public object? Result1 { get; private set; }
625+
624626
public TaskCompletionSource<object?> Tcs2 { get; } = new();
625627

628+
public object? Result2 { get; private set; }
629+
626630
[ICommand(IncludeCancelCommand = true)]
627631
private async Task DoWorkAsync(CancellationToken token)
628632
{
@@ -632,11 +636,11 @@ private async Task DoWorkAsync(CancellationToken token)
632636
{
633637
_ = await Tcs1.Task;
634638

635-
_ = Tcs1.TrySetResult(null);
639+
Result1 = 42;
636640
}
637641
catch (OperationCanceledException e)
638642
{
639-
_ = Tcs1.TrySetResult(e);
643+
Result1 = e;
640644
}
641645
}
642646

@@ -649,11 +653,11 @@ private async Task DoWorkWithParameterAsync(int number, CancellationToken token)
649653
{
650654
_ = await Tcs2.Task;
651655

652-
_ = Tcs2.TrySetResult(null);
656+
Result2 = 42;
653657
}
654-
catch (OperationCanceledException)
658+
catch (OperationCanceledException e)
655659
{
656-
_ = Tcs2.TrySetResult(number);
660+
Result2 = e;
657661
}
658662
}
659663
}

0 commit comments

Comments
 (0)