示例#1
0
        public void TwoStreamAppendSourcePostRead()
        {
            concatStreamSourceData.Position.Returns(10);

            var cs = new ConcatStream();

            Assert.That(cs.Position, Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);

            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength));

            cs.Seek(StreamSourceDefaultLength - 1, System.IO.SeekOrigin.Begin);
            concatStreamSourceDataUsed.Received().Position = StreamSourceDefaultLength - 1;
            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength - 1));
            concatStreamSourceDataUsed.Position.Returns(StreamSourceDefaultLength - 1);

            concatStreamSourceDataUsed.Read(Arg.Any <byte[]>(), 0, 1).Returns(1);
            cs.ReadByte();
            concatStreamSourceDataUsed.Position.Returns(StreamSourceDefaultLength);

            Assert.Throws <System.InvalidOperationException>(() =>
            {
                cs.AppendSource(concatStreamSourceData);
            });
        }
示例#2
0
        public void TwoStreamAppendSourcePostSeek()
        {
            concatStreamSourceData.Position.Returns(10);

            var cs = new ConcatStream();

            Assert.That(cs.Position, Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);

            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength));

            cs.Seek(10, System.IO.SeekOrigin.Begin);
            concatStreamSourceDataUsed.Received().Position = 10;
            Assert.That(cs.Position, Is.EqualTo(10));
            concatStreamSourceDataUsed.Position.Returns(10); // We first check we got the position, then we ensure we actually return the value

            cs.Seek(0, System.IO.SeekOrigin.End);
            concatStreamSourceDataUsed.Received().Position = StreamSourceDefaultLength;
            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength));
            concatStreamSourceDataUsed.Position.Returns(StreamSourceDefaultLength);

            Assert.Throws <System.InvalidOperationException>(() =>
            {
                cs.AppendSource(concatStreamSourceData);
            });
        }
示例#3
0
        public void TwoStreamCanSeek()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanSeek, Is.True);
        }
示例#4
0
        public void TwoStreamLength()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanSeek, Is.True);
            Assert.That(cs.Length, Is.EqualTo(StreamSourceDefaultLength * 2));
        }
示例#5
0
        public void TwoStreamOneNotSeekableCanSeekReversed()
        {
            concatStreamSourceDataUsed.CanSeek.Returns(false);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanSeek, Is.False);
        }
示例#6
0
        public void TwoStreamAppendSourceSeekablesOptimize()
        {
            var cs = new ConcatStream();

            Assert.That(GetNumberOfSources(cs), Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData, true);

            Assert.That(GetNumberOfSources(cs), Is.EqualTo(2));
        }
示例#7
0
        public void TwoStreamAppendSourcePositionPlusZero()
        {
            var cs = new ConcatStream();

            Assert.That(cs.Position, Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength));
        }
示例#8
0
        public void TwoStreamAppendSourceNotSeekablesNoOptimize()
        {
            concatStreamSourceData.CanSeek.Returns(false);

            var cs = new ConcatStream();

            Assert.That(GetNumberOfSources(cs), Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData, false);

            Assert.That(GetNumberOfSources(cs), Is.EqualTo(2));
        }
示例#9
0
        public void TwoStreamAppendSourcePositionPlusTen()
        {
            concatStreamSourceData.Position.Returns(10);

            var cs = new ConcatStream();

            Assert.That(cs.Position, Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength + 10));
        }
示例#10
0
        public void TwoStreamsSeekNonSeekable()
        {
            concatStreamSourceData.CanSeek.Returns(false);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.Throws <System.NotSupportedException>(() =>
            {
                cs.Seek(-1, System.IO.SeekOrigin.End);
            });
        }
示例#11
0
        public void TwoStreamsSeekSecondEnd()
        {
            concatStreamSourceData.Position.Returns(1);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            var res = cs.Seek(-1, System.IO.SeekOrigin.End);

            Assert.That(res, Is.EqualTo((StreamSourceDefaultLength * 2) - 1));

            concatStreamSourceDataUsed.DidNotReceiveWithAnyArgs().Position = 0;
            concatStreamSourceData.ReceivedWithAnyArgs().Position          = StreamSourceDefaultLength - 1;
        }
示例#12
0
        public void TwoStreamsSeekIntoFirst()
        {
            concatStreamSourceData.Position.Returns(1);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            var res = cs.Seek(-2, System.IO.SeekOrigin.Current);

            Assert.That(res, Is.EqualTo(StreamSourceDefaultLength - 1));

            concatStreamSourceDataUsed.ReceivedWithAnyArgs().Position = StreamSourceDefaultLength - 1;
            concatStreamSourceData.ReceivedWithAnyArgs().Position     = 0;
        }
示例#13
0
        public void TwoStreamsReadOneAtStartSecondStream()
        {
            concatStreamSourceData.Read(Arg.Any <byte[]>(), 0, 1).Returns(1);
            concatStreamSourceDataUsed.Read(null, 0, 0).ReturnsForAnyArgs(0);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            var value = cs.ReadByte();

            Assert.That(value, Is.Not.EqualTo(-1));

            concatStreamSourceData.Received(1).Read(Arg.Any <byte[]>(), 0, 1);
        }
