public void TestWriteAndFlush() { using (TempFile temp = new TempFile()) using (TestStream io = new TestStream(temp.Open())) using (BackgroundWriter wtr = new BackgroundWriter(io)) { const int sz = 1000; const int iter = 10000; var bytes = new byte[sz]; for (int i = 0; i < iter; i++) wtr.Write(bytes, 0, sz); wtr.Flush(); Assert.IsTrue(io.Flushed); Assert.AreEqual(sz * iter, io.Position); Assert.AreEqual(sz * iter, io.Length); } }
public void TestWriteOffset() { using (TestStream io = new TestStream()) using (BackgroundWriter wtr = new BackgroundWriter(io)) { wtr.Write(new byte[100], 0, 100); wtr.Write(1, new byte[] { 42 }, 0, 1); wtr.Flush(); Assert.AreEqual(2, io.Position); Assert.AreEqual(100, io.Length); io.Position = 1; Assert.AreEqual(42, io.ReadByte()); } }
public void TestPerformAction() { using (TestStream io = new TestStream()) using (BackgroundWriter wtr = new BackgroundWriter(io)) { wtr.Perform(s => s.Write(new byte[100], 0, 100)); wtr.Flush(); Assert.AreEqual(100, io.Position); Assert.AreEqual(100, io.Length); } }