예제 #1
0
        public void WrapTimedOut()
        {
            // Arrange
            ManualResetEvent waitHandle = new ManualResetEvent(false /* initialState */);

            AsyncCallback callback = ar => {
                waitHandle.Set();
            };

            // Act & assert
            IAsyncResult asyncResult = AsyncResultWrapper.WrapWithTimeout(callback, null,
                                                                          (innerCallback, innerState) => new MockAsyncResult(),
                                                                          ar => {
                Assert.Fail("This callback should never execute since we timed out.");
            },
                                                                          0);

            // wait for the timeout
            waitHandle.WaitOne();

            ExceptionHelper.ExpectException <TimeoutException>(
                delegate {
                AsyncResultWrapper.UnwrapAndContinue(asyncResult);
            });
        }
예제 #2
0
        public void WrapThrowsIfTimeoutIsOutOfRange()
        {
            // Arrange
            BeginInvokeCallback beginCallback = (callback, state) => null;
            AsyncCallback       endCallback   = ar => { };

            // Act & assert
            ExceptionHelper.ExpectArgumentOutOfRangeException(
                delegate {
                AsyncResultWrapper.WrapWithTimeout(null, null, beginCallback, endCallback, -1000);
            }, "timeout",
                @"The timeout period must be a non-negative number or Timeout.Infinite.
Parameter name: timeout");
        }