diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs index 4a801d1c4d..43cecb9491 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ObjectModelConverters.cs @@ -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[]), - owner: typeof(TestObject)); - /// /// Converts a VSTest to a Microsoft Testing Platform . /// @@ -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(TestCategoryProperty, defaultValue: null) is string[] mstestCategories) + foreach (KeyValuePair 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[]>(TraitsProperty, defaultValue: null) is KeyValuePair[] traits && - traits.Length > 0) - { - foreach (KeyValuePair trait in traits) + foreach (string category in categories) + { + testNode.Properties.Add(new TestMetadataProperty(category, string.Empty)); + } + } + else if (property.Value is KeyValuePair[] traits) { - testNode.Properties.Add(new TestMetadataProperty(trait.Key, trait.Value)); + foreach (KeyValuePair trait in traits) + { + testNode.Properties.Add(new TestMetadataProperty(trait.Key, trait.Value)); + } } } } diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs index 09809de7f8..14d64e2688 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs @@ -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(testCategoryProperty, ["category1"]); var testNode = testResult.ToTestNode(false, new NamedFeatureCapabilityWithVSTestProvider(), new ServerModeCommandLineOptions(), ClientInfo); @@ -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(testCategoryProperty, ["category1"]); var testNode = testResult.ToTestNode(true, new NamedFeatureCapabilityWithVSTestProvider(), new ServerModeCommandLineOptions(), ClientInfo);