Пример #1
0
        public void TwoStreamAppendSourceNotSeekablesOptimize()
        {
            concatStreamSourceData.CanSeek.Returns(false);

            var cs = new ConcatStream();

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

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

            Assert.That(GetNumberOfSources(cs), Is.EqualTo(1));
            concatStreamSourceDataUsed.Received().Dispose();
        }
Пример #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);
        }
Пример #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);
        }