namespace Nonemm.Spotting.Tests; /// A stream that hands out bytes a test prepared and keeps whatever is written /// back, so the telnet negotiation can be checked without a socket. Each read /// returns one prepared block, the way a socket hands over one packet. public sealed class FakeTelnetStream : Stream { private readonly Queue blocks; private readonly List written = []; public FakeTelnetStream(params byte[][] blocks) => this.blocks = new Queue(blocks); public IReadOnlyList Written => written; public override bool CanRead => true; public override bool CanSeek => false; public override bool CanWrite => true; public override long Length => throw new NotSupportedException(); public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { if (blocks.Count == 0) { return 0; } byte[] block = blocks.Dequeue(); block.CopyTo(buffer, offset); return block.Length; } public override void Write(byte[] buffer, int offset, int count) => written.AddRange(buffer.Skip(offset).Take(count)); public override void Flush() { } public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); public override void SetLength(long value) => throw new NotSupportedException(); }