public void rewind() { Assert.Throws <ArgumentNullException>(() => StreamExtensions.Rewind <Stream>(null)); Assert.True(ReferenceEquals(Stream.Null.Rewind(), Stream.Null)); var bytes = Guid.NewGuid().ToByteArray(); var stream = new MemoryStream(bytes); Assert.Equal(0, stream.Position); stream.Seek(0, SeekOrigin.End); Assert.Equal(stream.Length, stream.Position); stream.Rewind(); Assert.Equal(0, stream.Position); stream.Rewind(); Assert.Equal(0, stream.Position); }
public void bytes() { Assert.Throws <ArgumentNullException>(() => StreamExtensions.Bytes(null)); Assert.Equal(0, Stream.Null.Bytes().Length); var bytes = Guid.NewGuid().ToByteArray(); var stream = new MemoryStream(bytes); Assert.True(stream.Bytes().SequenceEqual(bytes)); Assert.Equal(-1, stream.ReadByte()); stream.Close(); Assert.Throws <ObjectDisposedException>(() => stream.ReadByte()); stream = new MemoryStream(bytes); Assert.True(stream.Bytes(true).SequenceEqual(bytes)); Assert.Throws <ObjectDisposedException>(() => stream.ReadByte()); }
public void text_writer() { Assert.Throws <ArgumentNullException>(() => StreamExtensions.TextWriter(null)); var text = Guid.NewGuid().ToString(); var stream = new MemoryStream(); using (var writer = stream.TextWriter()) { writer.Write(text); } Assert.True(stream.ToArray().SequenceEqual(text.Bytes())); Assert.Throws <ObjectDisposedException>(() => stream.ReadByte()); stream = new MemoryStream(); using (var writer = stream.TextWriter(Encoding.Unicode)) { writer.Write(text); } Assert.True(stream.ToArray().SequenceEqual(text.Bytes(Encoding.Unicode))); Assert.Throws <ObjectDisposedException>(() => stream.ReadByte()); }