public void WaitForExitBlocksWhenStillReading()
        {
            var blockingStream = new BlockingStream();
            var sr             = new StreamReader(blockingStream);
            var sw             = new StringWriter();

            var handler = new AsyncTwoWayStreamsHandler(sr, sw);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            new Task(() =>
            {
                Thread.Sleep(100);
                blockingStream.Unblock();
            }).Start();
            handler.WaitForExit();

            stopWatch.Stop();

            if (stopWatch.ElapsedMilliseconds < 100)
            {
                Assert.Fail("WaitForExit returned before the timer finished");
            }
            else
            {
                Assert.Pass("Successfully waited for the stream to end");
            }
        }
        public void WaitForExitBlocksWhenStillReading()
        {
            var blockingStream = new BlockingStream();
            var sr = new StreamReader(blockingStream);
            var sw = new StringWriter();

            var handler = new AsyncTwoWayStreamsHandler(sr, sw);

            var stopWatch = new Stopwatch();
            stopWatch.Start();

            new Task(() =>
            {
                Thread.Sleep(100);
                blockingStream.Unblock();
            }).Start();
            handler.WaitForExit();

            stopWatch.Stop();

            if (stopWatch.ElapsedMilliseconds < 100)
                Assert.Fail("WaitForExit returned before the timer finished");
            else
                Assert.Pass("Successfully waited for the stream to end");
        }
        public void WaitForExitExitsImmediatelyWhenNothingToWaitFor()
        {
            var sr = new StringReader("");
            var sw = new StringWriter();

            var handler = new AsyncTwoWayStreamsHandler(sr, sw);

            handler.WaitForExit();
            Assert.Pass("Successfully skipped waiting since there was nothing to do");
        }
        public void WaitForExitExitsImmediatelyWhenNothingToWaitFor()
        {
            var sr = new StringReader("");
            var sw = new StringWriter();

            var handler = new AsyncTwoWayStreamsHandler(sr, sw);

            handler.WaitForExit();
            Assert.Pass("Successfully skipped waiting since there was nothing to do");
        }