Ejemplo n.º 1
0
        public void TestChildren()
        {
            YogaNode parent = new YogaNode();

            foreach (YogaNode node in parent)
            {
                Assert.Fail(node.ToString());
            }

            YogaNode child0 = new YogaNode();

            Assert.AreEqual(-1, parent.IndexOf(child0));
            parent.Insert(0, child0);
            foreach (YogaNode node in parent)
            {
                Assert.AreEqual(0, parent.IndexOf(node));
            }

            YogaNode child1 = new YogaNode();

            parent.Insert(1, child1);
            int index = 0;

            foreach (YogaNode node in parent)
            {
                Assert.AreEqual(index++, parent.IndexOf(node));
            }

            parent.RemoveAt(0);
            Assert.AreEqual(-1, parent.IndexOf(child0));
            Assert.AreEqual(0, parent.IndexOf(child1));

            parent.Clear();
            Assert.AreEqual(0, parent.Count);

            parent.Clear();
            Assert.AreEqual(0, parent.Count);
        }
        /// <summary>
        /// Replaces a child Yoga node with a new one
        /// </summary>
        /// <param name="oldNode">Old Yoga node child.</param>
        /// <param name="newNode">New Yoga node child.</param>
        public void ReplaceYogaNode(YogaNode oldNode, YogaNode newNode)
        {
            if (_yogaNode == null)
            {
                throw new InvalidOperationException(
                          "Cannot replace a Yoga child node when there's no parent!");
            }

            int index = _yogaNode.IndexOf(oldNode);

            if (index < 0)
            {
                throw new InvalidOperationException(
                          "Yoga child node is not present in parent!");
            }

            _yogaNode.RemoveAt(index);
            _yogaNode.Insert(index, newNode);
        }