1
+ using System ;
2
+ using System . Threading . Tasks ;
3
+ using Xamarin . CommunityToolkit . Exceptions ;
4
+ using Xamarin . CommunityToolkit . ObjectModel ;
5
+ using Xamarin . CommunityToolkit . UnitTests . ObjectModel . ICommandTests . AsyncValueCommandTests ;
6
+ using Xunit ;
7
+
8
+ namespace Xamarin . CommunityToolkit . UnitTests . ObjectModel . ICommandTests . CommandFactoryTests
9
+ {
10
+ public class CommandFactoryAsyncValueCommandTests : BaseAsyncValueCommandTests
11
+ {
12
+
13
+ [ Fact ]
14
+ public void NullExecuteParameter ( )
15
+ {
16
+ // Arrange
17
+ Func < ValueTask > execute = null ;
18
+
19
+ // Act
20
+
21
+ // Assert
22
+ Assert . Throws < ArgumentNullException > ( ( ) => CommandFactory . Create ( execute ) ) ;
23
+ }
24
+
25
+ [ Fact ]
26
+ public void NullCanExecuteParameter ( )
27
+ {
28
+ // Arrange
29
+ var command = CommandFactory . Create ( NoParameterTask , null ) ;
30
+
31
+ // Act
32
+
33
+ // Assert
34
+ Assert . True ( command . CanExecute ( null ) ) ;
35
+ Assert . True ( command . CanExecute ( string . Empty ) ) ;
36
+ Assert . True ( command . CanExecute ( 0 ) ) ;
37
+ }
38
+
39
+ [ Fact ]
40
+ public void IntExecuteNullCanExecuteParameter ( )
41
+ {
42
+ // Arrange
43
+ var command = CommandFactory . Create < int > ( IntParameterTask , null ) ;
44
+
45
+ // Act
46
+
47
+ // Assert
48
+ Assert . True ( command . CanExecute ( null ) ) ;
49
+ Assert . True ( command . CanExecute ( string . Empty ) ) ;
50
+ Assert . True ( command . CanExecute ( 0 ) ) ;
51
+
52
+ command . Execute ( 0 ) ;
53
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . Execute ( null ) ) ;
54
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . Execute ( string . Empty ) ) ;
55
+ }
56
+
57
+ [ Fact ]
58
+ public void IntExecuteTrueCanExecuteParameter ( )
59
+ {
60
+ // Arrange
61
+ var command = CommandFactory . Create < int > ( IntParameterTask , CanExecuteTrue ) ;
62
+
63
+ // Act
64
+
65
+ // Assert
66
+ Assert . True ( command . CanExecute ( null ) ) ;
67
+ Assert . True ( command . CanExecute ( string . Empty ) ) ;
68
+ Assert . True ( command . CanExecute ( 0 ) ) ;
69
+ }
70
+
71
+ [ Fact ]
72
+ public void IntExecuteFalseCanExecuteParameter ( )
73
+ {
74
+ // Arrange
75
+ var command = CommandFactory . Create < int > ( IntParameterTask , CanExecuteFalse ) ;
76
+
77
+ // Act
78
+
79
+ // Assert
80
+ Assert . False ( command . CanExecute ( null ) ) ;
81
+ Assert . False ( command . CanExecute ( string . Empty ) ) ;
82
+ Assert . False ( command . CanExecute ( 0 ) ) ;
83
+ }
84
+
85
+ [ Fact ]
86
+ public void IntExecuteNullTypedCanExecuteParameter ( )
87
+ {
88
+ // Arrange
89
+ var command = CommandFactory . Create < int , bool > ( IntParameterTask , null ) ;
90
+
91
+ // Act
92
+
93
+ // Assert
94
+ Assert . True ( command . CanExecute ( true ) ) ;
95
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . CanExecute ( null ) ) ;
96
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . CanExecute ( string . Empty ) ) ;
97
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . CanExecute ( 0 ) ) ;
98
+ }
99
+
100
+ [ Fact ]
101
+ public void IntExecuteBoolCanExecuteParameter ( )
102
+ {
103
+ // Arrange
104
+ var command = CommandFactory . Create < int , bool > ( IntParameterTask , CanExecuteTrue ) ;
105
+
106
+ // Act
107
+
108
+ // Assert
109
+ Assert . True ( command . CanExecute ( true ) ) ;
110
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . CanExecute ( null ) ) ;
111
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . CanExecute ( string . Empty ) ) ;
112
+ Assert . Throws < InvalidCommandParameterException > ( ( ) => command . CanExecute ( 0 ) ) ;
113
+ }
114
+ }
115
+ }
0 commit comments