@@ -13,6 +13,8 @@ namespace nanoFramework.TestFramework
13
13
/// </summary>
14
14
public static class Helper
15
15
{
16
+ private delegate bool AnyDelegateType ( object source ) ;
17
+
16
18
private static string GetJoinedParams ( object [ ] data )
17
19
{
18
20
var returnString = string . Empty ;
@@ -28,24 +30,64 @@ private static string GetJoinedParams(object[] data)
28
30
return returnString . Substring ( 0 , returnString . Length - 4 ) ;
29
31
}
30
32
33
+ private static bool Any ( this object [ ] array , AnyDelegateType predicate )
34
+ {
35
+ foreach ( var item in array )
36
+ {
37
+ if ( predicate ( item ) )
38
+ return true ;
39
+ }
40
+
41
+ return false ;
42
+ }
43
+
31
44
/// <summary>
32
- /// Generates test display name based on passed <paramref name="method"/> and <paramref name="attribute "/>.
45
+ /// Generates test display name based on passed <paramref name="method"/>, <paramref name="attribute"/> and <paramref name="attributeIndex "/>.
33
46
/// </summary>
34
- /// <returns>Returns method name with parameters if passed attribute is of DataRow type</returns>
35
- public static string GetTestDisplayName ( MethodInfo method , object attribute )
47
+ /// <returns>Returns method name with attributeIndex if passed attribute is of DataRow type</returns>
48
+ public static string GetTestDisplayName ( MethodInfo method , object attribute , int attributeIndex )
36
49
{
37
50
// Comparing via full name, because attribute parameter is from "TestFramework.dll"
38
51
// and current type TestCaseAttribute is in scope of "TestAdapter" due to shared project
39
52
// The same reason - reflection to get value
40
53
if ( attribute . GetType ( ) . FullName == typeof ( DataRowAttribute ) . FullName )
41
54
{
42
- var methodParameters = ( object [ ] ) attribute . GetType ( )
43
- . GetMethod ( $ "get_{ nameof ( DataRowAttribute . MethodParameters ) } ") . Invoke ( attribute , null ) ;
44
-
45
- return $ "{ method . Name } - (params: { GetJoinedParams ( methodParameters ) } )";
55
+ return $ "{ method . Name } (index { attributeIndex } )";
46
56
}
47
57
48
58
return method . Name ;
49
59
}
60
+
61
+ /// <summary>
62
+ /// Removes "TestMethod" attribute from array if "DataRow" attribute exists in the same array
63
+ /// </summary>
64
+ /// <param name="attribs">Array of attributes to check</param>
65
+ /// <returns>New array without TestMethod if DataRow exists, if not the same array</returns>
66
+ public static object [ ] RemoveTestMethodIfDataRowExists ( object [ ] attribs )
67
+ {
68
+ //If method attribute contains TestMethod and DataRow - add only DataRow
69
+ if ( attribs . Any ( x => x . GetType ( ) . FullName == typeof ( TestMethodAttribute ) . FullName ) &&
70
+ attribs . Any ( x => x . GetType ( ) . FullName == typeof ( DataRowAttribute ) . FullName ) )
71
+ {
72
+ var newAttribs = new object [ attribs . Length - 1 ] ;
73
+
74
+ var newAttribsIndex = 0 ;
75
+ for ( int i = 0 ; i < attribs . Length ; i ++ )
76
+ {
77
+ var attrib = attribs [ i ] ;
78
+ if ( attrib . GetType ( ) . FullName == typeof ( TestMethodAttribute ) . FullName )
79
+ {
80
+ continue ;
81
+ }
82
+
83
+ newAttribs [ newAttribsIndex ] = attrib ;
84
+ newAttribsIndex ++ ;
85
+ }
86
+
87
+ return newAttribs ;
88
+ }
89
+
90
+ return attribs ;
91
+ }
50
92
}
51
93
}
0 commit comments