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
22 changes: 21 additions & 1 deletion tests/Aspire.Cli.EndToEnd.Tests/Helpers/CliE2ETestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ internal static string GetTestResultsRecordingPath(string testName)
return Hex1bTestHelpers.GetTestResultsRecordingPath(testName, "aspire-cli-e2e");
}

/// <summary>
/// Resolves the test method name for naming a recording file. See
/// <see cref="Hex1bTestHelpers.ResolveTestMethodName"/> for the full rationale.
/// </summary>
private static string ResolveTestMethodName(string callerMemberName)
=> Hex1bTestHelpers.ResolveTestMethodName(callerMemberName);

/// <summary>
/// Creates a headless Hex1b terminal configured for E2E testing with asciinema recording.
/// Uses default dimensions of 160x48 unless overridden.
Expand All @@ -103,7 +110,14 @@ internal static string GetTestResultsRecordingPath(string testName)
/// <returns>A configured <see cref="Hex1bTerminal"/> instance. Caller is responsible for disposal.</returns>
internal static Hex1bTerminal CreateTestTerminal(int width = 160, int height = 48, [CallerMemberName] string testName = "")
{
var recordingPath = GetTestResultsRecordingPath(testName);
// Prefer the xUnit-reported test method name so that when a [Fact]/[Theory]
// delegates into a private helper (e.g. *Core methods), the .cast file is
// still named after the public test the TRX records an outcome for. Without
// this, `[CallerMemberName]` captures the helper, the recording filename has
// no matching TRX entry, and the recording-comment workflow tags the test as
// "Unknown".
var resolvedTestName = ResolveTestMethodName(testName);
var recordingPath = GetTestResultsRecordingPath(resolvedTestName);
RegisterCaptureFile("recording.cast", recordingPath);
return Hex1bTerminal.CreateBuilder()
.WithHeadless()
Expand Down Expand Up @@ -162,6 +176,9 @@ internal static Hex1bTerminal CreateDockerTestTerminal(
int height = 48,
[CallerMemberName] string testName = "")
{
// See CreateTestTerminal above for why we prefer the xUnit-reported test
// method name over `[CallerMemberName]`.
testName = ResolveTestMethodName(testName);
var recordingPath = GetTestResultsRecordingPath(testName);
RegisterCaptureFile("recording.cast", recordingPath);
var dockerfilePath = GetDockerfilePath(repoRoot, variant);
Expand Down Expand Up @@ -334,6 +351,9 @@ internal static Hex1bTerminal CreatePodmanDockerTestTerminal(
int height = 48,
[CallerMemberName] string testName = "")
{
// See CreateTestTerminal above for why we prefer the xUnit-reported test
// method name over `[CallerMemberName]`.
testName = ResolveTestMethodName(testName);
var recordingPath = GetTestResultsRecordingPath(testName);
RegisterCaptureFile("recording.cast", recordingPath);

Expand Down
21 changes: 21 additions & 0 deletions tests/Shared/Hex1bTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ internal static Hex1bTerminal CreateTestTerminal(
int height = 48,
[CallerMemberName] string testName = "")
{
// Prefer the xUnit-reported test method name so that when a [Fact]/[Theory]
// delegates into a private helper (e.g. *Core methods), the .cast file is
// still named after the public test the TRX records an outcome for. The CLI
// E2E recording-comment workflow joins .cast files to TRX outcomes by name;
// when the helper name leaks in via `[CallerMemberName]`, no TRX entry
// matches and the test ends up tagged "Unknown" on every PR.
testName = ResolveTestMethodName(testName);
var recordingPath = GetTestResultsRecordingPath(testName, localSubDir);

var builder = Hex1bTerminal.CreateBuilder()
Expand Down Expand Up @@ -128,6 +135,20 @@ internal static string GetTestResultsRecordingPath(string testName, string local
return Path.Combine(recordingsDir, $"{testName}.cast");
}

/// <summary>
/// Resolves the test method name for naming a recording file. Prefers the xUnit-reported
/// <c>TestContext.Current.TestCase.TestMethodName</c> when running inside a live test
/// context, so a recording created from inside a private helper still gets named after
/// the public <c>[Fact]</c>/<c>[Theory]</c> that the TRX records an outcome for. Falls
/// back to the <see cref="CallerMemberNameAttribute"/>-supplied name when no test context
/// is available.
/// </summary>
internal static string ResolveTestMethodName(string callerMemberName)
{
var fromXunit = Xunit.TestContext.Current?.TestCase?.TestMethodName;
return !string.IsNullOrEmpty(fromXunit) ? fromXunit : callerMemberName;
}

/// <summary>
/// Waits for a successful command prompt with the expected sequence number.
/// </summary>
Expand Down
Loading