using System.Collections.Concurrent; using Terminal.Gui; namespace TerminalGuiFluentTesting; internal class FakeInput : IConsoleInput { private readonly CancellationToken _hardStopToken; private readonly CancellationTokenSource _timeoutCts; public FakeInput (CancellationToken hardStopToken) { _hardStopToken = hardStopToken; // Create a timeout-based cancellation token too to prevent tests ever fully hanging _timeoutCts = new (With.Timeout); } /// public void Dispose () { } /// public void Initialize (ConcurrentQueue inputBuffer) { InputBuffer = inputBuffer; } public ConcurrentQueue InputBuffer { get; set; } /// public void Run (CancellationToken token) { // Blocks until either the token or the hardStopToken is cancelled. WaitHandle.WaitAny (new [] { token.WaitHandle, _hardStopToken.WaitHandle, _timeoutCts.Token.WaitHandle }); } }