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 => LinqExts.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); }
public void chain_multiple_promises_using_all() { var promise = new Promise(); var chainedPromise1 = new Promise(); var chainedPromise2 = new Promise(); var completed = 0; promise .ThenAll(() => LinqExts.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); }
public void select_one_returns_first_item_from_select_all() { Init(); var mockGameObject1 = new Mock <GameObject>(); var mockGameObject2 = new Mock <GameObject>(); var selector = "foo"; var mockQuery = new Mock <IQuery>(); mockQueryParser .Setup(m => m.Parse(selector)) .Returns(mockQuery.Object); mockQuery .Setup(m => m.Match(mockGameObject1.Object)) .Returns(true); mockQuery .Setup(m => m.Match(mockGameObject2.Object)) .Returns(true); mockSceneTraversal .Setup(m => m.PreOrderHierarchy()) .Returns(LinqExts.FromItems(mockGameObject1.Object, mockGameObject2.Object)); Assert.Equal(mockGameObject1.Object, testObject.SelectOne(selector)); }
public void select_all_passes_objects_through_filter_created_by_parser() { Init(); var selector = "foo"; var mockQuery = new Mock <IQuery>(); mockQueryParser .Setup(m => m.Parse(selector)) .Returns(mockQuery.Object); var mockGameObject1 = new Mock <GameObject>(); mockQuery .Setup(m => m.Match(mockGameObject1.Object)) .Returns(false); var mockGameObject2 = new Mock <GameObject>(); mockQuery .Setup(m => m.Match(mockGameObject2.Object)) .Returns(true); mockSceneTraversal .Setup(m => m.PreOrderHierarchy()) .Returns(LinqExts.FromItems(mockGameObject1.Object, mockGameObject2.Object)); var testOutput = new GameObject[] { mockGameObject2.Object }; Assert.Equal(testOutput, testObject.SelectAll(selector)); }
public void can_filter_collection_of_game_objects() { Init(); var selector = "some-selector"; var mockQuery = new Mock <IQuery>(); mockQueryParser .Setup(m => m.Parse(selector)) .Returns(mockQuery.Object); var mockGameObject1 = new Mock <GameObject>(); var mockGameObject2 = new Mock <GameObject>(); var mockGameObject3 = new Mock <GameObject>(); mockQuery .Setup(m => m.Match(mockGameObject1.Object)) .Returns(false); mockQuery .Setup(m => m.Match(mockGameObject2.Object)) .Returns(true); mockQuery .Setup(m => m.Match(mockGameObject3.Object)) .Returns(false); var output = testObject.Filter(LinqExts.FromItems(mockGameObject1.Object, mockGameObject2.Object, mockGameObject3.Object), selector).ToArray(); Assert.Equal(1, output.Length); Assert.Equal(mockGameObject2.Object, output[0]); }
public void expect_one_throws_exception_on_multiple_matching_child_game_objects() { Init(); var mockParentGameObject = new Mock <GameObject>(); var selector = "some-selector"; var mockQuery = new Mock <IQuery>(); mockQueryParser .Setup(m => m.Parse(selector)) .Returns(mockQuery.Object); var mockGameObject1 = new Mock <GameObject>(); var mockGameObject2 = new Mock <GameObject>(); mockQuery .Setup(m => m.Match(mockGameObject1.Object)) .Returns(true); mockQuery .Setup(m => m.Match(mockGameObject2.Object)) .Returns(true); mockSceneTraversal .Setup(m => m.PreOrderHierarchy(mockParentGameObject.Object)) .Returns(LinqExts.FromItems(mockGameObject1.Object, mockGameObject2.Object)); Assert.Throws <ApplicationException>(() => testObject.ExpectOne(mockParentGameObject.Object, selector)); }
public void combined_promise_is_resolved_when_all_promises_are_already_resolved() { var promise1 = Promise.Resolved(); var promise2 = Promise.Resolved(); var all = Promise.All(LinqExts.FromItems(promise1, promise2)); var completed = 0; all.Then(() => { ++completed; }); Assert.Equal(1, completed); }
public void combined_promise_is_resolved_when_children_are_resolved() { var promise1 = new Promise(); var promise2 = new Promise(); var all = Promise.All(LinqExts.FromItems <IPromise>(promise1, promise2)); var completed = 0; all.Then(() => ++ completed); promise1.Resolve(); promise2.Resolve(); Assert.Equal(1, completed); }
public void combined_promise_is_rejected_when_both_promises_are_rejected() { var promise1 = new Promise(); var promise2 = new Promise(); var all = Promise.All(LinqExts.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); }
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>(); var chainedResult1 = 10; var chainedResult2 = 15; var completed = 0; promise .ThenAll(() => LinqExts.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); }
public void combined_promise_is_resolved_when_children_are_resolved() { var promise1 = new Promise <int>(); var promise2 = new Promise <int>(); var all = Promise <int> .All(LinqExts.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); }