Beispiel #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);
            });
        }
Beispiel #2
0
        public void OnePopulatedStreamReadByte()
        {
            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);

            Assert.That(cs.ReadByte(), Is.EqualTo(10));

            concatStreamSourceData.Received().Read(Arg.Any <byte[]>(), 0, 1);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public void OnePopulatedStreamReadBytePositionIsLength()
        {
            concatStreamSourceData.Position.Returns(1);
            concatStreamSourceData.Length.Returns(1);
            concatStreamSourceData.Read(null, 0, 0).ReturnsForAnyArgs(0);

            var cs = new ConcatStream();

            cs.AppendSource(concatStreamSourceData);

            Assert.That(cs.ReadByte(), Is.EqualTo(-1));

            concatStreamSourceData.Received().Read(Arg.Any <byte[]>(), 0, 1);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void EmptyStreamReadByte()
        {
            var cs = new ConcatStream();

            Assert.That(cs.ReadByte(), Is.EqualTo(-1));
        }