Skip to content
Merged
Changes from 2 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 @@ -85,12 +85,14 @@ public static TestNode ToResultTestNode(UnitTestElement element, FrameworkTestRe
private static TestNode CreateBaseTestNode(UnitTestElement element, bool isTrxEnabled, string? displayNameOverride)
{
TestMethod testMethod = element.TestMethod;
string testFullName = $"{testMethod.FullClassName}.{testMethod.Name}";

TestNode testNode = new()
{
Uid = new TestNodeUid(element.GetTestId().ToString()),
DisplayName = displayNameOverride ?? testMethod.DisplayName ?? testFullName,

// TestMethod.DisplayName is always initialized (the constructor sets it to displayName ?? name), so
// displayNameOverride is the only real fallback needed here.
DisplayName = displayNameOverride ?? testMethod.DisplayName,
};

AddCategoriesAndTraits(testNode, element, isTrxEnabled);
Expand Down Expand Up @@ -194,8 +196,9 @@ private static void AddTrxResultProperties(TestNode testNode, UnitTestElement el
}

TestMethod testMethod = element.TestMethod;
string testFullName = $"{testMethod.FullClassName}.{testMethod.Name}";
testNode.Properties.Add(new TrxTestDefinitionName(testMethod.DisplayName ?? testFullName));

// TestMethod.DisplayName is always initialized (constructor sets it to displayName ?? name).
testNode.Properties.Add(new TrxTestDefinitionName(testMethod.DisplayName));

TestMethodIdentifierProperty? testMethodIdentifierProperty = testNode.Properties.SingleOrDefault<TestMethodIdentifierProperty>();
if (testMethodIdentifierProperty is not null)
Expand All @@ -205,13 +208,15 @@ private static void AddTrxResultProperties(TestNode testNode, UnitTestElement el
? testMethodIdentifierProperty.TypeName
: $"{testMethodIdentifierProperty.Namespace}.{testMethodIdentifierProperty.TypeName}"));
}
else if (TryParseFullyQualifiedType(testFullName, out string? fullyQualifiedType))
else if (!StringEx.IsNullOrEmpty(testMethod.FullClassName))
{
testNode.Properties.Add(new TrxFullyQualifiedTypeNameProperty(fullyQualifiedType));
// FullClassName is the source of truth for the type name, so use it directly instead of re-parsing it out
// of a "FullClassName.Name" string.
testNode.Properties.Add(new TrxFullyQualifiedTypeNameProperty(testMethod.FullClassName));
Comment thread
Evangelink marked this conversation as resolved.
Resolved
}
else
{
throw new InvalidOperationException("Unable to parse fully qualified type name from test: " + testFullName);
throw new InvalidOperationException($"Unable to parse fully qualified type name from test: {testMethod.FullClassName}.{testMethod.Name}");
Comment thread
Copilot marked this conversation as resolved.
Resolved
}
}

Expand Down Expand Up @@ -291,22 +296,5 @@ private static void AddAttachments(TestNode testNode, FrameworkTestResult result
testNode.Properties.Add(new FileArtifactProperty(new FileInfo(pathToResultFile), Resource.AttachmentSetDisplayName, resultFile));
}
}

private static bool TryParseFullyQualifiedType(string fullyQualifiedName, [NotNullWhen(true)] out string? fullyQualifiedType)
{
fullyQualifiedType = null;

int openBracketIndex = fullyQualifiedName.IndexOf('(');
int lastDotIndexBeforeOpenBracket = openBracketIndex <= 0
? fullyQualifiedName.LastIndexOf('.')
: fullyQualifiedName.LastIndexOf('.', openBracketIndex - 1);
if (lastDotIndexBeforeOpenBracket <= 0)
{
return false;
}

fullyQualifiedType = fullyQualifiedName[..lastDotIndexBeforeOpenBracket];
return true;
}
}
#endif
Loading