示例#14
0
        public void TwoStreamsSeekFirstBegin()
        {
            concatStreamSourceNoData.Length.Returns(StreamSourceDefaultLength); // Just to prevent making and setting up a new mock

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);
            cs.AppendSource(concatStreamSourceNoData);

            var res = cs.Seek(1, System.IO.SeekOrigin.Begin);

            Assert.That(res, Is.EqualTo(1));

            concatStreamSourceData.ReceivedWithAnyArgs().Position        = 1;
            concatStreamSourceNoData.DidNotReceiveWithAnyArgs().Position = 0;
        }
示例#15
0
        public void TwoStreamOneNotSeekableLength()
        {
            concatStreamSourceDataUsed.CanSeek.Returns(false);
            concatStreamSourceDataUsed.Length.Returns(c => throw new System.NotSupportedException()); // Streams like FileStream will throw NotSupportedException if not seekable, but Length is called.

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanSeek, Is.False);
            Assert.Throws <System.NotSupportedException>(() =>
            {
                var len = cs.Length;
            });
        }
示例#16
0
        public void TwoStreamsReadOneAtEndFirstStream()
        {
            concatStreamSourceData.Position.Returns(StreamSourceDefaultLength - 1);
            concatStreamSourceData.Read(Arg.Any <byte[]>(), 0, 1).Returns(1);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);
            cs.AppendSource(concatStreamSourceNoData);

            var value = cs.ReadByte();

            Assert.That(value, Is.Not.EqualTo(-1));

            concatStreamSourceData.Received(1).Read(Arg.Any <byte[]>(), 0, 1);
            concatStreamSourceNoData.DidNotReceiveWithAnyArgs().Read(null, 0, 0);
        }
示例#17
0
        public void OnePopulatedStreamCanSeek()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanSeek, Is.True);
        }
示例#18
0
        public void TwoStreamAppendSourcePositionPlusTenPlusNonSeekable()
        {
            concatStreamSourceData.Position.Returns(10);

            var cs = new ConcatStream();

            Assert.That(cs.Position, Is.Zero);
            Assert.That(cs.CanSeek, Is.True);

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);
            Assert.That(cs.CanSeek, Is.True);

            concatStreamSourceData.CanSeek.Returns(false);

            cs.AppendSource(concatStreamSourceData);
        }
示例#19
0
        public void TwoStreamAppendSourcePositionPlusTenPlusInvalidTen()
        {
            concatStreamSourceData.Position.Returns(10);

            var cs = new ConcatStream();

            Assert.That(cs.Position, Is.Zero);

            cs.AppendSource(concatStreamSourceDataUsed);
            cs.AppendSource(concatStreamSourceData);
            Assert.Throws <System.ArgumentException>(() =>
            {
                cs.AppendSource(concatStreamSourceData);
            });

            Assert.That(cs.Position, Is.EqualTo(StreamSourceDefaultLength + 10));
        }
示例#20
0
        public void OnePopulatedStreamCanWrite()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanWrite, Is.False);
        }
示例#21
0
        public void OnePopulatedStreamPosition()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.Position, Is.Zero);
        }
示例#22
0
        public void OnePopulatedStreamLengthAlt()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.Length, Is.EqualTo(StreamSourceDefaultLength));
        }
示例#23
0
        public void TwoStreamsSeekIntoSecond()
        {
            concatStreamSourceData.Position.Returns(StreamSourceDefaultLength - 1);

            concatStreamSourceNoData.Length.Returns(StreamSourceDefaultLength); // Just to prevent making and setting up a new mock

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);
            cs.AppendSource(concatStreamSourceNoData);

            var res = cs.Seek(2, System.IO.SeekOrigin.Current);

            Assert.That(res, Is.EqualTo(StreamSourceDefaultLength + 1));

            concatStreamSourceData.ReceivedWithAnyArgs().Position   = StreamSourceDefaultLength;
            concatStreamSourceNoData.ReceivedWithAnyArgs().Position = 1;
        }
示例#24
0
        public void OnePopulatedStreamCanSeekFalse()
        {
            concatStreamSourceData.CanSeek.Returns(false);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.CanSeek, Is.False);
        }
示例#25
0
        public void OnePopulatedStreamPositionOffset()
        {
            concatStreamSourceData.Position.Returns(10); // Stream source should continue operating without the ConcatStream caring, unless it's the first source

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.Position, Is.EqualTo(10));
        }
示例#26
0
        public void OnePopulatedStreamLength()
        {
            concatStreamSourceData.Length.Returns(0);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.Length, Is.Zero);
        }
示例#27
0
        public void OnePopulatedStreamSeekEndChanged()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.Throws <System.ArgumentOutOfRangeException>(() =>
            {
                cs.Seek(1, System.IO.SeekOrigin.End);
            });
        }
示例#28
0
        public void OnePopulatedStreamSeekEndChangedInverse()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            var res = cs.Seek(-1, System.IO.SeekOrigin.End);

            Assert.That(res, Is.EqualTo(StreamSourceDefaultLength - 1));

            concatStreamSourceData.ReceivedWithAnyArgs().Position = StreamSourceDefaultLength - 1;
        }
示例#29
0
        public void OnePopulatedStreamSeekCurrentZero()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            var res = cs.Seek(0, System.IO.SeekOrigin.Current);

            Assert.That(res, Is.Zero);

            concatStreamSourceData.DidNotReceiveWithAnyArgs().Position = 0;
        }
示例#30
0
        public void OnePopulatedStreamSeekCurrentChanged()
        {
            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            var res = cs.Seek(1, System.IO.SeekOrigin.Current);

            Assert.That(res, Is.EqualTo(1));

            concatStreamSourceData.ReceivedWithAnyArgs().Position = 1;
        }