Beispiel #1
0
        public async Task RunAsync_Cancellation_Test()
        {
            // Arrange
            using var console = new VirtualConsole();

            var application = new CliApplicationBuilder()
                              .AddCommand(typeof(CancellableCommand))
                              .UseConsole(console)
                              .Build();

            var commandLineArguments = new[] { "cancel" };
            var environmentVariables = new Dictionary <string, string>();

            // Act
            console.CancelAfter(TimeSpan.FromSeconds(0.2));

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

            var stdOut = console.ReadOutputString().Trim();
            var stdErr = console.ReadErrorString().Trim();

            // Assert
            exitCode.Should().NotBe(0);
            stdOut.Should().BeNullOrWhiteSpace();
            stdErr.Should().NotBeNullOrWhiteSpace();

            Console.WriteLine(stdErr);
        }