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 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); }); }
public void TwoStreamCanSeek() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceDataUsed); cs.AppendSource(concatStreamSourceData); Assert.That(cs.CanSeek, Is.True); }
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)); }
public void TwoStreamOneNotSeekableCanSeekReversed() { concatStreamSourceDataUsed.CanSeek.Returns(false); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceDataUsed); cs.AppendSource(concatStreamSourceData); Assert.That(cs.CanSeek, Is.False); }
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)); }
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)); }
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)); }
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)); }
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); }); }
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; }
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; }
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 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; }
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; }); }
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 OnePopulatedStreamCanSeek() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.That(cs.CanSeek, Is.True); }
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); }
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)); }
public void OnePopulatedStreamCanWrite() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.That(cs.CanWrite, Is.False); }
public void OnePopulatedStreamPosition() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.That(cs.Position, Is.Zero); }
public void OnePopulatedStreamLengthAlt() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.That(cs.Length, Is.EqualTo(StreamSourceDefaultLength)); }
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; }
public void OnePopulatedStreamCanSeekFalse() { concatStreamSourceData.CanSeek.Returns(false); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.That(cs.CanSeek, Is.False); }
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)); }
public void OnePopulatedStreamLength() { concatStreamSourceData.Length.Returns(0); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.That(cs.Length, Is.Zero); }
public void OnePopulatedStreamSeekEndChanged() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.Throws <System.ArgumentOutOfRangeException>(() => { cs.Seek(1, System.IO.SeekOrigin.End); }); }
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; }
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; }
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; }