Beispiel #1
0
        public async Task When_Collection_Reset()
        {
            var SUT = new ComboBox();

            try
            {
                WindowHelper.WindowContent = SUT;

                var c = new MyObservableCollection <string>();
                c.Add("One");
                c.Add("Two");
                c.Add("Three");

                SUT.ItemsSource = c;

                await WindowHelper.WaitForIdle();

                Assert.AreEqual(SUT.Items.Count, 3);

                using (c.BatchUpdate())
                {
                    c.Add("Four");
                    c.Add("Five");
                }

                SUT.IsDropDownOpen = true;

                // Items are materialized when the popup is opened
                await WindowHelper.WaitForIdle();

                Assert.AreEqual(SUT.Items.Count, 5);
                Assert.IsNotNull(SUT.ContainerFromItem("One"));
                Assert.IsNotNull(SUT.ContainerFromItem("Four"));
                Assert.IsNotNull(SUT.ContainerFromItem("Five"));
            }
            finally
            {
                SUT.IsDropDownOpen = false;
            }
        }
Beispiel #2
0
        public async Task When_Full_Collection_Reset()
        {
            var SUT = new ComboBox();

            SUT.ItemTemplate = new DataTemplate(() => {
                var tb = new TextBlock();
                tb.SetBinding(TextBlock.TextProperty, new Windows.UI.Xaml.Data.Binding {
                    Path = "Text"
                });
                tb.SetBinding(TextBlock.NameProperty, new Windows.UI.Xaml.Data.Binding {
                    Path = "Text"
                });

                return(tb);
            });

            try
            {
                WindowHelper.WindowContent = SUT;

                var c = new MyObservableCollection <ItemModel>();
                c.Add(new ItemModel {
                    Text = "One"
                });
                c.Add(new ItemModel {
                    Text = "Two"
                });
                c.Add(new ItemModel {
                    Text = "Three"
                });

                SUT.ItemsSource = c;

                await WindowHelper.WaitForIdle();

                SUT.IsDropDownOpen = true;

                await WindowHelper.WaitForIdle();

                SUT.IsDropDownOpen = false;

                Assert.AreEqual(SUT.Items.Count, 3);

                using (c.BatchUpdate())
                {
                    c.Clear();
                    c.Add(new ItemModel {
                        Text = "Five"
                    });
                    c.Add(new ItemModel {
                        Text = "Six"
                    });
                    c.Add(new ItemModel {
                        Text = "Seven"
                    });
                }

                SUT.IsDropDownOpen = true;

                // Items are materialized when the popup is opened
                await WindowHelper.WaitForIdle();

                Assert.AreEqual(3, SUT.Items.Count);
                Assert.IsNotNull(SUT.ContainerFromItem(c[0]));
                Assert.IsNotNull(SUT.ContainerFromItem(c[1]));
                Assert.IsNotNull(SUT.ContainerFromItem(c[2]));

                Assert.IsNotNull(SUT.FindName("Seven"));
                Assert.IsNotNull(SUT.FindName("Five"));
                Assert.IsNotNull(SUT.FindName("Six"));
            }
            finally
            {
                SUT.IsDropDownOpen = false;
            }
        }