Exemplo n.º 1
0
        public async Task OperationCanceledReturnsExpectedOsCode()
        {
            var expectedCode = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                ? unchecked ((int)0xC000013A)
                : 130;
            var testConsole = new TestConsole(_output);
            var executeTask = CommandLineApplication.ExecuteAsync <DelayTilCanceledProgram>(testConsole, Array.Empty <string>());

            testConsole.RaiseCancelKeyPress();
            var exitCode = await executeTask;

            Assert.Equal(expectedCode, exitCode);
        }
Exemplo n.º 2
0
        public async Task ItExecutesAsyncMethod()
        {
            var console = new TestConsole(_output);
            var app     = new CommandLineApplication <ProgramWithAsyncOnExecute>(console);

            app.Conventions.UseOnExecuteMethodFromModel();
            var executeTask = app.ExecuteAsync(Array.Empty <string>());
            await ProgramWithAsyncOnExecute.ExecuteStarted.Task.ConfigureAwait(false);

            Assert.False(app.Model.Token.IsCancellationRequested);
            Assert.NotEqual(CancellationToken.None, app.Model.Token);
            console.RaiseCancelKeyPress();
            var result = await executeTask.ConfigureAwait(false);

            Assert.Equal(4, result);
            Assert.True(app.Model.Token.IsCancellationRequested);
        }
        public async Task OperationCanceledReturnsExpectedOsCode()
        {
            var expectedCode = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                ? unchecked ((int)0xC000013A)
                : 130;
            var testConsole = new TestConsole(_output);
            var app         = new CommandLineApplication(testConsole);

            app.OnExecuteAsync(async ct =>
            {
                await Task.Delay(-1, ct);
            });
            var executeTask = app.ExecuteAsync(Array.Empty <string>());

            testConsole.RaiseCancelKeyPress();
            var exitCode = await executeTask;

            Assert.Equal(expectedCode, exitCode);
        }