| File: SmokeTests.cs | Web Access |
| Project: src\tests\Aspire.Cli.EndToEnd.Tests\Aspire.Cli.EndToEnd.Tests.csproj (Aspire.Cli.EndToEnd.Tests) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Aspire.Cli.EndToEnd.Tests.Helpers; using Aspire.Cli.Tests.Utils; using Hex1b.Automation; using Hex1b.Input; using Xunit; namespace Aspire.Cli.EndToEnd.Tests; /// <summary> /// End-to-end tests for Aspire CLI run command (creating and launching projects). /// Each test class runs as a separate CI job for parallelization. /// </summary> public sealed class SmokeTests(ITestOutputHelper output) { [Fact] public async Task CreateAndRunAspireStarterProject() { var repoRoot = CliE2ETestHelpers.GetRepoRoot(); var installMode = CliE2ETestHelpers.DetectDockerInstallMode(repoRoot); var workspace = TemporaryWorkspace.Create(output); using var terminal = CliE2ETestHelpers.CreateDockerTestTerminal(repoRoot, installMode, output, mountDockerSocket: true, workspace: workspace); var pendingRun = terminal.RunAsync(TestContext.Current.CancellationToken); var counter = new SequenceCounter(); var auto = new Hex1bTerminalAutomator(terminal, defaultTimeout: TimeSpan.FromSeconds(500)); // Prepare Docker environment (prompt counting, umask, env vars) await auto.PrepareDockerEnvironmentAsync(counter, workspace); // Install the Aspire CLI await auto.InstallAspireCliInDockerAsync(installMode, counter); // Create a new project using aspire new await auto.AspireNewAsync("AspireStarterApp", counter); // Run the project with aspire run await auto.TypeAsync("aspire run"); await auto.EnterAsync(); // Regression test for https://github.com/microsoft/aspire/issues/13971 // If the apphost selection prompt appears, it means multiple apphosts were // incorrectly detected (e.g., AppHost.cs was incorrectly treated as a single-file apphost) await auto.WaitUntilAsync(s => { if (s.ContainsText("Select an apphost to use:")) { throw new InvalidOperationException( "Unexpected apphost selection prompt detected! " + "This indicates multiple apphosts were incorrectly detected."); } return s.ContainsText("Press CTRL+C to stop the apphost and exit."); }, timeout: TimeSpan.FromMinutes(2), description: "Press CTRL+C message (aspire run started)"); // Stop the running apphost with Ctrl+C await auto.Ctrl().KeyAsync(Hex1bKey.C); await auto.WaitForSuccessPromptAsync(counter); // Exit the shell await auto.TypeAsync("exit"); await auto.EnterAsync(); await pendingRun; } }