@@ -34,18 +34,6 @@ internal static class ObjectModelConverters
34
34
valueType : typeof ( string ) ,
35
35
owner : typeof ( TestCase ) ) ;
36
36
37
- private static readonly TestProperty TestCategoryProperty = TestProperty . Register (
38
- id : "MSTestDiscoverer.TestCategory" ,
39
- label : "TestCategory" ,
40
- valueType : typeof ( string [ ] ) ,
41
- owner : typeof ( TestCase ) ) ;
42
-
43
- private static readonly TestProperty TraitsProperty = TestProperty . Register (
44
- id : "TestObject.Traits" ,
45
- label : "Traits" ,
46
- valueType : typeof ( KeyValuePair < string , string > [ ] ) ,
47
- owner : typeof ( TestObject ) ) ;
48
-
49
37
/// <summary>
50
38
/// Converts a VSTest <see cref="TestCase"/> to a Microsoft Testing Platform <see cref="TestNode"/>.
51
39
/// </summary>
@@ -82,27 +70,33 @@ public static TestNode ToTestNode(this TestCase testCase, bool isTrxEnabled, INa
82
70
83
71
private static void CopyCategoryAndTraits ( TestObject testCaseOrResult , TestNode testNode , bool isTrxEnabled )
84
72
{
85
- // TPv2 is doing some special handling for MSTest... we should probably do the same.
86
- // See https://github.com/microsoft/vstest/blob/main/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs#L66-L70
87
- if ( testCaseOrResult . GetPropertyValue < string [ ] > ( TestCategoryProperty , defaultValue : null ) is string [ ] mstestCategories )
73
+ foreach ( KeyValuePair < TestProperty , object ? > property in testCaseOrResult . GetProperties ( ) )
88
74
{
89
- if ( isTrxEnabled )
75
+ #pragma warning disable CS0618 // Type or member is obsolete
76
+ if ( ( property . Key . Attributes & TestPropertyAttributes . Trait ) == 0 )
77
+ #pragma warning restore CS0618 // Type or member is obsolete
90
78
{
91
- testNode . Properties . Add ( new TrxCategoriesProperty ( mstestCategories ) ) ;
79
+ continue ;
92
80
}
93
81
94
- foreach ( string category in mstestCategories )
82
+ if ( property . Value is string [ ] categories )
95
83
{
96
- testNode . Properties . Add ( new TestMetadataProperty ( category , string . Empty ) ) ;
97
- }
98
- }
84
+ if ( isTrxEnabled )
85
+ {
86
+ testNode . Properties . Add ( new TrxCategoriesProperty ( categories ) ) ;
87
+ }
99
88
100
- if ( testCaseOrResult . GetPropertyValue < KeyValuePair < string , string > [ ] > ( TraitsProperty , defaultValue : null ) is KeyValuePair < string , string > [ ] traits &&
101
- traits . Length > 0 )
102
- {
103
- foreach ( KeyValuePair < string , string > trait in traits )
89
+ foreach ( string category in categories )
90
+ {
91
+ testNode . Properties . Add ( new TestMetadataProperty ( category , string . Empty ) ) ;
92
+ }
93
+ }
94
+ else if ( property . Value is KeyValuePair < string , string > [ ] traits )
104
95
{
105
- testNode . Properties . Add ( new TestMetadataProperty ( trait . Key , trait . Value ) ) ;
96
+ foreach ( KeyValuePair < string , string > trait in traits )
97
+ {
98
+ testNode . Properties . Add ( new TestMetadataProperty ( trait . Key , trait . Value ) ) ;
99
+ }
106
100
}
107
101
}
108
102
}
0 commit comments