@@ -52,52 +52,52 @@ internal TypeValidator(ReflectHelper reflectHelper, bool discoverInternals)
52
52
/// <returns>Return true if it is a valid test class.</returns>
53
53
internal virtual bool IsValidTestClass ( Type type , ICollection < string > warnings )
54
54
{
55
- if ( type . GetTypeInfo ( ) . IsClass &&
56
- ( _reflectHelper . IsAttributeDefined ( type , typeof ( TestClassAttribute ) , false ) ||
57
- _reflectHelper . HasAttributeDerivedFrom ( type , typeof ( TestClassAttribute ) , false ) ) )
55
+ if ( ! type . GetTypeInfo ( ) . IsClass
56
+ || ( ! _reflectHelper . IsAttributeDefined ( type , typeof ( TestClassAttribute ) , false )
57
+ && ! _reflectHelper . HasAttributeDerivedFrom ( type , typeof ( TestClassAttribute ) , false ) ) )
58
58
{
59
- // inaccessible class
60
- if ( ! TypeHasValidAccessibility ( type . GetTypeInfo ( ) , _discoverInternals ) )
61
- {
62
- var warning = string . Format ( CultureInfo . CurrentCulture , Resource . UTA_ErrorNonPublicTestClass , type . FullName ) ;
63
- warnings . Add ( warning ) ;
64
- return false ;
65
- }
59
+ return false ;
60
+ }
66
61
67
- // Generic class
68
- if ( type . GetTypeInfo ( ) . IsGenericTypeDefinition && ! type . GetTypeInfo ( ) . IsAbstract )
69
- {
70
- // In IDE generic classes that are not abstract are treated as not runnable. Keep consistence.
71
- var warning = string . Format ( CultureInfo . CurrentCulture , Resource . UTA_ErrorNonPublicTestClass , type . FullName ) ;
72
- warnings . Add ( warning ) ;
73
- return false ;
74
- }
62
+ // inaccessible class
63
+ if ( ! TypeHasValidAccessibility ( type . GetTypeInfo ( ) , _discoverInternals ) )
64
+ {
65
+ var warning = string . Format ( CultureInfo . CurrentCulture , Resource . UTA_ErrorNonPublicTestClass , type . FullName ) ;
66
+ warnings . Add ( warning ) ;
67
+ return false ;
68
+ }
75
69
76
- // Class is not valid if the testContext property is incorrect
77
- if ( ! HasCorrectTestContextSignature ( type ) )
78
- {
79
- var warning = string . Format ( CultureInfo . CurrentCulture , Resource . UTA_ErrorInValidTestContextSignature , type . FullName ) ;
80
- warnings . Add ( warning ) ;
81
- return false ;
82
- }
70
+ // Generic class
71
+ if ( type . GetTypeInfo ( ) . IsGenericTypeDefinition && ! type . GetTypeInfo ( ) . IsAbstract )
72
+ {
73
+ // In IDE generic classes that are not abstract are treated as not runnable. Keep consistence.
74
+ var warning = string . Format ( CultureInfo . CurrentCulture , Resource . UTA_ErrorNonPublicTestClass , type . FullName ) ;
75
+ warnings . Add ( warning ) ;
76
+ return false ;
77
+ }
83
78
84
- // Abstract test classes can be base classes for derived test classes.
85
- // There is no way to see if there are derived test classes.
86
- // Thus if a test class is abstract, just ignore all test methods from it
87
- // (they will be visible in derived classes). No warnings (such as test method, deployment item,
88
- // etc attribute is defined on the class) will be generated for this class:
89
- // What we do is:
90
- // - report the class as "not valid" test class. This will cause to skip enumerating tests from it.
91
- // - Do not generate warnings/do not create NOT RUNNABLE tests.
92
- if ( type . GetTypeInfo ( ) . IsAbstract )
93
- {
94
- return false ;
95
- }
79
+ // Class is not valid if the testContext property is incorrect
80
+ if ( ! HasCorrectTestContextSignature ( type ) )
81
+ {
82
+ var warning = string . Format ( CultureInfo . CurrentCulture , Resource . UTA_ErrorInValidTestContextSignature , type . FullName ) ;
83
+ warnings . Add ( warning ) ;
84
+ return false ;
85
+ }
96
86
97
- return true ;
87
+ // Abstract test classes can be base classes for derived test classes.
88
+ // There is no way to see if there are derived test classes.
89
+ // Thus if a test class is abstract, just ignore all test methods from it
90
+ // (they will be visible in derived classes). No warnings (such as test method, deployment item,
91
+ // etc attribute is defined on the class) will be generated for this class:
92
+ // What we do is:
93
+ // - report the class as "not valid" test class. This will cause to skip enumerating tests from it.
94
+ // - Do not generate warnings/do not create NOT RUNNABLE tests.
95
+ if ( type . GetTypeInfo ( ) . IsAbstract )
96
+ {
97
+ return false ;
98
98
}
99
99
100
- return false ;
100
+ return true ;
101
101
}
102
102
103
103
/// <summary>
@@ -159,56 +159,56 @@ internal static bool TypeHasValidAccessibility(TypeInfo type, bool discoverInter
159
159
}
160
160
161
161
// Either the type is not public or it is a nested class and itself or one of its containers is not public.
162
- if ( type . IsNested )
162
+ if ( ! type . IsNested )
163
163
{
164
- // Assembly is CLR term for internal visibility:
165
- // Private == private,
166
- // FamilyANDAssembly == private protected,
167
- // Assembly == internal,
168
- // Family == protected,
169
- // FamilyORAssembly == protected internal,
170
- // Public == public.
171
- // So this reads IsNestedInternal || IsNestedPublic:
172
- var isNestedPublicOrInternal = type . IsNestedAssembly || type . IsNestedPublic ;
173
-
174
- if ( ! isNestedPublicOrInternal )
175
- {
176
- // This type is nested, but is not public or internal.
177
- return false ;
178
- }
164
+ // The type is not public and is not nested. Non-nested types can be only public or internal
165
+ // so this type must be internal.
166
+ return true ;
167
+ }
179
168
180
- // The type itself is nested and is public, or internal, but could be in hierarchy of types
181
- // where some of the parent types is private (or other modifier that is not public and is not internal)
182
- // if we looked for just public types we could just look at IsVisible, but internal type nested in internal type
183
- // is not Visible, so we need to check all the parents and make sure they are all either public or internal.
184
- var parentsArePublicOrInternal = true ;
185
- var declaringType = type . DeclaringType ;
186
- while ( declaringType != null && parentsArePublicOrInternal )
187
- {
188
- var declaringTypeIsPublicOrInternal =
169
+ // Assembly is CLR term for internal visibility:
170
+ // Private == private,
171
+ // FamilyANDAssembly == private protected,
172
+ // Assembly == internal,
173
+ // Family == protected,
174
+ // FamilyORAssembly == protected internal,
175
+ // Public == public.
176
+ // So this reads IsNestedInternal || IsNestedPublic:
177
+ var isNestedPublicOrInternal = type . IsNestedAssembly || type . IsNestedPublic ;
178
+
179
+ if ( ! isNestedPublicOrInternal )
180
+ {
181
+ // This type is nested, but is not public or internal.
182
+ return false ;
183
+ }
189
184
190
- // Declaring type is non-nested type, and we are looking for internal or public, which are the only
191
- // two valid options that non-nested type can be.
192
- ! declaringType . IsNested
185
+ // The type itself is nested and is public, or internal, but could be in hierarchy of types
186
+ // where some of the parent types is private (or other modifier that is not public and is not internal)
187
+ // if we looked for just public types we could just look at IsVisible, but internal type nested in internal type
188
+ // is not Visible, so we need to check all the parents and make sure they are all either public or internal.
189
+ var parentsArePublicOrInternal = true ;
190
+ var declaringType = type . DeclaringType ;
191
+ while ( declaringType != null && parentsArePublicOrInternal )
192
+ {
193
+ var declaringTypeIsPublicOrInternal =
193
194
194
- // Or the type is nested internal, or nested public type, but not any other
195
- // like nested protected internal type, or nested private type.
196
- || declaringType . GetTypeInfo ( ) . IsNestedAssembly || declaringType . GetTypeInfo ( ) . IsNestedPublic ;
195
+ // Declaring type is non- nested type, and we are looking for internal or public, which are the only
196
+ // two valid options that non- nested type can be .
197
+ ! declaringType . IsNested
197
198
198
- if ( ! declaringTypeIsPublicOrInternal )
199
- {
200
- parentsArePublicOrInternal = false ;
201
- break ;
202
- }
199
+ // Or the type is nested internal, or nested public type, but not any other
200
+ // like nested protected internal type, or nested private type.
201
+ || declaringType . GetTypeInfo ( ) . IsNestedAssembly || declaringType . GetTypeInfo ( ) . IsNestedPublic ;
203
202
204
- declaringType = declaringType . DeclaringType ;
203
+ if ( ! declaringTypeIsPublicOrInternal )
204
+ {
205
+ parentsArePublicOrInternal = false ;
206
+ break ;
205
207
}
206
208
207
- return parentsArePublicOrInternal ;
209
+ declaringType = declaringType . DeclaringType ;
208
210
}
209
211
210
- // The type is not public and is not nested. Non-nested types can be only public or internal
211
- // so this type must be internal.
212
- return true ;
212
+ return parentsArePublicOrInternal ;
213
213
}
214
214
}
0 commit comments