public async Task PayloadSender_WhenLengthNotSet_AndNoData_SendsZeroLengthEnd()
        {
            var sender    = new PayloadSender();
            var transport = new MockTransportSender();

            sender.Connect(transport);

            var header = new Header()
            {
                Type          = PayloadTypes.Stream,
                Id            = Guid.NewGuid(),
                PayloadLength = 555,
                End           = false,
            };

            var stream = new MemoryStream(new byte[100]);

            stream.Position = 100;
            var done = new TaskCompletionSource <string>();

            sender.SendPayload(header, stream, false, (Header sentHeader) =>
            {
                Assert.Equal(0, sentHeader.PayloadLength);
                Assert.True(sentHeader.End);
                done.SetResult("done");
                return(Task.CompletedTask);
            });

            await done.Task;

            Assert.Single(transport.Buffers);
        }
        public async Task PayloadSender_WhenLengthSet_Sends()
        {
            var sender    = new PayloadSender();
            var transport = new MockTransportSender();

            sender.Connect(transport);

            var header = new Header()
            {
                Type          = PayloadTypes.Stream,
                Id            = Guid.NewGuid(),
                PayloadLength = 55,
                End           = false,
            };

            var stream = new MemoryStream(new byte[100]);
            TaskCompletionSource <string> done = new TaskCompletionSource <string>();

            sender.SendPayload(header, stream, true, (Header sentHeader) =>
            {
                Assert.AreEqual(55, sentHeader.PayloadLength);
                Assert.IsFalse(sentHeader.End);
                done.SetResult("done");
                return(Task.CompletedTask);
            });

            await done.Task;

            Assert.AreEqual(2, transport.Buffers.Count);
            Assert.AreEqual(55, stream.Position);
        }
        public void PayloadSender_Dispose()
        {
            var sender = new PayloadSender();

            var header = new Header()
            {
                Type          = PayloadTypes.Stream,
                Id            = Guid.NewGuid(),
                PayloadLength = 55,
                End           = false,
            };

            var stream = new MemoryStream(new byte[100]);

            sender.Dispose();

            Assert.Throws <ObjectDisposedException>(() => sender.SendPayload(header, stream, true, (Header sentHeader) => Task.CompletedTask));
        }