public void TestWait() { AsyncResult result; // default timeout result = new AsyncResult(null, null); Assert.AreEqual(result.Timeout, TimeSpan.MaxValue); Assert.IsFalse(result.TryWaitFor(TimeSpan.Zero)); Assert.IsFalse(result.TryWaitFor(TimeSpan.FromMilliseconds(1))); try { result.WaitFor(TimeSpan.Zero); Assert.Fail("TimeoutException expected"); } catch (TimeoutException) { } try { result.WaitFor(TimeSpan.FromMilliseconds(1)); Assert.Fail("TimeoutException expected"); } catch (TimeoutException) { } result.Complete("complete", new Exception("exception")); Assert.IsTrue(result.TryWaitFor(TimeSpan.Zero)); Assert.IsTrue(result.TryWaitFor(TimeSpan.MaxValue)); result.WaitFor(); result.WaitFor(TimeSpan.Zero); result.WaitFor(TimeSpan.MaxValue); // valid timeout result = new AsyncResult(null, null, TimeSpan.FromMilliseconds(10)); Assert.AreEqual(result.Timeout, TimeSpan.FromMilliseconds(10)); Assert.IsFalse(result.TryWaitFor(TimeSpan.Zero)); Assert.IsFalse(result.TryWaitFor(TimeSpan.FromMilliseconds(1))); try { result.WaitFor(TimeSpan.Zero); Assert.Fail("TimeoutException expected"); } catch (TimeoutException) { } try { result.WaitFor(TimeSpan.FromMilliseconds(1)); Assert.Fail("TimeoutException expected"); } catch (TimeoutException) { } try { result.WaitFor(); Assert.Fail("TimeoutException expected"); } catch (TimeoutException) { } result.Complete("complete", new Exception("exception")); Assert.IsTrue(result.TryWaitFor(TimeSpan.Zero)); Assert.IsTrue(result.TryWaitFor(TimeSpan.MaxValue)); result.WaitFor(); result.WaitFor(TimeSpan.Zero); result.WaitFor(TimeSpan.MaxValue); }