示例#1
0
        public void PaddedStream_SeekingWorks()
        {
            PaddedStream paddedStream = new PaddedStream(
                new MemoryStream(Enumerable.Range(0, 20).Select(i => (byte)i).ToArray())
            {
                Position = 0
            },
                0,
                30);

            MemoryStream ouputStream = new MemoryStream();

            paddedStream.CopyTo(ouputStream);

            Assert.AreEqual(paddedStream.Length, paddedStream.Position);

            CollectionAssert.AreEqual(
                Enumerable.Range(0, 20).Select(i => (byte)i).Concat(Enumerable.Repeat((byte)0, 30)).ToArray(),
                ouputStream.ToArray());

            paddedStream.Position = 10;
            Assert.AreEqual(10, paddedStream.Position);

            ouputStream = new MemoryStream();
            paddedStream.CopyTo(ouputStream);

            CollectionAssert.AreEqual(
                Enumerable.Range(10, 10).Select(i => (byte)i).Concat(Enumerable.Repeat((byte)0, 30)).ToArray(),
                ouputStream.ToArray());

            paddedStream.Position = 20;
            Assert.AreEqual(20, paddedStream.Position);

            ouputStream = new MemoryStream();
            paddedStream.CopyTo(ouputStream);

            CollectionAssert.AreEqual(
                Enumerable.Repeat((byte)0, 30).ToArray(),
                ouputStream.ToArray());
        }
示例#2
0
        public void PaddedStream_PadsInnerStreamData(byte[] data, byte paddingValue, int paddingLength)
        {
            PaddedStream paddedStream = new PaddedStream(new MemoryStream(data)
            {
                Position = 0
            }, paddingValue, paddingLength);

            Assert.AreEqual(0, paddedStream.Position);
            Assert.AreEqual(data.Length + paddingLength, paddedStream.Length);

            MemoryStream ouputStream = new MemoryStream();

            paddedStream.CopyTo(ouputStream);

            Assert.AreEqual(paddedStream.Length, paddedStream.Position);

            CollectionAssert.AreEqual(
                data.Concat(Enumerable.Repeat(paddingValue, paddingLength)).ToArray(),
                ouputStream.ToArray());
        }