Exemplo n.º 1
0
 public void WrapThrowsIfBeginCallbackIsNull()
 {
     // Act & assert
     ExceptionHelper.ExpectArgumentNullException(
         delegate {
         AsyncResultWrapper.Wrap(null, null, null, null);
     }, "beginCallback");
 }
Exemplo n.º 2
0
        public void WrapThrowsIfEndCallbackIsNull()
        {
            // Arrange
            BeginInvokeCallback beginCallback = (callback, state) => null;

            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                AsyncResultWrapper.Wrap(null, null, beginCallback, null);
            }, "endCallback");
        }
Exemplo n.º 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);
        }
Exemplo n.º 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");
        }
Exemplo n.º 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");
        }
Exemplo n.º 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");
        }
Exemplo n.º 7
0
        public void WrapCompletedSynchronously()
        {
            // Arrange
            IAsyncResult resultGivenToCallback = null;
            IAsyncResult innerResult           = new MockAsyncResult();

            // Act
            IAsyncResult outerResult = AsyncResultWrapper.Wrap(
                ar => { resultGivenToCallback = ar; },
                null,
                (callback, state) => {
                callback(innerResult);
                return(innerResult);
            },
                ar => { });

            // Assert
            Assert.AreEqual(outerResult, resultGivenToCallback);
        }
Exemplo n.º 8
0
        public void WrapReturnsAsyncResultWhichWrapsInnerResult()
        {
            // Arrange
            object outerAsyncState = new object();

            IAsyncResult innerResult = new MockAsyncResult()
            {
                CompletedSynchronously = true,
                IsCompleted            = true
            };

            // Act
            IAsyncResult outerResult = AsyncResultWrapper.Wrap(null, outerAsyncState,
                                                               (callback, state) => innerResult,
                                                               ar => { });

            // Assert
            Assert.AreEqual(outerAsyncState, outerResult.AsyncState);
            Assert.AreEqual(innerResult.AsyncWaitHandle, outerResult.AsyncWaitHandle);
            Assert.AreEqual(innerResult.CompletedSynchronously, outerResult.CompletedSynchronously);
            Assert.AreEqual(innerResult.IsCompleted, outerResult.IsCompleted);
        }