public void SeekToEnd() { var stream = new FastMemoryWriter(); stream.Write("JonnoJ"); var result = stream.Position; stream.Seek(0, System.IO.SeekOrigin.Begin); stream.Seek(0, System.IO.SeekOrigin.End); Assert.Equal(result, stream.Position); }
public void TwoSeeks() { var stream = new FastMemoryWriter(); stream.Write("JonnoJ"); var initilPoisition = stream.Position; stream.Seek(-2, System.IO.SeekOrigin.Current); Assert.Equal(initilPoisition - 2, stream.Position); stream.Seek(-2, System.IO.SeekOrigin.Current); Assert.Equal(initilPoisition - 4, stream.Position); Assert.Equal(initilPoisition, stream.Length); }
public void SeekToBegin() { var stream = new FastMemoryWriter(); stream.Write("JonnoJ"); stream.Seek(0, System.IO.SeekOrigin.Begin); Assert.Equal(0, stream.Position); }
public void SeekWithCurrent() { var stream = new FastMemoryWriter(); stream.Write("JonnoJ"); var result = stream.Position; stream.Seek(-1, System.IO.SeekOrigin.Current); Assert.Equal(result - 1, stream.Position); }
public void ReadString() { var text = "hello"; var memory = new FastMemoryWriter(); memory.Write(text); memory.Seek(0, SeekOrigin.Begin); var reader = new FastReader(memory); var result = reader.ReadString(); Assert.Equal(text, result); }
public void ReadWrongByteArray() { var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; var memory = new FastMemoryWriter(); memory.WriteByteArray(bytes); memory.SetLength(9); memory.Seek(0, SeekOrigin.Begin); var reader = new FastReader(memory); Assert.Throws <EndOfStreamException>(() => reader.ReadByteArray()); }
public void ReadByteArray() { var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; var memory = new FastMemoryWriter(); memory.WriteByteArray(bytes); memory.Seek(0, SeekOrigin.Begin); var reader = new FastReader(memory); var result = reader.ReadByteArray(); Assert.True(result.SequenceEqual(bytes)); }
public void Bytes() { var bytes = new byte[] { 10, 10, 11, 12 }; var writer = new FastMemoryWriter(); writer.Write(bytes); writer.Seek(0, SeekOrigin.Begin); var result = new byte[4]; writer.Read(result); Assert.True(bytes.SequenceEqual(result)); }
public async Task CopyToAsync() { var bytes = new byte[] { 10, 10 }; var writer = new FastMemoryWriter(); writer.Write(bytes); writer.Seek(0, SeekOrigin.Begin); var stream = new MemoryStream(); await writer.CopyToAsync(stream); var result = stream.ToArray(); Assert.Equal(bytes, result); }
public void Read() { var text = "JonnoJ"; var textBytes = Encoding.UTF8.GetBytes(text); var stream = new FastMemoryWriter(); stream.Write(text); stream.Seek(0, System.IO.SeekOrigin.Begin); var result = new byte[stream.Length]; stream.Read(result, 0, result.Length); // skip string length Assert.True(textBytes.SequenceEqual(result.Skip(4))); }
public void ReadOnEmpty() { var text = "JonnoJ"; var stream = new FastMemoryWriter(); stream.Write(text); stream.Seek(0, System.IO.SeekOrigin.Begin); var result = new byte[stream.Length]; var read = stream.Read(result, 0, result.Length); Assert.Equal(result.Length, read); read = stream.Read(result, 0, result.Length); Assert.Equal(0, read); }