public static async ValueTask <(int exitCode, MemoryStreamWriter stdOut, MemoryStreamWriter stdErr)> BuildAndRunTestAsync(this CliApplicationBuilder applicationBuilder, ITestOutputHelper testOutput, string commandLine, IReadOnlyDictionary <string, string> environmentVariables, bool containsExecutable = false, bool isInputRedirected = true, string?input = null) { var(console, stdIn, stdOut, stdErr) = VirtualConsole.CreateBufferedWithInput(isInputRedirected: isInputRedirected); CliApplication application = applicationBuilder.UseConsole(console) .Build(); if (input is not null) { stdIn.WriteString(input.TrimEnd('\r') + "\rexit\r"); } int exitCode = await application.RunAsync(commandLine, environmentVariables, containsExecutable); testOutput.WriteLine("Exit Code: {0}", exitCode); testOutput.Print(stdOut, stdErr); return(exitCode, stdOut, stdErr); }