public void TestReparentChild()
        {
            var root = new TestNode("Root");

            var child0 = new TestNode("0");
            var child1 = new TestNode("1");
            var child2 = new TestNode("2");

            child0.Parent = root;
            child1.Parent = root;
            child2.Parent = child1;

            child0.Parent = child2;

            Arrange.VerifyRelationship(child2, child0);
            Arrange.VerifyRelationship(root, child1);
            Arrange.VerifyRelationship(child1, child2);

            Assert.AreEqual(Arrange.GetNodeCount(root), 4);
        }
        public static string VerifyRelationship(TestNode parent, TestNode child)
        {
            string reason = string.Empty;

            if (child.Parent != parent)
            {
                reason += "Child not pointing to parent";
            }
            int count = CountChildReferences(parent, child);

            if (count == 0)
            {
                reason += "Child not contained by parent";
            }
            if (count > 1)
            {
                reason += $"Child contained by parent {count} times";
            }

            return(reason);
        }
Пример #3
0
        public void TestNewChildren()
        {
            ObservableCollection <TestNode> childNodes = new ObservableCollection <TestNode>();

            childNodes.Add(new TestNode("0"));
            childNodes.Add(new TestNode("1"));
            childNodes.Add(new TestNode("2"));

            var root = new TestNode(childNodes, "Root");

            Arrange.VerifyRelationship(root, childNodes[0]);
            Arrange.VerifyRelationship(root, childNodes[1]);
            Arrange.VerifyRelationship(root, childNodes[2]);

            var manager = new TreeItemsSourceManager <TestNode>(true, root, (node) => true, (node) => ((TestNode)node).Children);

            //manager.IsVisible = true;
            manager.IsExpanded = true;

            Debug.WriteLine(manager);
        }
        public void TestBasicTreeByParent()
        {
            var root = new TestNode("Root");

            var child0 = new TestNode("0");
            var child1 = new TestNode("1");
            var child2 = new TestNode("2");


            child0.Parent = root;
            child1.Parent = root;
            child2.Parent = root;
            Arrange.VerifyRelationship(root, child0);
            Arrange.VerifyRelationship(root, child1);
            Arrange.VerifyRelationship(root, child2);

            Assert.AreEqual(Arrange.GetNodeCount(root), 4);

            TestNode s = root;

            Debug.WriteLine(s);
        }
Пример #5
0
        public void TestParentToDescendant()
        {
            var root = new TestNode("Root");

            var manager = new TreeItemsSourceManager <TestNode>(true, root, (node) => true, (node) => ((TestNode)node).Children);

            //manager.IsVisible = true;
            manager.IsExpanded = true;
            var child0 = new TestNode("0");
            var child1 = new TestNode("1");
            var child2 = new TestNode("2");

            root.Children.Add(child0);
            child0.Children.Add(child1);
            child1.Children.Add(child2);

            Arrange.VerifyRelationship(root, child0);
            Arrange.VerifyRelationship(child0, child1);
            Arrange.VerifyRelationship(child1, child2);

            //manager.IsVisible = true;
            manager.IsExpanded = true;

            Debug.WriteLine(manager);

            try
            {
                child1.Parent = child2;
                Assert.Fail("Cyclic dependency.");
            }
            catch (TreeZeroException ex)
            {
                Assert.AreEqual(ExceptionReason.ParentToDescendant, ex.Reason);
            }
            catch (Exception ex)
            {
                Assert.Fail($"Wrong exception:{ex}");
            }
        }
        public void TestRemoveChild()
        {
            var root = new TestNode("Root");

            var child0 = new TestNode("0");
            var child1 = new TestNode("1");
            var child2 = new TestNode("2");

            child0.Parent = root;
            child1.Parent = root;
            child2.Parent = root;

            Arrange.VerifyRelationship(root, child0);

            Arrange.VerifyRelationship(root, child1);
            root.Children.Remove(child1);
            Assert.AreEqual(0, Arrange.CountChildReferences(root, child1));
            Assert.AreEqual(null, child1.Parent);

            Arrange.VerifyRelationship(root, child2);

            Assert.AreEqual(Arrange.GetNodeCount(root), 3);
        }
Пример #7
0
        public void TestNewChildrenFail()
        {
            ObservableCollection <TestNode> childNodes = new ObservableCollection <TestNode>();

            childNodes.Add(new TestNode("0"));
            childNodes.Add(new TestNode("1"));
            childNodes.Add(new TestNode("2"));

            var root = new TestNode(childNodes, "Root");

            try
            {
                var root2 = new TestNode(childNodes, "Root");
                Assert.Fail("Added same node to two roots");
            }
            catch (TreeZeroException ex)
            {
                Assert.AreEqual(ExceptionReason.CollectionItemAlreadyParented, ex.Reason);
            }
            catch (Exception ex)
            {
                Assert.Fail($"Wrong exception:{ex}");
            }
        }
 public static void BuildTestTree(TestNode root, int depth, int childNodeCount)
 {
     _createdIndex = 0;
     _BuildTestTree(root, depth, childNodeCount);
 }
        /// <summary>
        /// Pick a random node and a suitable node we can move it to.
        /// We cannot move a node to itself or to a descendant of itself.
        /// </summary>
        /// <param name="root">The root of the tree</param>
        /// <param name="nodeCount">Number of nodes in the tree</param>
        /// <param name="child">out the node that can be moved</param>
        /// <param name="newParent">out the Parent the node can be moved to</param>
        private void GetTwoSuitableNodes(TestNode root, int nodeCount, out TestNode child, out TestNode newParent)
        {
            do
            {
                int first  = _rand.Next(nodeCount);
                int second = _rand.Next(nodeCount);

                child     = GetItemAtIndex(root, first);
                newParent = GetItemAtIndex(root, second);
            }while (newParent.IsChildOf(child) || child == newParent || child.Parent == newParent);
        }
        private void TestTreeGridAgainstData(TreeItemsSourceManager <TestNode> manager, TestNode root)
        {
            Arrange.ExpandTreeGridNodes(manager);

            _monsterCount = 0;
            _testTreeGridAgainstData(manager, root);
            Debug.WriteLine($"MONSTER COUNT {_monsterCount}");
        }