public async Task SendAsync_ShouldWriteToPipeOutput_OnPayload(int length) { var pipe = new FakeDuplexPipe(); var conn = new FakeConnection { Pipe = pipe, Parser = new FakeFrameParser() }; await conn.SendAsync(new Frame <MessageMetadata>(new byte[length], new MessageMetadata { Length = length })); var sentBuffer = await pipe.ReadPipeWriter(); Assert.Equal(length + 4, sentBuffer.Buffer.Length); }
public async Task SendAsync_ShouldWriteToPipeOutput_OnEmptyPayload() { var pipe = new FakeDuplexPipe(); var conn = new FakeConnection { Pipe = pipe, Parser = new FakeFrameParser() }; await conn.SendAsync(new Frame <MessageMetadata>(new ReadOnlySequence <byte>(new byte[0]), new MessageMetadata { Length = 0 })); var sentBuffer = await pipe.ReadPipeWriter(); Assert.Equal(4, sentBuffer.Buffer.Length); }
public async Task SendAsync_ShouldThrow_OnDisposed() { var pipe = new FakeDuplexPipe(); var conn = new FakeConnection { Pipe = pipe, Parser = new FakeFrameParser() }; conn.OnCreate = () => conn.Dispose(); await conn.Setup(); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await conn.SendAsync( new Frame <MessageMetadata>(new ReadOnlySequence <byte>(new byte[0]), new MessageMetadata { Length = 0 }))); }
public async Task Setup_ShouldReadFrame_OnReceivedData() { var pipe = new FakeDuplexPipe(); var conn = new FakeConnection { Pipe = pipe, Parser = new FakeFrameParser() }; var setup = conn.Setup(); conn.OnReceive = metadata => { Assert.NotNull(metadata); Assert.Equal(4, metadata.Length); conn.Dispose(); }; //let's write a simple message. await pipe.FakeRead(_createMessage(4)); // then start the receive loop await setup; }