public void TestResetItemsSource()
        {
            AvalonTestRunner.RunInSTA(delegate
              {
                  //populate sample data
                  List<string> businessObjects = new List<string>(4);
                  businessObjects.Add("A");
                  businessObjects.Add("AA");
                  businessObjects.Add("AAA");
                  businessObjects.Add("AAAA");
                  businessObjects.Add("AAAA");

                  TreeListBox treeListBox = new TreeListBox();
                  treeListBox.ExposedGenerateItemsSource(businessObjects);

                  //check that there are 4 items in the items source and that they are of type TreeLiistBoxInfo
                  Assert.AreEqual(5, treeListBox.Items.Count,
                                  "Invalid number of items added");
                  for (int i = 0; i < treeListBox.Items.Count; i++)
                  {
                      Assert.AreEqual(typeof (TreeListBoxInfo),
                                      treeListBox.Items[i].GetType(),
                                      "Invalid type added to tree list box");
                  }
              });
        }
Beispiel #2
0
        /// <summary>
        /// constructor for the TreeListBoxItem
        /// </summary>
        /// <param name="parent">The parent TreeListBox</param>
        public TreeListBoxItem(TreeListBox parent)
        {
            treeListBox = parent;

            Unloaded += delegate
            {
                if (!currentInfo.IsExpanded)
                    UnRegisterCollectionNotification();
            };
        }
        /// <summary>
        /// constructor for the TreeListBoxItem
        /// </summary>
        /// <param name="parent">The parent TreeListBox</param>
        public TreeListBoxItem(TreeListBox parent)
        {
            treeListBox = parent;

            Unloaded += delegate
            {
                if (!currentInfo.IsExpanded)
                {
                    UnRegisterCollectionNotification();
                }
            };
        }
        public void TestItemsSourceCollectionNotifications()
        {
            AvalonTestRunner.RunInSTA(delegate
              {
                  //populate sample data
                  ObservableCollection<string> businessObjects =
                      new ObservableCollection<string>();
                  businessObjects.Add("A");
                  businessObjects.Add("AA");
                  businessObjects.Add("AAA");
                  businessObjects.Add("AAAA");

                  TreeListBox treeListBox = new TreeListBox();
                  treeListBox.ExposedGenerateItemsSource(businessObjects);
                  Assert.AreEqual(4, treeListBox.Items.Count,
                                  "Invalid number of items added");

                  //add anew item and verify that this item was added to the items source
                  businessObjects.Add("NewItem1");
                  //check the Count
                  Assert.AreEqual(5, treeListBox.Items.Count,
                                  "Invalid number of items added");
                  //check the position of the item
                  Assert.AreEqual("NewItem1",
                                  ((TreeListBoxInfo) treeListBox.Items[4]).DataItem,
                                  "Item was added at an invalid index");

                  //insert another item in the begining of the list
                  businessObjects.Insert(1, "NewItem2");
                  //check the Count
                  Assert.AreEqual(6, treeListBox.Items.Count,
                                  "Invalid number of items added");
                  //check the position of the item
                  Assert.AreEqual("NewItem2",
                                  ((TreeListBoxInfo) treeListBox.Items[1]).DataItem,
                                  "Item was added at an invalid index");

                  //Check the remove
                  businessObjects.RemoveAt(1);
                  //check the Count
                  Assert.AreEqual(5, treeListBox.Items.Count,
                                  "Invalid number of items added");
                  //validate that the item was deleted properly
                  for (int i = 0; i < treeListBox.Items.Count; i++)
                      Assert.AreNotEqual("NewItem2",
                                         ((TreeListBoxInfo) treeListBox.Items[i]).DataItem,
                                         "Item was removed from the wrong index");
              });
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.treeListBox = ((AC.AvalonControlsLibrary.Controls.TreeListBox)(target));
     return;
     case 2:
     
     #line 117 "..\..\VirtualizationTreeViewTest.xaml"
     ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.BulkInsertClick);
     
     #line default
     #line hidden
     return;
     case 3:
     this.visualCount = ((System.Windows.Controls.TextBlock)(target));
     return;
     }
     this._contentLoaded = true;
 }
