Exemple #1
0
        public static void Component_GetComponentFromParentTest()
        {
            using (var component = new TestComponent())
                using (var parent = new TestUpdateableComponent()) {
                    component.Parent = parent;

                    var result = component.GetComponentFromParent <TestUpdateableComponent>();
                    Assert.AreEqual(parent, result);
                }
        }
Exemple #2
0
        public static void Component_GetComponentFromParent_OnceRemovedTest()
        {
            using (var component = new TestComponent())
                using (var parent1 = new TestComponent())
                    using (var parent2 = new TestUpdateableComponent()) {
                        parent1.Parent   = parent2;
                        component.Parent = parent1;

                        var result = component.GetComponentFromParent <TestUpdateableComponent>();
                        Assert.AreEqual(parent2, result);
                    }
        }
Exemple #3
0
        public static void Component_GetComponentsInChildrenTest()
        {
            using (var component1 = new TestComponent())
                using (var component2 = new TestComponent())
                    using (var component3 = new TestComponent())
                        using (var component4 = new TestComponent()) {
                            component2.Parent = component1;
                            component3.Parent = component2;
                            component4.Parent = component2;

                            var testComponents = new TestUpdateableComponent[10];
                            var sequencers     = new SpriteAnimator[10];

                            for (var i = 0; i < 10; i++)
                            {
                                if (i % 4 == 0)
                                {
                                    testComponents[i] = component1.AddChild <TestUpdateableComponent>();
                                    sequencers[i]     = component1.AddChild <SpriteAnimator>();
                                }
                                else if (i % 3 == 0)
                                {
                                    testComponents[i] = component2.AddChild <TestUpdateableComponent>();
                                    sequencers[i]     = component2.AddChild <SpriteAnimator>();
                                }
                                else if (i % 2 == 0)
                                {
                                    testComponents[i] = component3.AddChild <TestUpdateableComponent>();
                                    sequencers[i]     = component3.AddChild <SpriteAnimator>();
                                }
                                else
                                {
                                    testComponents[i] = component4.AddChild <TestUpdateableComponent>();
                                    sequencers[i]     = component4.AddChild <SpriteAnimator>();
                                }
                            }

                            var result1 = component1.GetComponentsInChildren <TestUpdateableComponent>();
                            Assert.AreEqual(result1.Count, testComponents.Length);
                            foreach (var component in testComponents)
                            {
                                Assert.Contains(component, result1);
                            }

                            var result2 = component1.GetComponentsInChildren <SpriteAnimator>();
                            Assert.AreEqual(result2.Count, sequencers.Length);
                            foreach (var component in sequencers)
                            {
                                Assert.Contains(component, result2);
                            }
                        }
        }
Exemple #4
0
        public static void Component_GetComponentInChildrenTest()
        {
            using (var component1 = new TestComponent("1"))
                using (var component2 = new TestComponent("2"))
                    using (var component3 = new TestComponent("3"))
                        using (var component4 = new TestComponent("4")) {
                            component1.AddChild(component2);
                            component2.AddChild(component3);
                            component3.AddChild(component4);

                            var testComponent = new TestUpdateableComponent();
                            component4.AddChild(testComponent);
                            component2.AddChild(new SpriteAnimator());
                            component3.AddChild(new Body());
                            component4.AddChild(new SpriteAnimator());

                            Assert.AreEqual(testComponent, component1.GetComponentInChildren <TestUpdateableComponent>(false));
                            Assert.IsNull(component1.GetComponentInChildren <TestUpdateableComponent>(true));
                        }
        }