Ejemplo n.º 1
0
        public void TestItemContainerGeneratorRefresh()
        {
            var items = new ObservableCollection <string>
            {
                "1",
                "2",
                "3"
            };

            var tabControl = new TabControlEx
            {
                ItemsSource = items
            };

            using (new TestWindow(tabControl))
            {
                var itemsPanel = (Panel)tabControl.GetType().GetField("itemsHolder", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(tabControl);

                var tabItemsInitial = GetTabItems(tabControl);

                Assert.That(tabItemsInitial, Has.Count.EqualTo(3));

                Assert.That(itemsPanel.Children.Count, Is.EqualTo(1));

                tabControl.ItemContainerGenerator.GetType().GetMethod("Refresh", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(tabControl.ItemContainerGenerator, null);

                UITestHelper.DoEvents();

                Assert.That(itemsPanel.Children.Count, Is.EqualTo(1));
            }
        }
Ejemplo n.º 2
0
        public void TestAddRemoveInsertWithItemsSource()
        {
            var items = new ObservableCollection <string>
            {
                "1",
                "2",
                "3"
            };

            var tabControl = new TabControlEx
            {
                ItemsSource = items
            };

            using (new TestWindow(tabControl))
            {
                var itemsPanel = (Panel)tabControl.GetType().GetField("itemsHolder", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(tabControl);

                var tabItemsInitial = GetTabItems(tabControl);

                Assert.That(tabItemsInitial, Has.Count.EqualTo(3));

                Assert.That(itemsPanel.Children.Count, Is.EqualTo(1));

                foreach (var tabItem in tabItemsInitial)
                {
                    tabItem.IsSelected = true;
                    UITestHelper.DoEvents();
                }

                Assert.That(itemsPanel.Children.Count, Is.EqualTo(3));

                items.RemoveAt(1);
                items.Insert(1, "2");

                UITestHelper.DoEvents();

                Assert.That(itemsPanel.Children.Count, Is.EqualTo(2));
            }
        }