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()); }
private void TestTreeGridAgainstData(TreeItemsSourceManager <TestNode> manager, TestNode root) { Arrange.ExpandTreeGridNodes(manager); _monsterCount = 0; _testTreeGridAgainstData(manager, root); Debug.WriteLine($"MONSTER COUNT {_monsterCount}"); }
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 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}"); } }