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_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_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 }))); }