using Nonemm.Digital; namespace Nonemm.Digital.Tests; /// A bridge that goes nowhere: the test reads what was sent to it and says what /// comes back. public sealed class FakeBridge : BridgeChannel { private readonly List sent = []; public bool IsStarted { get; private set; } public IReadOnlyList Sent { get { lock (sent) { return sent.ToArray(); } } } public event EventHandler? LineReceived; public event EventHandler? Failed; public Task StartAsync(CancellationToken cancellation = default) { IsStarted = true; return Task.CompletedTask; } public Task SendAsync(string line, CancellationToken cancellation = default) { lock (sent) { sent.Add(line); } return Task.CompletedTask; } public Task ToWindowsPathAsync(string path, CancellationToken cancellation = default) => Task.FromResult("Z:" + path.Replace('/', '\\')); public void Say(string verb, params string[] fields) => LineReceived?.Invoke(this, BridgeLine.Write(verb, fields)); public void Stop(string why) => Failed?.Invoke(this, why); public void Dispose() { } }