public void WrapThrowsIfBeginCallbackIsNull() { // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { AsyncResultWrapper.Wrap(null, null, null, null); }, "beginCallback"); }
public void WrapThrowsIfEndCallbackIsNull() { // Arrange BeginInvokeCallback beginCallback = (callback, state) => null; // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { AsyncResultWrapper.Wrap(null, null, beginCallback, null); }, "endCallback"); }
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"); }
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); }
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); }