@@ -13,6 +13,8 @@ namespace nanoFramework.TestFramework
1313 /// </summary>
1414 public static class Helper
1515 {
16+ private delegate bool AnyDelegateType ( object source ) ;
17+
1618 private static string GetJoinedParams ( object [ ] data )
1719 {
1820 var returnString = string . Empty ;
@@ -28,24 +30,64 @@ private static string GetJoinedParams(object[] data)
2830 return returnString . Substring ( 0 , returnString . Length - 4 ) ;
2931 }
3032
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+
3144 /// <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 "/>.
3346 /// </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 )
3649 {
3750 // Comparing via full name, because attribute parameter is from "TestFramework.dll"
3851 // and current type TestCaseAttribute is in scope of "TestAdapter" due to shared project
3952 // The same reason - reflection to get value
4053 if ( attribute . GetType ( ) . FullName == typeof ( DataRowAttribute ) . FullName )
4154 {
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 } )";
4656 }
4757
4858 return method . Name ;
4959 }
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+ }
5092 }
5193}
0 commit comments