public void TestReadOnlyMemStream() { var mem = new CMemoryStream(m_buf2, 0, m_buf2.Length, true) { Position = 0 }; var reader = new BinaryReader(mem); var x = reader.ReadInt32(); mem.Seek(-2, SeekOrigin.Current); Assert.AreEqual(true, mem.CanRead, "Should be CanRead"); Assert.AreEqual(false, mem.CanWrite, "Should not be CanWrite"); Assert.AreEqual(true, mem.CanSeek, "Should be CanSeek"); try { mem.SetLength(4); Assert.Fail("Should not be able to set the length of a read-only stream."); } catch (InvalidOperationException) { // all is well } try { mem.WriteByte(0); Assert.Fail("Should not be able to write to a readonly stream"); } catch (InvalidOperationException) { // all is well } try { mem.SetBuffer(m_buf1); Assert.Fail("Should not be able to set the underlying buffer in a readonly CMemoryStream."); } catch (InvalidOperationException) { // all is well } }
public void TestSetLength() { m_memStream.SetLength(5); Assert.AreEqual <long>(5, m_memStream.Length, "Length is wrong"); }