@@ -58,7 +58,8 @@ public void Test_ThrowHelper_Throw(Type exceptionType)
58
58
{
59
59
var methods = (
60
60
from method in typeof ( ThrowHelper ) . GetMethods ( BindingFlags . Public | BindingFlags . Static )
61
- where method . Name == $ "Throw{ exceptionType . Name } "
61
+ where method . Name == $ "Throw{ exceptionType . Name } " &&
62
+ ! method . IsGenericMethod
62
63
select method ) . ToArray ( ) ;
63
64
64
65
foreach ( var method in methods )
@@ -79,5 +80,66 @@ from parameter in method.GetParameters()
79
80
}
80
81
}
81
82
}
83
+
84
+ [ TestCategory ( "Guard" ) ]
85
+ [ TestMethod ]
86
+ [ DataRow ( typeof ( ArrayTypeMismatchException ) ) ]
87
+ [ DataRow ( typeof ( ArgumentException ) ) ]
88
+ [ DataRow ( typeof ( ArgumentNullException ) ) ]
89
+ [ DataRow ( typeof ( ArgumentOutOfRangeException ) ) ]
90
+ [ DataRow ( typeof ( COMException ) ) ]
91
+ [ DataRow ( typeof ( ExternalException ) ) ]
92
+ [ DataRow ( typeof ( FormatException ) ) ]
93
+ [ DataRow ( typeof ( InsufficientMemoryException ) ) ]
94
+ [ DataRow ( typeof ( InvalidDataException ) ) ]
95
+ [ DataRow ( typeof ( InvalidOperationException ) ) ]
96
+ [ DataRow ( typeof ( LockRecursionException ) ) ]
97
+ [ DataRow ( typeof ( MissingFieldException ) ) ]
98
+ [ DataRow ( typeof ( MissingMemberException ) ) ]
99
+ [ DataRow ( typeof ( MissingMethodException ) ) ]
100
+ [ DataRow ( typeof ( NotSupportedException ) ) ]
101
+ [ DataRow ( typeof ( ObjectDisposedException ) ) ]
102
+ [ DataRow ( typeof ( OperationCanceledException ) ) ]
103
+ [ DataRow ( typeof ( PlatformNotSupportedException ) ) ]
104
+ [ DataRow ( typeof ( SynchronizationLockException ) ) ]
105
+ [ DataRow ( typeof ( TimeoutException ) ) ]
106
+ [ DataRow ( typeof ( UnauthorizedAccessException ) ) ]
107
+ [ DataRow ( typeof ( Win32Exception ) ) ]
108
+ public void Test_ThrowHelper_Generic_Throw ( Type exceptionType )
109
+ {
110
+ var methods = (
111
+ from method in typeof ( ThrowHelper ) . GetMethods ( BindingFlags . Public | BindingFlags . Static )
112
+ where method . Name == $ "Throw{ exceptionType . Name } " &&
113
+ method . IsGenericMethod
114
+ select method ) . ToArray ( ) ;
115
+
116
+ foreach ( var method in methods )
117
+ {
118
+ // Prepare the parameters with the default value
119
+ var parameters = (
120
+ from parameter in method . GetParameters ( )
121
+ select DefaultValues [ parameter . ParameterType ] ) . ToArray ( ) ;
122
+
123
+ // Invoke with value type
124
+ try
125
+ {
126
+ method . MakeGenericMethod ( typeof ( int ) ) . Invoke ( null , parameters ) ;
127
+ }
128
+ catch ( TargetInvocationException e )
129
+ {
130
+ Assert . IsInstanceOfType ( e . InnerException , exceptionType ) ;
131
+ }
132
+
133
+ // Invoke with reference type
134
+ try
135
+ {
136
+ method . MakeGenericMethod ( typeof ( string ) ) . Invoke ( null , parameters ) ;
137
+ }
138
+ catch ( TargetInvocationException e )
139
+ {
140
+ Assert . IsInstanceOfType ( e . InnerException , exceptionType ) ;
141
+ }
142
+ }
143
+ }
82
144
}
83
145
}
0 commit comments