示例#1
0
        public async Task TestWriteDelayed()
        {
            var impl = new DelayedContentOutputStream();

            impl.WriteDelayed(Task.FromResult(new byte[] { 1, 2 }));
            impl.WriteDelayed(Task.FromResult(new byte[] { 3, 4 }));
            impl.WriteDelayed(Task.FromResult(new byte[] { 5, 6 }));

            var actualBytes = await ToBytes_(impl);

            AssertSequence_(new byte[] {
                1, 2, 3, 4, 5, 6
            }, actualBytes);
        }
示例#2
0
        public async Task TestWriteEverything()
        {
            var impl = new DelayedContentOutputStream();

            impl.WriteByte(1);
            impl.Write(new byte[] { 2, 3 });
            impl.WriteDelayed(Task.FromResult(new byte[] { 4, 5 }));
            impl.Write(new byte[] { 6, 7 });
            impl.WriteByte(8);
            impl.WriteDelayed(Task.FromResult(new byte[] { 9, 10 }));

            var actualBytes = await ToBytes_(impl);

            AssertSequence_(new byte[] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            }, actualBytes);
        }
示例#3
0
        public async Task TestEmptyDelayedStream()
        {
            var impl = new DelayedContentOutputStream();

            impl.WriteDelayed(Task.FromResult(Array.Empty <byte>()));

            var actualBytes = await ToBytes_(impl);

            Assert.AreEqual(0, actualBytes.Length);
        }
示例#4
0
        public async Task TestDelayedLength()
        {
            var impl = new DelayedContentOutputStream();

            var lengthTask = impl.GetDelayedLength();

            impl.WriteDelayed(
                lengthTask.ContinueWith(length => new[] { (byte)length.Result }),
                Task.FromResult(1L));
            impl.WriteDelayed(
                Task.FromResult(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }),
                Task.FromResult(3L));

            var actualBytes = await ToBytes_(impl);

            AssertSequence_(new byte[] {
                4, 0, 1, 2,
            }, actualBytes);
        }
示例#5
0
        public async Task TestBlockLength()
        {
            var impl = new DelayedContentOutputStream();

            impl.EnterBlockAndGetDelayedLength(
                (s, lTask) => {
                s.WriteDelayed(
                    lTask.ContinueWith(length => new[] { (byte)length.Result }),
                    Task.FromResult(1L));
            });

            impl.WriteByte(29);

            impl.EnterBlockAndGetDelayedLength(
                (s, lTask) => {
                s.WriteDelayed(
                    lTask.ContinueWith(length => new[] { (byte)length.Result }),
                    Task.FromResult(1L));
                s.Align(5);
            });

            var lengthTask = impl.EnterBlockAndGetDelayedLength(
                (s, lTask) => {
                s.WriteByte(0);
                s.WriteByte(1);
                s.WriteByte(2);
            });

            impl.WriteDelayed(
                lengthTask.ContinueWith(length => new[] { (byte)length.Result }),
                Task.FromResult(1L));

            var actualBytes = await ToBytes_(impl);

            AssertSequence_(new byte[] {
                1,
                29,
                1, 0, 0, 0, 0,
                0, 1, 2, 3
            }, actualBytes);
        }
示例#6
0
        public async Task TestPosition()
        {
            var impl = new DelayedContentOutputStream();

            var positionTask1 = impl.GetDelayedPosition();

            impl.WriteDelayed(
                positionTask1.ContinueWith(pos => new[] { (byte)pos.Result }),
                Task.FromResult(1L));

            impl.WriteByte(1);
            impl.Write(new byte[] { 2, 3 });

            var positionTask2 = impl.GetDelayedPosition();

            impl.WriteDelayed(
                positionTask2.ContinueWith(pos => new[] { (byte)pos.Result }),
                Task.FromResult(1L));

            impl.WriteDelayed(Task.FromResult(new byte[] { 4, 5 }));
            impl.Write(new byte[] { 6, 7 });

            var positionTask3 = impl.GetDelayedPosition();

            impl.WriteDelayed(
                positionTask3.ContinueWith(pos => new[] { (byte)pos.Result }),
                Task.FromResult(1L));

            impl.WriteByte(8);
            impl.WriteDelayed(Task.FromResult(new byte[] { 9, 10 }));

            var positionTask4 = impl.GetDelayedPosition();

            impl.WriteDelayed(
                positionTask4.ContinueWith(pos => new[] { (byte)pos.Result }),
                Task.FromResult(1L));


            var actualBytes = await ToBytes_(impl);

            AssertSequence_(new byte[] {
                0, 1, 2, 3,
                4, 4, 5, 6, 7,
                9, 8, 9, 10,
                13
            }, actualBytes);
        }