Exemple #1
0
        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);
        }
        public static CliApplicationBuilder UseWebExample(this CliApplicationBuilder builder, WebCliConfiguration configuration)
        {
            builder.UseConsole(configuration.Console);

            if (configuration.LoggerDestination is not null)
            {
                builder.ConfigureLogging((cfg) =>
                {
                    cfg.ClearProviders();
                    cfg.AddWebLogger(configuration.LoggerDestination, (c) => c.LogLevel = LogLevel.Trace);
                    cfg.SetMinimumLevel(LogLevel.Trace);
                });
            }

            return(builder);
        }
        public static async ValueTask <(int exitCode, MemoryStreamWriter stdOut, MemoryStreamWriter stdErr)> BuildAndRunTestAsync(this CliApplicationBuilder applicationBuilder,
                                                                                                                                  ITestOutputHelper testOutput,
                                                                                                                                  IReadOnlyList <string> commandLineArguments,
                                                                                                                                  IReadOnlyDictionary <string, string> environmentVariables,
                                                                                                                                  bool isInputRedirected = true)
        {
            var(console, stdOut, stdErr) = VirtualConsole.CreateBuffered(isInputRedirected: isInputRedirected);

            CliApplication application = applicationBuilder.UseConsole(console)
                                         .Build();

            int exitCode = await application.RunAsync(commandLineArguments, environmentVariables);

            testOutput.WriteLine("Exit Code: {0}", exitCode);
            testOutput.Print(stdOut, stdErr);

            return(exitCode, stdOut, stdErr);
        }
Exemple #4
0
        public async Task Console_color_extensions_should_work_after_colors_reset()
        {
            // Arrange
            var builder = new CliApplicationBuilder().AddCommand <WithColorsAndResetCommand>();

            var(console, stdOut, stdErr) = VirtualAnsiConsole.CreateBuffered(isInputRedirected: false, isOutputRedirected: false, isErrorRedirected: false);

            CliApplication application = builder.UseConsole(console)
                                         .Build();

            int exitCode = await application.RunAsync("colors-with-reset", new Dictionary <string, string>());

            _output.WriteLine("Exit Code: {0}", exitCode);
            _output.Print(stdOut, stdErr);

            // Assert
            exitCode.Should().Be(ExitCodes.Success);
            stdOut.GetString().Should().Contain(WithColorsAndResetCommand.ExpectedOutputText);
            stdErr.GetString().Should().BeNullOrWhiteSpace();
        }