@@ -62,7 +62,11 @@ public async Task Test_AsyncRelayCommandOfT_AlwaysEnabled()
62
62
63
63
Assert . AreEqual ( ticks , 2 ) ;
64
64
65
- _ = Assert . ThrowsException < InvalidCastException > ( ( ) => command . Execute ( new object ( ) ) ) ;
65
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( new object ( ) ) , "parameter" ) ;
66
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( 42 ) , "parameter" ) ;
67
+
68
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( new object ( ) ) , "parameter" ) ;
69
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( 42 ) , "parameter" ) ;
66
70
}
67
71
68
72
[ TestMethod ]
@@ -87,6 +91,12 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionTrue()
87
91
command . Execute ( "2" ) ;
88
92
89
93
Assert . AreEqual ( ticks , 2 ) ;
94
+
95
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( new object ( ) ) , "parameter" ) ;
96
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( 42 ) , "parameter" ) ;
97
+
98
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( new object ( ) ) , "parameter" ) ;
99
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( 42 ) , "parameter" ) ;
90
100
}
91
101
92
102
[ TestMethod ]
@@ -112,10 +122,16 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionFalse()
112
122
command . Execute ( "42" ) ;
113
123
114
124
Assert . AreEqual ( ticks , 42 ) ;
125
+
126
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( new object ( ) ) , "parameter" ) ;
127
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( 42 ) , "parameter" ) ;
128
+
129
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( new object ( ) ) , "parameter" ) ;
130
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( 42 ) , "parameter" ) ;
115
131
}
116
132
117
133
[ TestMethod ]
118
- public void Test_AsyncRelayCommandOfT_NullWithValueType ( )
134
+ public void Test_AsyncRelayCommandOfT_InvalidArgumentWithValueType ( )
119
135
{
120
136
int n = 0 ;
121
137
@@ -125,18 +141,38 @@ public void Test_AsyncRelayCommandOfT_NullWithValueType()
125
141
return Task . CompletedTask ;
126
142
} ) ;
127
143
144
+ // Special case
128
145
Assert . IsFalse ( command . CanExecute ( null ) ) ;
129
- _ = Assert . ThrowsException < NullReferenceException > ( ( ) => command . Execute ( null ) ) ;
130
146
131
- command = new AsyncRelayCommand < int > (
147
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( "Hello" ) , "parameter" ) ;
148
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( 3.14f ) , "parameter" ) ;
149
+
150
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( null ) , "parameter" ) ;
151
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( "Hello" ) , "parameter" ) ;
152
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( 3.14f ) , "parameter" ) ;
153
+ }
154
+
155
+ [ TestMethod ]
156
+ public void Test_AsyncRelayCommandOfT_InvalidArgumentWithValueType_WithCanExecute ( )
157
+ {
158
+ int n = 0 ;
159
+
160
+ AsyncRelayCommand < int > ? command = new (
132
161
i =>
133
162
{
134
163
n = i ;
135
164
return Task . CompletedTask ;
136
165
} , i => i > 0 ) ;
137
166
167
+ // Special case
138
168
Assert . IsFalse ( command . CanExecute ( null ) ) ;
139
- _ = Assert . ThrowsException < NullReferenceException > ( ( ) => command . Execute ( null ) ) ;
169
+
170
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( "Hello" ) , "parameter" ) ;
171
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( 3.14f ) , "parameter" ) ;
172
+
173
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( null ) , "parameter" ) ;
174
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( "Hello" ) , "parameter" ) ;
175
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( 3.14f ) , "parameter" ) ;
140
176
}
141
177
142
178
[ TestMethod ]
@@ -239,7 +275,11 @@ private static async Task Test_AsyncRelayCommandOfT_AllowConcurrentExecutions_Te
239
275
240
276
Assert . IsFalse ( command . IsRunning ) ;
241
277
242
- _ = Assert . ThrowsException < InvalidCastException > ( ( ) => command . Execute ( new object ( ) ) ) ;
278
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( new object ( ) ) , "parameter" ) ;
279
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . CanExecute ( 3.14f ) , "parameter" ) ;
280
+
281
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( new object ( ) ) , "parameter" ) ;
282
+ ExceptionHelper . ThrowsArgumentExceptionWithParameterName ( ( ) => command . Execute ( 3.14f ) , "parameter" ) ;
243
283
}
244
284
245
285
[ TestMethod ]
0 commit comments