Exemple #1
0
        public void Write()
        {
            var bytes = new byte[] { 0, 1, 2, 3, 4, 5, };
            var src   = new MemoryStream(bytes);
            var dest  = new StreamProxy(src);

            Assert.That(dest.Seek(1, SeekOrigin.Begin), Is.EqualTo(1L));
            dest.SetLength(4);
            dest.Write(new byte[] { 9, 9, 9 }, 0, 3);
            dest.Flush();
            Assert.That(bytes[0], Is.EqualTo((byte)0));
            Assert.That(bytes[1], Is.EqualTo((byte)9));
            Assert.That(bytes[2], Is.EqualTo((byte)9));
            Assert.That(bytes[3], Is.EqualTo((byte)9));
            Assert.That(bytes[4], Is.EqualTo((byte)4));

            dest.Dispose();
            Assert.That(() => dest.Write(new byte[] { 1 }, 0, 1), Throws.TypeOf <NullReferenceException>());
        }