Beispiel #1
0
        public void all_promises_are_updated_when_a_pending_promise_is_canceled_during_update()
        {
            var testObject = new PromiseTimer();

            var p1Updates = 0;
            var p2Updates = 0;
            var p3Updates = 0;

            var p1 = testObject
                     .WaitUntil(timeData =>
            {
                p1Updates++;

                return(false);
            });

            testObject
            .WaitUntil(timeData =>
            {
                p2Updates++;

                return(true);
            })
            .Then(() =>
            {
                testObject.Cancel(p1);
            });

            testObject
            .WaitUntil(timeData =>
            {
                p3Updates++;

                return(false);
            });

            testObject.Update(0.01f);

            Assert.Equal(1, p1Updates);
            Assert.Equal(1, p2Updates);
            Assert.Equal(1, p3Updates);
        }
Beispiel #2
0
        public void when_promise_is_cancelled_by_user_reject_promise()
        {
            var       testObject      = new PromiseTimer();
            Exception caughtException = null;


            var promise = testObject
                          .WaitUntil(timeData => timeData.elapsedTime > 1.0f);

            promise.Catch(ex => caughtException = ex);

            promise.Done(null, ex => caughtException = ex);

            testObject.Update(1.0f);
            testObject.Cancel(promise);
            testObject.Update(1.0f);

            Assert.IsType <PromiseCancelledException>(caughtException);
            Assert.Equal(caughtException.Message, "Promise was cancelled by user.");
        }