Beispiel #6
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.noChildren = ((System.Windows.Controls.TextBox)(target));
                return;

            case 2:
                this.noLevels = ((System.Windows.Controls.TextBox)(target));
                return;

            case 3:

            #line 38 "..\..\HierarchalListBoxTest.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.ResetAndAddNew);

            #line default
            #line hidden
                return;

            case 4:
                this.testList = ((AC.AvalonControlsLibrary.Controls.TreeListBox)(target));
                return;

            case 5:
                this.testTree = ((System.Windows.Controls.TreeView)(target));
                return;

            case 6:
                this.totalVirtualizedItems = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 7:
                this.totalVirtualizedItemsForTree = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.treeListBox = ((AC.AvalonControlsLibrary.Controls.TreeListBox)(target));
                return;

            case 2:

            #line 117 "..\..\VirtualizationTreeViewTest.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.BulkInsertClick);

            #line default
            #line hidden
                return;

            case 3:
                this.visualCount = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.noChildren = ((System.Windows.Controls.TextBox)(target));
     return;
     case 2:
     this.noLevels = ((System.Windows.Controls.TextBox)(target));
     return;
     case 3:
     
     #line 38 "..\..\HierarchalListBoxTest.xaml"
     ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.ResetAndAddNew);
     
     #line default
     #line hidden
     return;
     case 4:
     this.testList = ((AC.AvalonControlsLibrary.Controls.TreeListBox)(target));
     return;
     case 5:
     this.testTree = ((System.Windows.Controls.TreeView)(target));
     return;
     case 6:
     this.totalVirtualizedItems = ((System.Windows.Controls.TextBlock)(target));
     return;
     case 7:
     this.totalVirtualizedItemsForTree = ((System.Windows.Controls.TextBlock)(target));
     return;
     }
     this._contentLoaded = true;
 }
        public void TestPopulationOfChildrenFromNotifications()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //children collection
                ObservableCollection<MockHierarchalObject> childNodes =
                    new ObservableCollection<MockHierarchalObject>(
                        new List<MockHierarchalObject>(new MockHierarchalObject[]
                                                         {
                                                             //children
                                                             new MockHierarchalObject(
                                                                 "child1 of A"),
                                                             new MockHierarchalObject(
                                                                 "child2 of A"),
                                                             new MockHierarchalObject(
                                                                 "child3 of A"),
                                                         }));

                //create sample data
                MockHierarchalObject dataSource =
                    new MockHierarchalObject("A", childNodes);

                //prepare the parent collection
                TreeListBox parentControl = new TreeListBox();
                parentControl.ChildItemSourcePath = "Children";
                parentControl.ExposedGenerateItemsSource(new MockHierarchalObject[]
                                                           {
                                                               new MockHierarchalObject(
                                                                   "First, item with no children")
                                                               ,
                                                               //add a simple item that has no children
                                                               dataSource,
                                                               //add the item that has children to test on
                                                               new MockHierarchalObject(
                                                                   "Last, item with no children")
                                                           });

                Assert.AreEqual(3, parentControl.Items.Count, "Invalid number of items");
                //create an item to test
                TreeListBoxItem item = new TreeListBoxItem(parentControl);
                item.ExposePrepareItem(parentControl.Items[1] as TreeListBoxInfo);
                //pass the info that was create for the item that has children

                //expand the item this should result in the items source of the parent include the children
                item.IsExpanded = true;
                //3 root nodes and 3 children are suppose to be in the list
                Assert.AreEqual(3 + 3, parentControl.Items.Count,
                                "Invalid number of items");

                //add a new item to child collection and check if it is added
                childNodes.Add(new MockHierarchalObject("child4 of A"));
                //3 root nodes and 3 + 1(which is the new one) children are suppose to be in the list
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items");
                //check the index of the new item in the flat list
                //1 is the index of the container item, and 4 is the count of the children
                Assert.AreEqual("child4 of A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[1 + 4]).DataItem).
                                    Text,
                                "Item was not added in the right index");

                //check that the insert in a specific index
                childNodes.Insert(2, new MockHierarchalObject("inserted child of A"));
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items");
                //check that the insert was done in the right index(where 1 is the parent index and 2 is the index in the children collection)
                Assert.AreEqual("inserted child of A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[1 + 3]).DataItem).
                                    Text,
                                "Item was not added in the right index");

                //check the remove of items
                childNodes.RemoveAt(2);
                //check the Count
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items added");
                //validate that the item was deleted properly
                for (int i = 0; i < parentControl.Items.Count; i++)
                    Assert.AreNotEqual("inserted child of A",
                                       ((MockHierarchalObject)
                                        ((TreeListBoxInfo)parentControl.Items[i]).
                                            DataItem).Text,
                                       "Item was removed from the wrong index");

                //check that if we collapse the items no children are add
                item.IsExpanded = false;
                //check that the items where collapsed
                Assert.AreEqual(3, parentControl.Items.Count,
                                "Invalid number of items after collapse item");

                childNodes.Add(new MockHierarchalObject("Test collapse"));
                //check that the item was not added to the flat list since the item is collapsed
                Assert.AreEqual(3, parentControl.Items.Count,
                                "Invalid number of items after collapse item");

                //check that when you re expand the item all items are generated
                item.IsExpanded = true;
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items after collapse item");
            });
        }
        public void TestPopulationOfChildren()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //create sample data
                MockHierarchalObject dataSource =
                    new MockHierarchalObject("A",
                                             new List<MockHierarchalObject>(
                                                 new MockHierarchalObject[]
                                                   {
                                                       //children
                                                       new MockHierarchalObject(
                                                           "child1 of A"),
                                                       new MockHierarchalObject(
                                                           "child2 of A"),
                                                       new MockHierarchalObject(
                                                           "child3 of A"),
                                                   }));

                //prepare the parent collection
                TreeListBox parentControl = new TreeListBox();
                parentControl.ChildItemSourcePath = "Children";
                parentControl.ExposedGenerateItemsSource(new MockHierarchalObject[]
                                                           {
                                                               new MockHierarchalObject(
                                                                   "First, item with no children")
                                                               ,
                                                               //add a simple item that has no children
                                                               dataSource,
                                                               //add the item that has children to test on
                                                               new MockHierarchalObject(
                                                                   "Last, item with no children")
                                                           });
                Assert.AreEqual(3, parentControl.Items.Count, "Invalid number of items");
                //create an item to test
                TreeListBoxItem item = new TreeListBoxItem(parentControl);
                item.ExposePrepareItem(parentControl.Items[1] as TreeListBoxInfo);
                //pass the info that was create for the item that has children

                //expand the item this should result in the items source of the parent include the children
                item.IsExpanded = true;
                //3 root nodes and 3 children are suppose to be in the list
                Assert.AreEqual(3 + 3, parentControl.Items.Count,
                                "Invalid number of items");

                //check that the items where create in the right indeces
                Assert.AreEqual("child1 of A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[2]).DataItem).Text,
                                "Child Item was placed in the wrong index");
                //validate that the last item(which is index to of the root nodes) of the root nodes has been moved to the proper index
                //2 is the index in the root nodes, 3 is the count of the children, so the last item should have moved to index 5
                Assert.AreEqual("Last, item with no children",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[2 + 3]).DataItem).
                                    Text,
                                "Root Item was placed in the wrong index");

                //validate that the level of the items has been incremented
                //start from index 2, since the children are place at index 2
                for (int i = 2; i < 3 + 2; i++)
                    Assert.AreEqual(1, ((TreeListBoxInfo)parentControl.Items[i]).Level,
                                    "Invalid level set for child nodes");

                //Validate the Collapse
                item.IsExpanded = false;

                //all children should be dropped
                Assert.AreEqual(3, parentControl.Items.Count, "Invalid number of items");

                //check that the indeces of the items is back to normal
                Assert.AreEqual("First, item with no children",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[0]).DataItem).Text,
                                "Root Item was placed in the wrong index");
                Assert.AreEqual("A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[1]).DataItem).Text,
                                "Root Item was placed in the wrong index");
                Assert.AreEqual("Last, item with no children",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[2]).DataItem).Text,
                                "Root Item was placed in the wrong index");
            });
        }