@@ -62,7 +62,11 @@ public async Task Test_AsyncRelayCommandOfT_AlwaysEnabled()
6262
6363 Assert . AreEqual ( ticks , 2 ) ;
6464
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" ) ;
6670 }
6771
6872 [ TestMethod ]
@@ -87,6 +91,12 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionTrue()
8791 command . Execute ( "2" ) ;
8892
8993 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" ) ;
90100 }
91101
92102 [ TestMethod ]
@@ -112,10 +122,16 @@ public void Test_AsyncRelayCommandOfT_WithCanExecuteFunctionFalse()
112122 command . Execute ( "42" ) ;
113123
114124 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" ) ;
115131 }
116132
117133 [ TestMethod ]
118- public void Test_AsyncRelayCommandOfT_NullWithValueType ( )
134+ public void Test_AsyncRelayCommandOfT_InvalidArgumentWithValueType ( )
119135 {
120136 int n = 0 ;
121137
@@ -125,18 +141,38 @@ public void Test_AsyncRelayCommandOfT_NullWithValueType()
125141 return Task . CompletedTask ;
126142 } ) ;
127143
144+ // Special case
128145 Assert . IsFalse ( command . CanExecute ( null ) ) ;
129- _ = Assert . ThrowsException < NullReferenceException > ( ( ) => command . Execute ( null ) ) ;
130146
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 (
132161 i =>
133162 {
134163 n = i ;
135164 return Task . CompletedTask ;
136165 } , i => i > 0 ) ;
137166
167+ // Special case
138168 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" ) ;
140176 }
141177
142178 [ TestMethod ]
@@ -239,7 +275,11 @@ private static async Task Test_AsyncRelayCommandOfT_AllowConcurrentExecutions_Te
239275
240276 Assert . IsFalse ( command . IsRunning ) ;
241277
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" ) ;
243283 }
244284
245285 [ TestMethod ]
0 commit comments