Exemple #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);
            });
        }
Exemple #2
0
        public void TwoStreamsReadTwoIndependent()
        {
            concatStreamSourceData.Position.Returns(StreamSourceDefaultLength - 1);
            concatStreamSourceData.Read(Arg.Any <byte[]>(), 0, 1).Returns(1, 0);

            concatStreamSourceNoData.Length.Returns(StreamSourceDefaultLength); // Just to prevent making and setting up a new mock
            concatStreamSourceNoData.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));
            value = cs.ReadByte();
            Assert.That(value, Is.Not.EqualTo(-1));

            concatStreamSourceData.Received(2).Read(Arg.Any <byte[]>(), 0, 1);
            concatStreamSourceNoData.Received(1).Read(Arg.Any <byte[]>(), 0, 1);
        }
Exemple #3
0
        public void OnePopulatedStreamReadOne()
        {
            concatStreamSourceData.Read(Arg.Is <byte[]>(x => x != null), 0, 1).Returns(1).AndDoes(i => i.ArgAt <byte[]>(0)[0] = 10);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            var buffer = new byte[1];

            Assert.That(buffer[0], Is.Zero);

            var res = cs.Read(buffer, 0, 1);

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

            Assert.That(buffer[0], Is.EqualTo(10));

            concatStreamSourceData.Received().Read(Arg.Any <byte[]>(), 0, 1);
        }