public void TestAdaptee() { // Construct a tree. // root // a // aa // ab // b // ba var treeView = new MyItemTreeView(); var a = new MyNode("a"); var aa = new MyNode("aa"); var ab = new MyNode("ab"); var b = new MyNode("b"); var ba = new MyNode("ba"); treeView.Root.Children.Add(a); a.Children.Add(aa); a.Children.Add(ab); treeView.Root.Children.Add(b); b.Children.Add(ba); var treeViewModel = new TreeViewModel(); var treeViewWithSelection = new TreeViewWithSelection(treeView); treeViewModel.Adaptee = treeViewWithSelection; treeViewModel.AutoExpand = AutoExpandMode.Disabled; // Test ShowRoot being false. treeViewModel.ShowRoot = false; treeViewModel.CollapseAll(); var expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); var rootModelNode = treeViewModel.Root; Assert.IsFalse(rootModelNode.IsVisible); Assert.IsFalse(rootModelNode.IsSelected); // Expand to first leaf ("aa") with ShowRoot being false. Node firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); // Test ShowRoot being true. treeViewModel.ShowRoot = true; treeViewModel.CollapseAll(); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); // Expand to first leaf ("aa") with ShowRoot being true. firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); // Test ExpandAll treeViewModel.ExpandAll(); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 6); Assert.AreEqual(treeViewWithSelection, treeViewModel.Adaptee); Assert.AreEqual(treeViewModel.AutoExpand, AutoExpandMode.Disabled); Assert.IsTrue(treeViewModel.ShowRoot); }
public void TestAdaptee() { // Construct a tree. // root // a // aa // ab // b // ba var treeView = new MyItemTreeView(); var a = new MyNode("a"); var aa = new MyNode("aa"); var ab = new MyNode("ab"); var b = new MyNode("b"); var ba = new MyNode("ba"); treeView.Root.Children.Add(a); a.Children.Add(aa); a.Children.Add(ab); treeView.Root.Children.Add(b); b.Children.Add(ba); var treeViewModel = new TreeViewModel(); var treeViewWithSelection = new TreeViewWithSelection(treeView); treeViewModel.Adaptee = treeViewWithSelection; treeViewModel.AutoExpand = AutoExpandMode.Disabled; // Test ShowRoot being false. treeViewModel.ShowRoot = false; treeViewModel.CollapseAll(); var expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); var rootModelNode = treeViewModel.Root; Assert.IsFalse(rootModelNode.IsVisible); Assert.IsFalse(rootModelNode.IsSelected); // Expand to first leaf ("aa") with ShowRoot being false. Node firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); // Test ShowRoot being true. treeViewModel.ShowRoot = true; treeViewModel.CollapseAll(); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); // Expand to first leaf ("aa") with ShowRoot being true. firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); // Test ExpandAll treeViewModel.ExpandAll(); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 6); Assert.AreEqual(treeViewWithSelection, treeViewModel.Adaptee); Assert.AreEqual(treeViewModel.AutoExpand, AutoExpandMode.Disabled); Assert.IsTrue(treeViewModel.ShowRoot); }
public void TestGetInfoCalls() { // Construct a tree. // root // a // aa // ab // b // ba var treeView = new MyItemTreeView(); var a = new MyNode("a"); var aa = new MyNode("aa"); var ab = new MyNode("ab"); var b = new MyNode("b"); var ba = new MyNode("ba"); treeView.Root.Children.Add(a); a.Children.Add(aa); a.Children.Add(ab); treeView.Root.Children.Add(b); b.Children.Add(ba); var treeViewModel = new TreeViewModel(treeView); // Test ShowRoot being false. treeViewModel.ShowRoot = false; treeViewModel.CollapseAll(); treeView.NodesQueried.Clear(); treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo() var expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); var rootModelNode = treeViewModel.Root; Assert.IsFalse(rootModelNode.IsVisible); Assert.IsFalse(rootModelNode.IsSelected); //IItemView.GetInfo() should not be called on collapsed nodes. Assert.IsFalse(treeView.NodesQueried.Contains(aa)); // Expand to first leaf ("aa") with ShowRoot being false. Node firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); treeView.NodesQueried.Clear(); treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo() Assert.IsTrue(treeView.NodesQueried.Contains(aa)); Assert.IsTrue(treeView.NodesQueried.Contains(a)); Assert.IsFalse(treeView.NodesQueried.Contains(ba)); // Test ShowRoot being true. treeViewModel.ShowRoot = true; treeViewModel.CollapseAll(); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); // Expand to first leaf ("aa") with ShowRoot being true. treeView.NodesQueried.Clear(); firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); // Test ExpandAll treeView.NodesQueried.Clear(); treeViewModel.ExpandAll(); treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo() expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 6); Assert.IsTrue(treeView.NodesQueried.Count == 6); Assert.AreEqual(treeView, treeViewModel.Adaptee); Assert.IsTrue(treeViewModel.ShowRoot); }
public void TestGetInfoCalls() { // Construct a tree. // root // a // aa // ab // b // ba var treeView = new MyItemTreeView(); var a = new MyNode("a"); var aa = new MyNode("aa"); var ab = new MyNode("ab"); var b = new MyNode("b"); var ba = new MyNode("ba"); treeView.Root.Children.Add(a); a.Children.Add(aa); a.Children.Add(ab); treeView.Root.Children.Add(b); b.Children.Add(ba); var treeViewModel = new TreeViewModel(treeView); // Test ShowRoot being false. treeViewModel.ShowRoot = false; treeViewModel.CollapseAll(); treeView.NodesQueried.Clear(); treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo() var expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); var rootModelNode = treeViewModel.Root; Assert.IsFalse(rootModelNode.IsVisible); Assert.IsFalse(rootModelNode.IsSelected); //IItemView.GetInfo() should not be called on collapsed nodes. Assert.IsFalse(treeView.NodesQueried.Contains(aa)); // Expand to first leaf ("aa") with ShowRoot being false. Node firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); treeView.NodesQueried.Clear(); treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo() Assert.IsTrue(treeView.NodesQueried.Contains(aa)); Assert.IsTrue(treeView.NodesQueried.Contains(a)); Assert.IsFalse(treeView.NodesQueried.Contains(ba)); // Test ShowRoot being true. treeViewModel.ShowRoot = true; treeViewModel.CollapseAll(); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 0); // Expand to first leaf ("aa") with ShowRoot being true. treeView.NodesQueried.Clear(); firstLeaf = treeViewModel.ExpandToFirstLeaf(); Assert.IsTrue(firstLeaf.Adaptee == aa); expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded" Assert.IsTrue(expandedList[0] == treeView.Root); Assert.IsTrue(expandedList[1] == a); Assert.IsTrue(expandedList[2] == aa); // Test ExpandAll treeView.NodesQueried.Clear(); treeViewModel.ExpandAll(); treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo() expandedList = treeViewModel.GetExpandedItems().ToList(); Assert.IsTrue(expandedList.Count == 6); Assert.IsTrue(treeView.NodesQueried.Count == 6); Assert.AreEqual(treeView, treeViewModel.Adaptee); Assert.IsTrue(treeViewModel.ShowRoot); }