@@ -85,12 +85,14 @@ public static TestNode ToResultTestNode(UnitTestElement element, FrameworkTestRe
8585 private static TestNode CreateBaseTestNode ( UnitTestElement element , bool isTrxEnabled , string ? displayNameOverride )
8686 {
8787 TestMethod testMethod = element . TestMethod ;
88- string testFullName = $ "{ testMethod . FullClassName } .{ testMethod . Name } ";
8988
9089 TestNode testNode = new ( )
9190 {
9291 Uid = new TestNodeUid ( element . GetTestId ( ) . ToString ( ) ) ,
93- DisplayName = displayNameOverride ?? testMethod . DisplayName ?? testFullName ,
92+
93+ // TestMethod.DisplayName is always initialized (the constructor sets it to displayName ?? name), so
94+ // displayNameOverride is the only real fallback needed here.
95+ DisplayName = displayNameOverride ?? testMethod . DisplayName ,
9496 } ;
9597
9698 AddCategoriesAndTraits ( testNode , element , isTrxEnabled ) ;
@@ -194,8 +196,9 @@ private static void AddTrxResultProperties(TestNode testNode, UnitTestElement el
194196 }
195197
196198 TestMethod testMethod = element . TestMethod ;
197- string testFullName = $ "{ testMethod . FullClassName } .{ testMethod . Name } ";
198- testNode . Properties . Add ( new TrxTestDefinitionName ( testMethod . DisplayName ?? testFullName ) ) ;
199+
200+ // TestMethod.DisplayName is always initialized (constructor sets it to displayName ?? name).
201+ testNode . Properties . Add ( new TrxTestDefinitionName ( testMethod . DisplayName ) ) ;
199202
200203 TestMethodIdentifierProperty ? testMethodIdentifierProperty = testNode . Properties . SingleOrDefault < TestMethodIdentifierProperty > ( ) ;
201204 if ( testMethodIdentifierProperty is not null )
@@ -205,13 +208,15 @@ private static void AddTrxResultProperties(TestNode testNode, UnitTestElement el
205208 ? testMethodIdentifierProperty . TypeName
206209 : $ "{ testMethodIdentifierProperty . Namespace } .{ testMethodIdentifierProperty . TypeName } ") ) ;
207210 }
208- else if ( TryParseFullyQualifiedType ( testFullName , out string ? fullyQualifiedType ) )
211+ else if ( ! StringEx . IsNullOrEmpty ( testMethod . FullClassName ) )
209212 {
210- testNode . Properties . Add ( new TrxFullyQualifiedTypeNameProperty ( fullyQualifiedType ) ) ;
213+ // FullClassName is the source of truth for the type name, so use it directly instead of re-parsing it out
214+ // of a "FullClassName.Name" string.
215+ testNode . Properties . Add ( new TrxFullyQualifiedTypeNameProperty ( testMethod . FullClassName ) ) ;
211216 }
212217 else
213218 {
214- throw new InvalidOperationException ( "Unable to parse fully qualified type name from test: " + testFullName ) ;
219+ throw new InvalidOperationException ( $ "The test method ' { testMethod . Name } ' does not have a fully qualified class name." ) ;
215220 }
216221 }
217222
@@ -291,22 +296,5 @@ private static void AddAttachments(TestNode testNode, FrameworkTestResult result
291296 testNode . Properties . Add ( new FileArtifactProperty ( new FileInfo ( pathToResultFile ) , Resource . AttachmentSetDisplayName , resultFile ) ) ;
292297 }
293298 }
294-
295- private static bool TryParseFullyQualifiedType ( string fullyQualifiedName , [ NotNullWhen ( true ) ] out string ? fullyQualifiedType )
296- {
297- fullyQualifiedType = null ;
298-
299- int openBracketIndex = fullyQualifiedName . IndexOf ( '(' ) ;
300- int lastDotIndexBeforeOpenBracket = openBracketIndex <= 0
301- ? fullyQualifiedName . LastIndexOf ( '.' )
302- : fullyQualifiedName . LastIndexOf ( '.' , openBracketIndex - 1 ) ;
303- if ( lastDotIndexBeforeOpenBracket <= 0 )
304- {
305- return false ;
306- }
307-
308- fullyQualifiedType = fullyQualifiedName [ .. lastDotIndexBeforeOpenBracket ] ;
309- return true ;
310- }
311299}
312300#endif
0 commit comments