@@ -58,7 +58,8 @@ public void Test_ThrowHelper_Throw(Type exceptionType)
5858 {
5959 var methods = (
6060 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
6263 select method ) . ToArray ( ) ;
6364
6465 foreach ( var method in methods )
@@ -79,5 +80,66 @@ from parameter in method.GetParameters()
7980 }
8081 }
8182 }
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+ }
82144 }
83145}
0 commit comments