Files
CliFx/CliFx.Tests/Commands/CancellableCommand.cs
Alexey Golub 3831cfc7c0 Get rid of internal tests
Move all tests to e2e+ level
2020-08-19 22:31:09 +03:00

31 lines
819 B
C#

using System;
using System.Threading.Tasks;
using CliFx.Attributes;
namespace CliFx.Tests.Commands
{
[Command("cmd")]
public class CancellableCommand : ICommand
{
public const string CompletionOutputText = "Finished";
public const string CancellationOutputText = "Canceled";
public async ValueTask ExecuteAsync(IConsole console)
{
try
{
await Task.Delay(
TimeSpan.FromSeconds(3),
console.GetCancellationToken()
);
console.Output.WriteLine(CompletionOutputText);
}
catch (OperationCanceledException)
{
console.Output.WriteLine(CancellationOutputText);
throw;
}
}
}
}