public void AccessingCancelExceptionOrRejectExceptionInOnResolvedDoesNotThrow() { var promise1 = Promise.Resolved(); var promise2 = Promise.Resolved(100); TestHelper.AddCallbacks <int, object, string>(promise1, onResolve: () => { #if PROMISE_CANCEL Promise.CancelException(); Promise.CancelException("Cancel!"); #endif Promise.RejectException("Reject!"); }); TestHelper.AddCallbacks <int, bool, object, string>(promise2, onResolve: v => { #if PROMISE_CANCEL Promise.CancelException(); Promise.CancelException("Cancel!"); #endif Promise.RejectException("Reject!"); }); Promise.Manager.HandleCompletes(); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
public void AsyncPromiseIsCanceledFromThrow8() { string expected = "Cancel"; bool canceled = false; async Promise <int> Func() { await Promise.Resolved(); throw Promise.CancelException(expected); } Func() .CatchCancelation(e => { Assert.AreEqual(expected, e.Value); canceled = true; }); Assert.AreEqual(false, canceled); Promise.Manager.HandleCompletes(); Assert.AreEqual(true, canceled); TestHelper.Cleanup(); }
public void AsyncPromiseIsCanceledFromThrow4() { string expected = "Cancel"; bool canceled = false; #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously async Promise <int> Func() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { throw Promise.CancelException(expected); } Func() .CatchCancelation(e => { Assert.AreEqual(expected, e.Value); canceled = true; }); Assert.AreEqual(false, canceled); Promise.Manager.HandleCompletes(); Assert.AreEqual(true, canceled); TestHelper.Cleanup(); }
public void AsyncPromiseIsCanceledFromThrow3() { string expected = "Cancel"; bool canceled = false; #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously async Promise Func() #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { throw Promise.CancelException(expected); } Func() .CatchCancelation(e => { Assert.AreEqual(expected, e.Value); canceled = true; }); Assert.AreEqual(false, canceled); Promise.Manager.HandleCompletes(); Assert.AreEqual(true, canceled); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
public void AccessingCancelExceptionOrRejectExceptionInNormalCodeThrows() { #if PROMISE_CANCEL Assert.Throws <InvalidOperationException>(() => Promise.CancelException()); Assert.Throws <InvalidOperationException>(() => Promise.CancelException("Cancel!")); #endif Assert.Throws <InvalidOperationException>(() => Promise.RejectException("Reject!")); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }
public void AccessingCancelExceptionOrRejectExceptionInOnRejectedDoesNotThrow() { var promise1 = Promise.Rejected("Reject!"); var promise2 = Promise.Rejected <int, string>("Reject!"); TestHelper.AddCallbacks <int, string, string>(promise1, onReject: (string rej) => { Promise.CancelException(); Promise.CancelException("Cancel!"); Promise.RejectException("Reject!"); }, onUnknownRejection: () => { Promise.CancelException(); Promise.CancelException("Cancel!"); Promise.RejectException("Reject!"); }); TestHelper.AddCallbacks <int, bool, string, string>(promise2, onReject: (string rej) => { Promise.CancelException(); Promise.CancelException("Cancel!"); Promise.RejectException("Reject!"); }, onUnknownRejection: () => { Promise.CancelException(); Promise.CancelException("Cancel!"); Promise.RejectException("Reject!"); }); Promise.Manager.HandleCompletes(); TestHelper.Cleanup(); }
public void AccessingCancelExceptionOrRejectExceptionInOnResolvedDoesNotThrow() { var promise1 = Promise.Resolved(); var promise2 = Promise.Resolved(100); TestHelper.AddCallbacks <int, object, string>(promise1, onResolve: () => { Promise.CancelException(); Promise.CancelException("Cancel!"); Promise.RejectException("Reject!"); }); TestHelper.AddCallbacks <int, bool, object, string>(promise2, onResolve: v => { Promise.CancelException(); Promise.CancelException("Cancel!"); Promise.RejectException("Reject!"); }); Promise.Manager.HandleCompletes(); TestHelper.Cleanup(); }
public void ThrowingCancelExceptionInOnRejectedCancelsThePromiseWithTheGivenValue() { var promise1 = Promise.Rejected("Rejected"); var promise2 = Promise.Rejected <int, string>("Rejected"); int voidCancelations = 0; int intCancelations = 0; string expected = "Cancel!"; Action <Promise> callback = p => { p.CatchCancelation(reason => { Assert.AreEqual(expected, reason.Value); ++voidCancelations; }); throw Promise.CancelException(expected); }; Action <Promise> callbackT = p => { p.CatchCancelation(reason => { Assert.AreEqual(expected, reason.Value); ++intCancelations; }); throw Promise.CancelException(expected); }; TestHelper.AddCallbacks <int, object, string>(promise1, promiseToVoid: callback, promiseToConvert: p => { callback(p); return(0); }, promiseToPromise: p => { callback(p); return(Promise.Resolved()); }, promiseToPromiseConvert: p => { callback(p); return(Promise.Resolved(0)); } ); TestHelper.AddContinueCallbacks <int, string>(promise1, promiseToVoid: callback, promiseToConvert: p => { callback(p); return(0); }, promiseToPromise: p => { callback(p); return(Promise.Resolved()); }, promiseToPromiseConvert: p => { callback(p); return(Promise.Resolved(0)); } ); TestHelper.AddCallbacks <int, bool, object, string>(promise2, promiseToVoid: callbackT, promiseToConvert: p => { callbackT(p); return(false); }, promiseToPromise: p => { callbackT(p); return(Promise.Resolved()); }, promiseToPromiseConvert: p => { callbackT(p); return(Promise.Resolved(false)); } ); TestHelper.AddContinueCallbacks <int, int, string>(promise2, promiseToVoid: callbackT, promiseToConvert: p => { callbackT(p); return(0); }, promiseToPromise: p => { callbackT(p); return(Promise.Resolved()); }, promiseToPromiseConvert: p => { callbackT(p); return(Promise.Resolved(0)); } ); Promise.Manager.HandleCompletes(); Assert.AreEqual(TestHelper.rejectVoidVoidCallbacks + TestHelper.rejectVoidConvertCallbacks + TestHelper.rejectVoidPromiseVoidCallbacks + TestHelper.rejectVoidPromiseConvertCallbacks + TestHelper.continueVoidVoidCallbacks + TestHelper.continueVoidConvertCallbacks + TestHelper.continueVoidPromiseVoidCallbacks + TestHelper.continueVoidPromiseConvertCallbacks, voidCancelations); Assert.AreEqual(TestHelper.rejectTVoidCallbacks + TestHelper.rejectTConvertCallbacks + TestHelper.rejectTPromiseVoidCallbacks + TestHelper.rejectTPromiseConvertCallbacks + TestHelper.continueTVoidCallbacks + TestHelper.continueTConvertCallbacks + TestHelper.continueTPromiseVoidCallbacks + TestHelper.continueTPromiseConvertCallbacks, intCancelations); // Clean up. GC.Collect(); Promise.Manager.HandleCompletesAndProgress(); LogAssert.NoUnexpectedReceived(); }