public void Write_Two() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); stream.Write(mammasBullar, 0, mammasBullar.Length); stream.Write(mammasBullar, 0, mammasBullar.Length); Assert.Equal(mammasBullar.Length * 2, stream.Position); Assert.Equal(mammasBullar.Length * 2, stream.Length); // must be able to write after the last byte. stream.Position = mammasBullar.Length * 2; }
public void Write_WrongOffset() { var slice = new BufferSlice(5); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Write(mammasBullar, -1, 1)); }
public void Write_TooSmallInternalBuffer() { var slice = new BufferSlice(5); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Write(mammasBullar, 0, 6)); }
public void Position_SetGet() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); stream.Write(mammasBullar, 0, mammasBullar.Length); stream.Position = 2; Assert.Equal(2, stream.Position); }
public void Write_ThenMovePositionOutOfRange() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); stream.Write(mammasBullar, 0, mammasBullar.Length); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Position = mammasBullar.Length + 1); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Position = -1); }
public void Read_OneTime() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast."); stream.Write(mammasBullar, 0, mammasBullar.Length); var buffer = new byte[10]; stream.Position = 0; stream.Read(buffer, 0, 6); Assert.Equal("Mammas", Encoding.UTF8.GetString(buffer, 0, 6)); }
public void ReadLongerThanBuffer() { var slice = new BufferSlice(65535); var stream = new SliceStream(slice); var expected = "Mammas bullar smakar godast"; var mammasBullar = Encoding.UTF8.GetBytes(expected); stream.Write(mammasBullar, 0, mammasBullar.Length); var buffer = new byte[100]; stream.Position = 0; Assert.Equal(expected.Length, stream.Read(buffer, 0, 1024)); Assert.Equal(expected, Encoding.UTF8.GetString(buffer, 0, expected.Length)); }
public void InitUsingWrittenAndWriteMore() { var initial = "Hello world!"; var addition = "Something more.."; var buffer = new byte[65535]; var text = Encoding.ASCII.GetBytes(initial); Buffer.BlockCopy(text, 0, buffer, 0, text.Length); var slice = new BufferSlice(buffer, 0, buffer.Length); var stream = new SliceStream(slice, text.Length); stream.SetLength(initial.Length); stream.Position = stream.Length; var writeable = Encoding.ASCII.GetBytes(addition); stream.Write(writeable, 0, writeable.Length); stream.Position = 0; var reader = new StreamReader(stream); var actual = reader.ReadToEnd(); Assert.Equal(initial + addition, actual); }