@@ -117,41 +117,34 @@ public static List<TestCase> FindTestCases(string source)
117117 AppDomain . CurrentDomain . AssemblyResolve += App_AssemblyResolve ;
118118 AppDomain . CurrentDomain . Load ( test . GetName ( ) ) ;
119119
120- Type [ ] allTypes = test . GetTypes ( ) ;
120+ var allTypes = test . GetTypes ( ) . Where ( x => x . IsClass ) ;
121121 foreach ( var type in allTypes )
122122 {
123- if ( type . IsClass )
123+ if ( ! type . IsClass )
124124 {
125- var typeAttribs = type . GetCustomAttributes ( true ) ;
126- foreach ( var typeAttrib in typeAttribs )
125+ continue ;
126+ }
127+
128+ var typeAttribs = type . GetCustomAttributes ( true )
129+ . Where ( x => x . GetType ( ) . FullName == typeof ( TestClassAttribute ) . GetType ( ) . FullName ) ;
130+ foreach ( var typeAttrib in typeAttribs )
131+ {
132+ var methods = type . GetMethods ( ) ;
133+ // First we look at Setup
134+ foreach ( var method in methods )
127135 {
128- if ( typeof ( TestClassAttribute ) . FullName == typeAttrib . GetType ( ) . FullName )
136+ var attribs = method . GetCustomAttributes ( true ) ;
137+ attribs = Helper . RemoveTestMethodIfDataRowExists ( attribs ) ;
138+ var attribsToItterate = attribs . Where ( x => IsTestMethod ( x ) ) . ToArray ( ) ;
139+ for ( int i = 0 ; i < attribsToItterate . Length ; i ++ )
129140 {
130- var methods = type . GetMethods ( ) ;
131- // First we look at Setup
132- foreach ( var method in methods )
133- {
134- var attribs = method . GetCustomAttributes ( true ) ;
135- attribs = Helper . RemoveTestMethodIfDataRowExists ( attribs ) ;
136- for ( int i = 0 ; i < attribs . Length ; i ++ )
137- {
138- var attrib = attribs [ i ] ;
139-
140- if ( attrib . GetType ( ) . FullName == typeof ( SetupAttribute ) . FullName ||
141- attrib . GetType ( ) . FullName == typeof ( TestMethodAttribute ) . FullName ||
142- attrib . GetType ( ) . FullName == typeof ( CleanupAttribute ) . FullName ||
143- attrib . GetType ( ) . FullName == typeof ( DataRowAttribute ) . FullName )
144- {
145- var testCase = GetFileNameAndLineNumber ( allCsFils , type , method , attrib , i ) ;
146- testCase . Source = source ;
147- testCase . ExecutorUri = new Uri ( TestsConstants . NanoExecutor ) ;
148- testCase . FullyQualifiedName = $ "{ type . FullName } .{ testCase . DisplayName } ";
149- testCase . Traits . Add ( new Trait ( "Type" , attrib . GetType ( ) . Name . Replace ( "Attribute" , "" ) ) ) ;
150- testCases . Add ( testCase ) ;
151- }
152- }
153- }
154-
141+ var attrib = attribsToItterate [ i ] ;
142+ var testCase = GetFileNameAndLineNumber ( allCsFils , type , method , attrib , i ) ;
143+ testCase . Source = source ;
144+ testCase . ExecutorUri = new Uri ( TestsConstants . NanoExecutor ) ;
145+ testCase . FullyQualifiedName = $ "{ type . FullName } .{ testCase . DisplayName } ";
146+ testCase . Traits . Add ( new Trait ( "Type" , attrib . GetType ( ) . Name . Replace ( "Attribute" , "" ) ) ) ;
147+ testCases . Add ( testCase ) ;
155148 }
156149 }
157150 }
@@ -160,6 +153,33 @@ public static List<TestCase> FindTestCases(string source)
160153 return testCases ;
161154 }
162155
156+ private static bool IsTestMethod ( object attrib )
157+ {
158+ var attributeName = attrib . GetType ( ) . FullName ;
159+
160+ if ( attributeName == typeof ( SetupAttribute ) . FullName )
161+ {
162+ return true ;
163+ }
164+
165+ if ( attributeName == typeof ( TestMethodAttribute ) . FullName )
166+ {
167+ return true ;
168+ }
169+
170+ if ( attributeName == typeof ( CleanupAttribute ) . FullName )
171+ {
172+ return true ;
173+ }
174+
175+ if ( attributeName == typeof ( DataRowAttribute ) . FullName )
176+ {
177+ return true ;
178+ }
179+
180+ return false ;
181+ }
182+
163183 private static Assembly App_AssemblyResolve ( object sender , ResolveEventArgs args )
164184 {
165185 try
@@ -233,25 +253,29 @@ private static TestCase GetFileNameAndLineNumber(string[] csFiles, Type classNam
233253 {
234254 StreamReader sr = new StreamReader ( csFile ) ;
235255 var allFile = sr . ReadToEnd ( ) ;
236- if ( allFile . Contains ( $ "class { clName } ") )
256+ if ( ! allFile . Contains ( $ "class { clName } ") )
257+ {
258+ continue ;
259+ }
260+
261+ if ( ! allFile . Contains ( $ " { methodName } (") )
262+ {
263+ continue ;
264+ }
265+
266+ // We found it!
267+ int lineNum = 1 ;
268+ foreach ( var line in allFile . Split ( '\r ' ) )
237269 {
238- if ( allFile . Contains ( $ " { methodName } (") )
270+ if ( line . Contains ( $ " { methodName } (") )
239271 {
240- // We found it!
241- int lineNum = 1 ;
242- foreach ( var line in allFile . Split ( '\r ' ) )
243- {
244- if ( line . Contains ( $ " { methodName } (") )
245- {
246- flret . CodeFilePath = csFile ;
247- flret . LineNumber = lineNum ;
248- flret . DisplayName = Helper . GetTestDisplayName ( method , attribute , attributeIndex ) ;
249- return flret ;
250- }
251-
252- lineNum ++ ;
253- }
272+ flret . CodeFilePath = csFile ;
273+ flret . LineNumber = lineNum ;
274+ flret . DisplayName = Helper . GetTestDisplayName ( method , attribute , attributeIndex ) ;
275+ return flret ;
254276 }
277+
278+ lineNum ++ ;
255279 }
256280 }
257281
0 commit comments