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); }); }
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); }
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); }
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); }
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); }
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); }
public void EmptyStreamReadByte() { var cs = new ConcatStream(); Assert.That(cs.ReadByte(), Is.EqualTo(-1)); }