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 TestBuildTree() { var root = new TestNode("Root"); Arrange.BuildTestTree(root, 2, 2); Arrange.TestTreeIntegrity(root); }