public void TestConstructReadOnlyWithWritableStream() { var readOnly = true; var inner = new MemoryStream(8); var stream = new PartialStream(inner, 4, 4, readOnly /*readonly*/, true); Assert.AreEqual(4, inner.Position); if (!inner.CanWrite) Assert.Fail("inner stream is not writable"); Assert.IsFalse(stream.CanWrite); try { stream.Write(new byte[] {0x00, 0x01, 0x02, 0x03}, 0, 4); Assert.Fail("NotSupportedException not thrown"); } catch (NotSupportedException) { } try { stream.WriteByte(0x00); Assert.Fail("NotSupportedException not thrown"); } catch (NotSupportedException) { } try { stream.Flush(); Assert.Fail("NotSupportedException not thrown"); } catch (NotSupportedException) { } }