@@ -31,7 +31,8 @@ public RunContextAdapter(ICommandLineOptions commandLineOptions, IRunSettings ru
31
31
public RunContextAdapter ( ICommandLineOptions commandLineOptions , IRunSettings runSettings , TestNodeUid [ ] testNodeUids )
32
32
: this ( commandLineOptions , runSettings )
33
33
{
34
- FilterExpressionWrapper = new ( CreateFilter ( testNodeUids ) ) ;
34
+ // We assume that the UIDs we receive are TestCase.FullyQualifiedName values.
35
+ FilterExpressionWrapper = new ( string . Join ( "|" , testNodeUids . Select ( ConvertToFullyQualifiedNameFilterString ) ) ) ;
35
36
}
36
37
37
38
// NOTE: Always false as it's TPv2 oriented and so not applicable to TA.
@@ -61,57 +62,38 @@ public RunContextAdapter(ICommandLineOptions commandLineOptions, IRunSettings ru
61
62
/// <inheritdoc />
62
63
public IRunSettings ? RunSettings { get ; }
63
64
64
- // We use heuristic to understand if the filter should be a TestCaseId or FullyQualifiedName.
65
- // We know that in VSTest TestCaseId is a GUID and FullyQualifiedName is a string.
66
- private static string CreateFilter ( TestNodeUid [ ] testNodesUid )
65
+ private static string ConvertToFullyQualifiedNameFilterString ( TestNodeUid testNodeUid )
67
66
{
68
- StringBuilder filter = new ( ) ;
67
+ StringBuilder filterString = new ( "FullyQualifiedName=" ) ;
69
68
70
- for ( int i = 0 ; i < testNodesUid . Length ; i ++ )
69
+ for ( int i = 0 ; i < testNodeUid . Value . Length ; i ++ )
71
70
{
72
- if ( Guid . TryParse ( testNodesUid [ i ] . Value , out Guid guid ) )
71
+ char currentChar = testNodeUid . Value [ i ] ;
72
+ switch ( currentChar )
73
73
{
74
- filter . Append ( "Id=" ) ;
75
- filter . Append ( guid . ToString ( ) ) ;
76
- }
77
- else
78
- {
79
- filter . Append ( "FullyQualifiedName=" ) ;
80
- for ( int k = 0 ; i < testNodesUid [ i ] . Value . Length ; i ++ )
81
- {
82
- char currentChar = testNodesUid [ i ] . Value [ k ] ;
83
- switch ( currentChar )
74
+ case ' \\ ' :
75
+ case '(' :
76
+ case ')' :
77
+ case '&' :
78
+ case '|' :
79
+ case '=' :
80
+ case '!' :
81
+ case '~' :
82
+ // If the symbol is not escaped, add an escape character.
83
+ if ( i - 1 < 0 || testNodeUid . Value [ i - 1 ] != ' \\ ' )
84
84
{
85
- case '\\ ' :
86
- case '(' :
87
- case ')' :
88
- case '&' :
89
- case '|' :
90
- case '=' :
91
- case '!' :
92
- case '~' :
93
- // If the symbol is not escaped, add an escape character.
94
- if ( i - 1 < 0 || testNodesUid [ i ] . Value [ k - 1 ] != '\\ ' )
95
- {
96
- filter . Append ( '\\ ' ) ;
97
- }
98
-
99
- filter . Append ( currentChar ) ;
100
- break ;
101
-
102
- default :
103
- filter . Append ( currentChar ) ;
104
- break ;
85
+ filterString . Append ( '\\ ' ) ;
105
86
}
106
- }
107
- }
108
87
109
- if ( i != testNodesUid . Length - 1 )
110
- {
111
- filter . Append ( '|' ) ;
88
+ filterString . Append ( currentChar ) ;
89
+ break ;
90
+
91
+ default :
92
+ filterString . Append ( currentChar ) ;
93
+ break ;
112
94
}
113
95
}
114
96
115
- return filter . ToString ( ) ;
97
+ return filterString . ToString ( ) ;
116
98
}
117
99
}
0 commit comments