Example #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);
            });
        }
Example #2
0
 public void UnwrapAndContinueThrowsIfAsyncResultIsNull()
 {
     // Act & assert
     ExceptionHelper.ExpectArgumentNullException(
         delegate {
         AsyncResultWrapper.UnwrapAndContinue(null);
     }, "asyncResult");
 }
Example #3
0
        public void UnwrapAndContinueExecutesStoredDelegateAndReturnsValue()
        {
            // Arrange
            IAsyncResult result = AsyncResultWrapper.Wrap(null, null,
                                                          (callback, state) => new MockAsyncResult(),
                                                          ar => 42);

            // Act
            int returned = AsyncResultWrapper.UnwrapAndContinue <int>(result);

            // Assert
            Assert.AreEqual(42, returned);
        }
Example #4
0
        public void UnwrapAndContinueThrowsIfAsyncResultIsIncorrectType()
        {
            // Arrange
            IAsyncResult result = AsyncResultWrapper.Wrap(null, null,
                                                          (callback, state) => new MockAsyncResult(),
                                                          ar => { });

            // Act & assert
            ExceptionHelper.ExpectArgumentException(
                delegate {
                AsyncResultWrapper.UnwrapAndContinue <int>(result);
            },
                @"The provided IAsyncResult is not valid for this method.
Parameter name: asyncResult");
        }
Example #5
0
        public void UnwrapAndContinueThrowsIfCalledTwiceOnSameAsyncResult()
        {
            // Arrange
            IAsyncResult result = AsyncResultWrapper.Wrap(null, null,
                                                          (callback, state) => new MockAsyncResult(),
                                                          ar => { });

            // Act & assert
            AsyncResultWrapper.UnwrapAndContinue(result);
            ExceptionHelper.ExpectArgumentException(
                delegate {
                AsyncResultWrapper.UnwrapAndContinue(result);
            },
                @"The provided IAsyncResult has already been consumed.
Parameter name: asyncResult");
        }
Example #6
0
        public void UnwrapAndContinueThrowsIfAsyncResultTagMismatch()
        {
            // Arrange
            IAsyncResult result = AsyncResultWrapper.Wrap(null, null,
                                                          (callback, state) => new MockAsyncResult(),
                                                          ar => { },
                                                          "some tag");

            // Act & assert
            ExceptionHelper.ExpectArgumentException(
                delegate {
                AsyncResultWrapper.UnwrapAndContinue(result, "some other tag");
            },
                @"The provided IAsyncResult is not valid for this method.
Parameter name: asyncResult");
        }