Skip to content

Commit 419a2d3

Browse files
committed
Revert non-playground changes
1 parent a38db90 commit 419a2d3

File tree

4 files changed

+43
-45
lines changed

4 files changed

+43
-45
lines changed

src/Adapter/MSTest.TestAdapter/TestMethodFilter.cs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal TestMethodFilter()
2525
[Constants.PriorityProperty.Label] = Constants.PriorityProperty,
2626
[TestCaseProperties.FullyQualifiedName.Label] = TestCaseProperties.FullyQualifiedName,
2727
[TestCaseProperties.DisplayName.Label] = TestCaseProperties.DisplayName,
28-
[TestCaseProperties.Id.Label] = TestCaseProperties.Id,
2928
[Constants.TestClassNameProperty.Label] = Constants.TestClassNameProperty,
3029
};
3130
}

src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static class ObjectModelConverters
3030
public static TestNode ToTestNode(this TestCase testCase, bool isTrxEnabled, ClientInfo client)
3131
{
3232
string testNodeUid = testCase.GetPropertyValue<string>(TestNodeUidProperty, null)
33-
?? testCase.Id.ToString();
33+
?? testCase.FullyQualifiedName;
3434

3535
TestNode testNode = new()
3636
{

src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/RunContextAdapter.cs

+25-43
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public RunContextAdapter(ICommandLineOptions commandLineOptions, IRunSettings ru
3131
public RunContextAdapter(ICommandLineOptions commandLineOptions, IRunSettings runSettings, TestNodeUid[] testNodeUids)
3232
: this(commandLineOptions, runSettings)
3333
{
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)));
3536
}
3637

3738
// NOTE: Always false as it's TPv2 oriented and so not applicable to TA.
@@ -61,57 +62,38 @@ public RunContextAdapter(ICommandLineOptions commandLineOptions, IRunSettings ru
6162
/// <inheritdoc />
6263
public IRunSettings? RunSettings { get; }
6364

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)
6766
{
68-
StringBuilder filter = new();
67+
StringBuilder filterString = new("FullyQualifiedName=");
6968

70-
for (int i = 0; i < testNodesUid.Length; i++)
69+
for (int i = 0; i < testNodeUid.Value.Length; i++)
7170
{
72-
if (Guid.TryParse(testNodesUid[i].Value, out Guid guid))
71+
char currentChar = testNodeUid.Value[i];
72+
switch (currentChar)
7373
{
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] != '\\')
8484
{
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('\\');
10586
}
106-
}
107-
}
10887

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;
11294
}
11395
}
11496

115-
return filter.ToString();
97+
return filterString.ToString();
11698
}
11799
}

test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ public ObjectModelConvertersTests(ITestExecutionContext testExecutionContext)
2020
{
2121
}
2222

23+
public void ToTestNode_WhenTestCaseHasTestNodeUidProperty_TestNodeUidUsesIt()
24+
{
25+
TestCase testCase = new("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs");
26+
testCase.SetPropertyValue(ObjectModelConverters.TestNodeUidProperty, "SomeUid");
27+
var testNode = testCase.ToTestNode(false, TestClient);
28+
29+
Assert.AreEqual("SomeUid", testNode.Uid.Value);
30+
}
31+
32+
public void ToTestNode_WhenTestCaseHasNoTestNodeUidProperty_TestNodeUidUsesFqn()
33+
{
34+
TestCase testCase = new("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs");
35+
var testNode = testCase.ToTestNode(false, TestClient);
36+
37+
Assert.AreEqual("SomeFqn", testNode.Uid.Value);
38+
}
39+
2340
public void ToTestNode_WhenTestCaseHasDisplayName_TestNodeDisplayNameUsesIt()
2441
{
2542
TestCase testCase = new("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")

0 commit comments

Comments
 (0)