Beispiel #1
0
        public async Task TestEmptyStream()
        {
            var impl        = new DelayedContentOutputStream();
            var actualBytes = await ToBytes_(impl);

            Assert.AreEqual(0, actualBytes.Length);
        }
Beispiel #2
0
        private async Task <byte[]> ToBytes_(
            DelayedContentOutputStream delayedContentOutputStream)
        {
            using var memoryStream = new MemoryStream();
            await delayedContentOutputStream.CompleteAndCopyToDelayed(memoryStream);

            return(memoryStream.ToArray());
        }
Beispiel #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);
        }
Beispiel #4
0
        public async Task TestEmptySynchronousStream()
        {
            var impl = new DelayedContentOutputStream();

            impl.Write(Array.Empty <byte>());

            var actualBytes = await ToBytes_(impl);

            Assert.AreEqual(0, actualBytes.Length);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public async Task TestWriteIndividual()
        {
            var impl = new DelayedContentOutputStream();

            impl.WriteByte(1);
            impl.WriteByte(2);
            impl.WriteByte(3);

            var actualBytes = await ToBytes_(impl);

            AssertSequence_(new byte[] {
                1, 2, 3
            }, actualBytes);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }