示例#1
0
        public void chain_multiple_promises_using_all()
        {
            var promise         = new Promise();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            promise
            .ThenAll(() => EnumerableExt.FromItems(chainedPromise1, chainedPromise2).Cast <IPromise>())
            .Then(() => ++ completed);

            Assert.Equal(0, completed);

            promise.Resolve();

            Assert.Equal(0, completed);

            chainedPromise1.Resolve();

            Assert.Equal(0, completed);

            chainedPromise2.Resolve();

            Assert.Equal(1, completed);
        }
示例#2
0
        public void chain_multiple_promises_using_all()
        {
            var promise         = new Promise();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            TestHelpers.VerifyDoesntThrowUnhandledException(() =>
            {
                promise
                .ThenAll(() => EnumerableExt.FromItems(chainedPromise1, chainedPromise2)
                         .Cast <IPromise>())
                .Then(() => ++ completed);

                Assert.Equal(0, completed);

                promise.Resolve();

                Assert.Equal(0, completed);

                chainedPromise1.Resolve();

                Assert.Equal(0, completed);

                chainedPromise2.Resolve();

                Assert.Equal(1, completed);
            });
        }
示例#3
0
        public void combined_promise_is_resolved_when_children_are_resolved()
        {
            var promise1 = new Promise <int>();
            var promise2 = new Promise <int>();

            TestHelpers.VerifyDoesntThrowUnhandledException(() =>
            {
                var all = Promise <int> .All(EnumerableExt.FromItems <IPromise <int> >(promise1, promise2));

                var completed = 0;

                all.Then(v =>
                {
                    ++completed;

                    var values = v.ToArray();
                    Assert.Equal(2, values.Length);
                    Assert.Equal(1, values[0]);
                    Assert.Equal(2, values[1]);
                });

                promise1.Resolve(1);
                promise2.Resolve(2);

                Assert.Equal(1, completed);
            });
        }
示例#4
0
        public void chain_multiple_promises_using_all_and_convert_to_non_value_promise()
        {
            var promise         = new Promise <string>();
            var chainedPromise1 = new Promise();
            var chainedPromise2 = new Promise();

            var completed = 0;

            promise
            .ThenAll(i => EnumerableExt.FromItems(chainedPromise1, chainedPromise2).Cast <IPromise>())
            .Then(() =>
            {
                ++completed;
            });

            Assert.Equal(0, completed);

            promise.Resolve("hello");

            Assert.Equal(0, completed);

            chainedPromise1.Resolve();

            Assert.Equal(0, completed);

            chainedPromise2.Resolve();

            Assert.Equal(1, completed);
        }
示例#5
0
        public void combined_promise_is_resolved_when_all_promises_are_already_resolved()
        {
            var promise1 = Promise.Resolved();
            var promise2 = Promise.Resolved();

            TestHelpers.VerifyDoesntThrowUnhandledException(() =>
            {
                var all = Promise.All(EnumerableExt.FromItems(promise1, promise2));

                var completed = 0;

                all.Then(() => ++ completed);

                Assert.Equal(1, completed);
            });
        }
示例#6
0
        public void combined_promise_is_resolved_when_all_promises_are_already_resolved()
        {
            var promise1 = Promise.Resolved();
            var promise2 = Promise.Resolved();

            var all = Promise.All(EnumerableExt.FromItems(promise1, promise2));

            var completed = 0;

            all.Then(() =>
            {
                ++completed;
            });

            Assert.Equal(1, completed);
        }
示例#7
0
        public void combined_promise_is_resolved_when_children_are_resolved()
        {
            var promise1 = new Promise();
            var promise2 = new Promise();

            var all = Promise.All(EnumerableExt.FromItems <IPromise>(promise1, promise2));

            var completed = 0;

            all.Then(() => ++ completed);

            promise1.Resolve();
            promise2.Resolve();

            Assert.Equal(1, completed);
        }
