public void PromiseIsCanceledFromToken() { CancelationSource cancelationSource = CancelationSource.New(); var deferred = Promise.NewDeferred(); var deferredInt = Promise.NewDeferred <int>(); int cancelCallbacks = 0; TestHelper.AddResolveCallbacksWithCancelation <float, string>( deferred.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddCallbacksWithCancelation <float, object, string>( deferred.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddContinueCallbacksWithCancelation <float, string>( deferred.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddResolveCallbacksWithCancelation <int, float, string>( deferredInt.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddCallbacksWithCancelation <int, float, object, string>( deferredInt.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); TestHelper.AddContinueCallbacksWithCancelation <int, float, string>( deferredInt.Promise, cancelationToken: cancelationSource.Token, onCancel: _ => ++ cancelCallbacks, onCancelCapture: (_, __) => ++ cancelCallbacks ); cancelationSource.Cancel(); deferred.Resolve(); deferredInt.Resolve(1); Promise.Manager.HandleCompletes(); Assert.AreEqual( TestHelper.cancelVoidCallbacks + TestHelper.cancelTCallbacks, cancelCallbacks ); cancelationSource.Dispose(); TestHelper.Cleanup(); }
public void OnResolvedIsNotInvokedIfTokenIsAlreadyCanceled() { CancelationSource cancelationSource = CancelationSource.New(); cancelationSource.Cancel(); var deferred = Promise.NewDeferred(); var deferredInt = Promise.NewDeferred <int>(); TestHelper.AddResolveCallbacksWithCancelation <float, string>( deferred.Promise, onResolve: () => Assert.Fail("OnResolved was invoked."), onResolveCapture: _ => Assert.Fail("OnResolved was invoked."), cancelationToken: cancelationSource.Token ); TestHelper.AddCallbacksWithCancelation <float, object, string>( deferred.Promise, onResolve: () => Assert.Fail("OnResolved was invoked."), onResolveCapture: _ => Assert.Fail("OnResolved was invoked."), cancelationToken: cancelationSource.Token ); TestHelper.AddResolveCallbacksWithCancelation <int, float, string>( deferredInt.Promise, onResolve: _ => Assert.Fail("OnResolved was invoked."), onResolveCapture: _ => Assert.Fail("OnResolved was invoked."), cancelationToken: cancelationSource.Token ); TestHelper.AddCallbacksWithCancelation <int, float, object, string>( deferredInt.Promise, onResolve: _ => Assert.Fail("OnResolved was invoked."), onResolveCapture: _ => Assert.Fail("OnResolved was invoked."), cancelationToken: cancelationSource.Token ); deferred.Resolve(); deferredInt.Resolve(1); Promise.Manager.HandleCompletes(); cancelationSource.Dispose(); TestHelper.Cleanup(); }