public void TerribleUnitTest(Action <TestNode, TestNode> method0, Action <TestNode, TestNode> method1)
        {
            var root = new TestNode("Root");

            Arrange.BuildTestTree(root, 4, 4);

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

            Arrange.ExpandTreeGridNodes(manager);

            // Used to test the tree is correct after we undo every move.
            foreach (TestNode item in TestNode.AllChildren(root))
            {
                item.OriginalParent = item.Parent;
            }

            // Ensure the tree parent/child relationships are correct.
            Arrange.TestTreeIntegrity(root);
            Debug.WriteLine(root.PrintTree());

            // Used to store moves, so we can undo them later.
            Stack <Tuple <TestNode, TestNode> > moves = new Stack <Tuple <TestNode, TestNode> >();

            int nodeCount = Arrange.GetNodeCount(root);

            for (int c = 0; c < nodeCount; c++)
            {
                TestNode child, newParent;
                GetTwoSuitableNodes(root, nodeCount, out child, out newParent);
                Debug.WriteLine($"Moving {child.Name} from {child.Parent.Name} to {newParent.Name}");
                // Store the move, so we can undo it later.
                moves.Push(new Tuple <TestNode, TestNode>(child, child.Parent));
                // Move the child to the new parent.
                method0(child, newParent);

                TestTreeGridAgainstData(manager, root);

                Assert.AreEqual(newParent, child.Parent, "Wrong parent");
                Assert.AreEqual(nodeCount, Arrange.GetNodeCount(root), "Node has gone missing");
            }
            Arrange.TestTreeIntegrity(root);
            //Debug.WriteLine(root.ToString());
            Assert.AreEqual(nodeCount, Arrange.GetNodeCount(root));

            // Undo every move.
            // NOTE: The tree will be back to its starting shape, but the order of node Children may be different.
            while (moves.TryPop(out var move))
            {
                method1(move.Item1, move.Item2);
                TestTreeGridAgainstData(manager, root);
            }

            // Ensure the tree has the same shape we started with, allowing for node Children to be in a different order.
            foreach (TestNode item in TestNode.AllChildren(root))
            {
                Assert.AreEqual(item.OriginalParent, item.Parent);
            }

            //Debug.WriteLine(root.PrintTree());
        }
        public void TestNestChild()
        {
            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;

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

            Assert.AreEqual(Arrange.GetNodeCount(root), 4);
        }
        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);
        }
        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);
        }