public void FlushAsyncTest() { this.CombinatorialEngineProvider.RunCombinations( new[] { new int[] { 0 }, new int[] { 1 }, new int[] { 1, 20, 1, 0 }, new int[] { 100000, 1, 100000, 23 } }, new bool[] { false, true }, new bool[] { false, true }, AsyncTestStream.InterestingBehaviors, (writeCounts, useBiggerBuffer, repeat, asyncBehaviors) => { AsyncTestStream testStream = new AsyncTestStream() { FailOnRead = true, AsyncMethodBehaviorsEnumerator = asyncBehaviors.EndLessLoop() }; AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(testStream); while (true) { int totalWrittenCount = 0; foreach (int writeCount in writeCounts) { byte[] data = new byte[writeCount + (useBiggerBuffer ? 20 : 0)]; for (int i = 0; i < writeCount; i++) { data[i + (useBiggerBuffer ? 10 : 0)] = (byte)((totalWrittenCount + i) % 256); } asyncBufferedStream.Write(data, useBiggerBuffer ? 10 : 0, writeCount); totalWrittenCount += writeCount; } this.Assert.AreEqual(0, testStream.InnerStream.Length, "The buffered stream should not have written anything to the underlying stream yet."); asyncBufferedStream.FlushAsync().Wait(); byte[] writtenData = ((MemoryStream)testStream.InnerStream).GetBuffer(); this.Assert.AreEqual(totalWrittenCount, testStream.InnerStream.Length, "Wrong number of bytes was written to the stream."); for (int i = 0; i < totalWrittenCount; i++) { this.Assert.AreEqual(i % 256, writtenData[i], "Wrong data written to the stream."); } if (!repeat) { break; } testStream.InnerStream = new MemoryStream(); repeat = false; } this.Assert.IsFalse(testStream.Disposed, "The stream should not have been disposed yet."); asyncBufferedStream.Dispose(); this.Assert.IsFalse(testStream.Disposed, "The underlying stream should not be disposed."); }); }
public void StaticBehaviorTest() { AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream()); this.Assert.IsFalse(asyncBufferedStream.CanRead, "CanRead should be false."); this.Assert.IsFalse(asyncBufferedStream.CanSeek, "CanSeek should be false."); this.Assert.IsTrue(asyncBufferedStream.CanWrite, "CanWrite should be true."); }
public void DisposeClearTest() { using (AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream())) { asyncBufferedStream.Write(new byte[] { 1 }, 0, 1); asyncBufferedStream.Clear(); } }
public void StaticBehaviorTest() { AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream()); this.Assert.IsFalse(asyncBufferedStream.CanRead, "CanRead should be false."); this.Assert.IsFalse(asyncBufferedStream.CanSeek, "CanSeek should be false."); this.Assert.IsTrue(asyncBufferedStream.CanWrite, "CanWrite should be true."); }
public void DisposeClearTest() { using (AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream())) { asyncBufferedStream.Write(new byte[] { 1 }, 0, 1); asyncBufferedStream.Clear(); } }
public void DisposeFlushTest() { AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream()); // Dispose without writing anything and without FlushAsync should work asyncBufferedStream.Dispose(); asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream()); asyncBufferedStream.Write(new byte[] { 1 }, 0, 1); this.Assert.ExpectedException( () => { asyncBufferedStream.Dispose(); }, ODataExpectedExceptions.ODataException("AsyncBufferedStream_WriterDisposedWithoutFlush"), this.ExceptionVerifier); }
public void DisposeFlushTest() { AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream()); // Dispose without writing anything and without FlushAsync should work asyncBufferedStream.Dispose(); asyncBufferedStream = new AsyncBufferedStreamTestWrapper(new MemoryStream()); asyncBufferedStream.Write(new byte[] { 1 }, 0, 1); this.Assert.ExpectedException( () => { asyncBufferedStream.Dispose(); }, ODataExpectedExceptions.ODataException("AsyncBufferedStream_WriterDisposedWithoutFlush"), this.ExceptionVerifier); }
public void FlushAsyncTest() { this.CombinatorialEngineProvider.RunCombinations( new[] { new int[] { 0 }, new int[] { 1 }, new int[] { 1, 20, 1, 0 }, new int[] { 100000, 1, 100000, 23 } }, new bool[] { false, true }, new bool[] { false, true }, AsyncTestStream.InterestingBehaviors, (writeCounts, useBiggerBuffer, repeat, asyncBehaviors) => { AsyncTestStream testStream = new AsyncTestStream() { FailOnRead = true, AsyncMethodBehaviorsEnumerator = asyncBehaviors.EndLessLoop() }; AsyncBufferedStreamTestWrapper asyncBufferedStream = new AsyncBufferedStreamTestWrapper(testStream); while (true) { int totalWrittenCount = 0; foreach (int writeCount in writeCounts) { byte[] data = new byte[writeCount + (useBiggerBuffer ? 20 : 0)]; for (int i = 0; i < writeCount; i++) { data[i + (useBiggerBuffer ? 10 : 0)] = (byte)((totalWrittenCount + i) % 256); } asyncBufferedStream.Write(data, useBiggerBuffer ? 10 : 0, writeCount); totalWrittenCount += writeCount; } this.Assert.AreEqual(0, testStream.InnerStream.Length, "The buffered stream should not have written anything to the underlying stream yet."); #if SILVERLIGHT asyncBufferedStream.Flush(); #else asyncBufferedStream.FlushAsync().Wait(); #endif byte[] writtenData = ((MemoryStream)testStream.InnerStream).GetBuffer(); this.Assert.AreEqual(totalWrittenCount, testStream.InnerStream.Length, "Wrong number of bytes was written to the stream."); for (int i = 0; i < totalWrittenCount; i++) { this.Assert.AreEqual(i % 256, writtenData[i], "Wrong data written to the stream."); } if (!repeat) { break; } testStream.InnerStream = new MemoryStream(); repeat = false; } this.Assert.IsFalse(testStream.Disposed, "The stream should not have been disposed yet."); asyncBufferedStream.Dispose(); this.Assert.IsFalse(testStream.Disposed, "The underlying stream should not be disposed."); }); }