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 basicConcatStreamSeek() { byte[] writeBuffer = new byte[14]; byte[] readBuffer = new byte[14]; MemoryStream s1 = new MemoryStream(); MemoryStream s2 = new MemoryStream(); ConcatStream testCS = new ConcatStream(s1, s2); for (int i = 0; i < 14; i++) { writeBuffer[i] = Convert.ToByte(i); } s1.Write(writeBuffer, 0, 6); s2.Write(writeBuffer, 6, 8); s1.Seek(0, SeekOrigin.Begin); s2.Seek(0, SeekOrigin.Begin); testCS.Read(readBuffer, 0, 14); Assert.AreEqual(14, testCS.Position); testCS.Seek(0, SeekOrigin.Begin); Assert.AreEqual(0, testCS.Position); Assert.AreEqual(0, s1.Position); Assert.AreEqual(0, s2.Position); }
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 EmptyStreamSeekEndZero() { var cs = new ConcatStream(); var res = cs.Seek(0, System.IO.SeekOrigin.End); Assert.That(res, Is.Zero); }
public void EmptyStreamSeekEnd() { var cs = new ConcatStream(); Assert.Throws <System.ArgumentOutOfRangeException>(() => { cs.Seek(1, System.IO.SeekOrigin.End); }); }
public void OnePopulatedStreamSeekEndChanged() { var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); Assert.Throws <System.ArgumentOutOfRangeException>(() => { cs.Seek(1, System.IO.SeekOrigin.End); }); }
//[Test()] public void ConcatStreamTest() { byte[] buffer1 = new byte[10]; byte[] buffer2 = new byte[10]; ConcatStream stream = new ConcatStream(new MemoryStream(buffer1), new NoSeekMemoryStream(buffer2)); stream.Read(new byte[20], 0, 20); stream.Seek(0, SeekOrigin.Begin); }
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 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; }
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 WriteTest() { ConcatStream cstr = new ConcatStream(new MemoryStream(Encoding.ASCII.GetBytes("newstream")), new MemoryStream()); string newStr = "stringthatshouldoverwriteeverythingelse"; cstr.Write(Encoding.ASCII.GetBytes(newStr), 0, newStr.Length); cstr.Seek(0, SeekOrigin.Begin); byte[] buf = new byte[newStr.Length]; cstr.Read(buf, 0, newStr.Length); Assert.That(newStr == Encoding.ASCII.GetString(buf)); }
public void OnePopulatedStreamSeekEndZeroChanged() { concatStreamSourceData.Position.Returns(1); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); var res = cs.Seek(0, System.IO.SeekOrigin.End); Assert.That(res, Is.EqualTo(StreamSourceDefaultLength)); concatStreamSourceData.ReceivedWithAnyArgs().Position = StreamSourceDefaultLength; }
public void OnePopulatedStreamSeekCurrentInverse() { concatStreamSourceData.Position.Returns(1); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); var res = cs.Seek(-1, System.IO.SeekOrigin.Current); Assert.That(res, Is.Zero); concatStreamSourceData.ReceivedWithAnyArgs().Position = 0; }
public void OnePopulatedStreamSeekBegin() { concatStreamSourceData.Position.Returns(1); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); var res = cs.Seek(1, System.IO.SeekOrigin.Begin); Assert.That(res, Is.EqualTo(1)); concatStreamSourceData.DidNotReceiveWithAnyArgs().Position = 0; }
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 OnePopulatedStreamSeekBeginZeroChanged() { concatStreamSourceData.Position.Returns(1); var cs = new ConcatStream(); cs.AppendSource(concatStreamSourceData); var res = cs.Seek(0, System.IO.SeekOrigin.Begin); Assert.That(res, Is.Zero); concatStreamSourceData.ReceivedWithAnyArgs().Position = 0; }
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 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 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 boundaryRead() { byte[] writeBuffer = new byte[14]; byte[] readBuffer = new byte[1]; int read1; int read2; MemoryStream s1 = new MemoryStream(); MemoryStream s2 = new MemoryStream(); for (int i = 0; i < 14; i++) { writeBuffer[i] = Convert.ToByte(i); } s1.Write(writeBuffer, 0, 6); s2.Write(writeBuffer, 6, 8); s1.Seek(0, SeekOrigin.Begin); s2.Seek(0, SeekOrigin.Begin); ConcatStream testCS = new ConcatStream(s1, s2); long length = testCS.Length; testCS.Seek(length - 1, SeekOrigin.Begin); long position = testCS.Position; read1 = testCS.Read(readBuffer, 0, 1); read2 = testCS.Read(readBuffer, 0, 1); int x = 0; Assert.AreEqual(13, readBuffer [0]); }