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); }); }
public void UnwrapAndContinueThrowsIfAsyncResultIsNull() { // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { AsyncResultWrapper.UnwrapAndContinue(null); }, "asyncResult"); }
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); }
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"); }
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"); }
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"); }