@@ -62,9 +62,10 @@ public async Task Test_ICommandAttribute_RelayCommand()
62
62
63
63
await Task . WhenAll ( tasks ) ;
64
64
65
+ model . Values . Clear ( ) ;
65
66
tasks . Clear ( ) ;
66
67
67
- for ( int i = 10 ; i < 20 ; i ++ )
68
+ for ( int i = 0 ; i < 10 ; i ++ )
68
69
{
69
70
if ( model . AddValueToListAndDelayWithDefaultConcurrencyCommand . CanExecute ( i ) )
70
71
{
@@ -79,24 +80,54 @@ public async Task Test_ICommandAttribute_RelayCommand()
79
80
Assert . AreEqual ( 1 , tasks . Count ) ;
80
81
81
82
// Only the first item should have been added
82
- CollectionAssert . AreEqual ( model . Values , Enumerable . Range ( 0 , 11 ) . ToArray ( ) ) ;
83
+ CollectionAssert . AreEqual ( model . Values , new [ ] { 0 } ) ;
84
+
85
+ model . ResetTcs ( ) ;
86
+ model . Values . Clear ( ) ;
87
+ tasks . Clear ( ) ;
88
+
89
+ for ( int i = 0 ; i < 10 ; i ++ )
90
+ {
91
+ // Ignore the checks
92
+ tasks . Add ( model . AddValueToListAndDelayWithDefaultConcurrencyCommand . ExecuteAsync ( i ) ) ;
93
+ }
94
+
95
+ model . Tcs . SetResult ( null ) ;
96
+
97
+ await Task . WhenAll ( tasks ) ;
98
+
99
+ Assert . AreEqual ( 10 , tasks . Count ) ;
83
100
84
- for ( int i = 1 ; i < tasks . Count ; i ++ )
101
+ CollectionAssert . AreEqual ( model . Values , Enumerable . Range ( 0 , 10 ) . ToArray ( ) ) ;
102
+
103
+ model . Values . Clear ( ) ;
104
+ tasks . Clear ( ) ;
105
+
106
+ for ( int i = 0 ; i < 10 ; i ++ )
85
107
{
86
- Assert . AreSame ( Task . CompletedTask , tasks [ i ] ) ;
108
+ if ( model . AddValueToListAndDelayWithDefaultConcurrencyAsync_WithCancelCommandCommand . CanExecute ( i ) )
109
+ {
110
+ tasks . Add ( model . AddValueToListAndDelayWithDefaultConcurrencyAsync_WithCancelCommandCommand . ExecuteAsync ( i ) ) ;
111
+ }
87
112
}
88
113
114
+ Assert . AreEqual ( 1 , tasks . Count ) ;
115
+
116
+ // Same as above, only the first one is added
117
+ CollectionAssert . AreEqual ( model . Values , new [ ] { 0 } ) ;
118
+
119
+ model . Values . Clear ( ) ;
89
120
tasks . Clear ( ) ;
90
121
91
- for ( int i = 11 ; i < 21 ; i ++ )
122
+ for ( int i = 0 ; i < 10 ; i ++ )
92
123
{
124
+ // Ignore the checks
93
125
tasks . Add ( model . AddValueToListAndDelayWithDefaultConcurrencyAsync_WithCancelCommandCommand . ExecuteAsync ( i ) ) ;
94
126
}
95
127
96
128
Assert . AreEqual ( 10 , tasks . Count ) ;
97
129
98
- // Only the first item should have been added, like the previous case
99
- CollectionAssert . AreEqual ( model . Values , Enumerable . Range ( 0 , 12 ) . ToArray ( ) ) ;
130
+ CollectionAssert . AreEqual ( model . Values , Enumerable . Range ( 0 , 10 ) . ToArray ( ) ) ;
100
131
}
101
132
102
133
[ TestMethod ]
@@ -432,7 +463,9 @@ public sealed partial class MyViewModel
432
463
433
464
public List < int > Values { get ; } = new ( ) ;
434
465
435
- public TaskCompletionSource < object ? > Tcs { get ; } = new ( ) ;
466
+ public TaskCompletionSource < object ? > Tcs { get ; private set ; } = new ( ) ;
467
+
468
+ public void ResetTcs ( ) => Tcs = new TaskCompletionSource < object ? > ( ) ;
436
469
437
470
/// <summary>This is a single line summary.</summary>
438
471
[ ICommand ]
0 commit comments