示例#8
0
        public void combined_promise_is_rejected_when_second_promise_is_rejected()
        {
            var promise1 = new Promise();
            var promise2 = new Promise();

            TestHelpers.VerifyDoesntThrowUnhandledException(() => {
                var all = Promise.All(EnumerableExt.FromItems <IPromise>(promise1, promise2));

                var errors = 0;
                all.Catch(e => { ++errors; });

                promise1.Resolve();
                promise2.Reject(new Exception("Error!"));

                Assert.Equal(1, errors);
            });
        }
示例#9
0
        public void combined_promise_is_rejected_when_both_promises_are_rejected()
        {
            var promise1 = new Promise <int>();
            var promise2 = new Promise <int>();

            TestHelpers.VerifyDoesntThrowUnhandledException(() =>
            {
                var all = Promise <int> .All(EnumerableExt.FromItems <IPromise <int> >(promise1, promise2));

                all.Then(v => throw new Exception("Shouldn't happen"));

                var errors = 0;
                all.Catch(e => { ++errors; });

                promise1.Reject(new Exception("Error!"));
                promise2.Reject(new Exception("Error!"));

                Assert.Equal(1, errors);
            });
        }
示例#10
0
        public void chain_multiple_value_promises_using_all_resolved_out_of_order()
        {
            var       promise         = new Promise();
            var       chainedPromise1 = new Promise <int>();
            var       chainedPromise2 = new Promise <int>();
            const int chainedResult1  = 10;
            const int chainedResult2  = 15;

            var completed = 0;

            TestHelpers.VerifyDoesntThrowUnhandledException(() =>
            {
                promise
                .ThenAll(() => EnumerableExt.FromItems(chainedPromise1, chainedPromise2)
                         .Cast <IPromise <int> >())
                .Then(result =>
                {
                    var items = result.ToArray();
                    Assert.Equal(2, items.Length);
                    Assert.Equal(chainedResult1, items[0]);
                    Assert.Equal(chainedResult2, items[1]);

                    ++completed;
                });

                Assert.Equal(0, completed);

                promise.Resolve();

                Assert.Equal(0, completed);

                chainedPromise2.Resolve(chainedResult2);

                Assert.Equal(0, completed);

                chainedPromise1.Resolve(chainedResult1);

                Assert.Equal(1, completed);
            });
        }
示例#11
0
        public void combined_promise_is_rejected_when_both_promises_are_rejected()
        {
            var promise1 = new Promise();
            var promise2 = new Promise();

            var all = Promise.All(EnumerableExt.FromItems <IPromise>(promise1, promise2));

            all.Then(() =>
            {
                throw new ApplicationException("Shouldn't happen");
            });

            var errors = 0;

            all.Catch(e =>
            {
                ++errors;
            });

            promise1.Reject(new ApplicationException("Error!"));
            promise2.Reject(new ApplicationException("Error!"));

            Assert.Equal(1, errors);
        }
示例#12
0
        public void chain_multiple_promises_using_all_that_are_resolved_out_of_order()
        {
            var promise         = new Promise();
            var chainedPromise1 = new Promise <int>();
            var chainedPromise2 = new Promise <int>();
            var chainedResult1  = 10;
            var chainedResult2  = 15;

            var completed = 0;

            promise
            .ThenAll(() => EnumerableExt.FromItems(chainedPromise1, chainedPromise2).Cast <IPromise <int> >())
            .Then(result =>
            {
                var items = result.ToArray();
                Assert.Equal(2, items.Length);
                Assert.Equal(chainedResult1, items[0]);
                Assert.Equal(chainedResult2, items[1]);

                ++completed;
            });

            Assert.Equal(0, completed);

            promise.Resolve();

            Assert.Equal(0, completed);

            chainedPromise1.Resolve(chainedResult1);

            Assert.Equal(0, completed);

            chainedPromise2.Resolve(chainedResult2);

            Assert.Equal(1, completed);
        }