Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ internal static class ObjectModelConverters
valueType: typeof(string),
owner: typeof(TestCase));

private static readonly TestProperty TestCategoryProperty = TestProperty.Register(
id: "MSTestDiscoverer.TestCategory",
label: "TestCategory",
valueType: typeof(string[]),
owner: typeof(TestCase));

private static readonly TestProperty TraitsProperty = TestProperty.Register(
id: "TestObject.Traits",
label: "Traits",
valueType: typeof(KeyValuePair<string, string>[]),
owner: typeof(TestObject));

/// <summary>
/// Converts a VSTest <see cref="TestCase"/> to a Microsoft Testing Platform <see cref="TestNode"/>.
/// </summary>
Expand Down Expand Up @@ -82,27 +70,33 @@ public static TestNode ToTestNode(this TestCase testCase, bool isTrxEnabled, INa

private static void CopyCategoryAndTraits(TestObject testCaseOrResult, TestNode testNode, bool isTrxEnabled)
{
// TPv2 is doing some special handling for MSTest... we should probably do the same.
// See https://github.com/microsoft/vstest/blob/main/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs#L66-L70
if (testCaseOrResult.GetPropertyValue<string[]>(TestCategoryProperty, defaultValue: null) is string[] mstestCategories)
foreach (KeyValuePair<TestProperty, object?> property in testCaseOrResult.GetProperties())
{
if (isTrxEnabled)
#pragma warning disable CS0618 // Type or member is obsolete
if ((property.Key.Attributes & TestPropertyAttributes.Trait) == 0)
#pragma warning restore CS0618 // Type or member is obsolete
{
testNode.Properties.Add(new TrxCategoriesProperty(mstestCategories));
continue;
}

foreach (string category in mstestCategories)
if (property.Value is string[] categories)
{
testNode.Properties.Add(new TestMetadataProperty(category, string.Empty));
}
}
if (isTrxEnabled)
{
testNode.Properties.Add(new TrxCategoriesProperty(categories));
}

if (testCaseOrResult.GetPropertyValue<KeyValuePair<string, string>[]>(TraitsProperty, defaultValue: null) is KeyValuePair<string, string>[] traits &&
traits.Length > 0)
{
foreach (KeyValuePair<string, string> trait in traits)
foreach (string category in categories)
{
testNode.Properties.Add(new TestMetadataProperty(category, string.Empty));
}
}
else if (property.Value is KeyValuePair<string, string>[] traits)
{
testNode.Properties.Add(new TestMetadataProperty(trait.Key, trait.Value));
foreach (KeyValuePair<string, string> trait in traits)
{
testNode.Properties.Add(new TestMetadataProperty(trait.Key, trait.Value));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public void ToTestNode_WhenTestResultOutcomeIsFailed_TestNodePropertiesContainFa
public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestProperty_TestNodePropertiesContainTheCategoryInTraits()
{
TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs"));
var testCategoryProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "Label", typeof(string[]), TestPropertyAttributes.None, typeof(TestCase));
#pragma warning disable CS0618 // Type or member is obsolete
var testCategoryProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "Label", typeof(string[]), TestPropertyAttributes.Trait, typeof(TestCase));
#pragma warning restore CS0618 // Type or member is obsolete
testResult.SetPropertyValue<string[]>(testCategoryProperty, ["category1"]);

var testNode = testResult.ToTestNode(false, new NamedFeatureCapabilityWithVSTestProvider(), new ServerModeCommandLineOptions(), ClientInfo);
Expand All @@ -91,7 +93,9 @@ public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestProperty
public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestPropertyWithTrxEnabled_TestNodePropertiesContainTrxCategoriesProperty()
{
TestResult testResult = new(new TestCase("assembly.class.SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs"));
var testCategoryProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "Label", typeof(string[]), TestPropertyAttributes.None, typeof(TestCase));
#pragma warning disable CS0618 // Type or member is obsolete
var testCategoryProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", "Label", typeof(string[]), TestPropertyAttributes.Trait, typeof(TestCase));
#pragma warning restore CS0618 // Type or member is obsolete
testResult.SetPropertyValue<string[]>(testCategoryProperty, ["category1"]);

var testNode = testResult.ToTestNode(true, new NamedFeatureCapabilityWithVSTestProvider(), new ServerModeCommandLineOptions(), ClientInfo);
Expand Down
Loading