예제 #1
0
        public void Setting_SelectedItem_Should_Set_Selection()
        {
            var items = new[]
            {
                new TabItem
                {
                    Name = "first"
                },
                new TabItem
                {
                    Name = "second"
                },
            };

            var target = new TabStrip
            {
                Template     = new FuncControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items        = items,
                SelectedItem = items[1],
            };

            target.ApplyTemplate();

            Assert.Equal(1, target.SelectedIndex);
            Assert.Same(items[1], target.SelectedItem);
        }
예제 #2
0
        public void Removing_Selected_Should_Select_Next()
        {
            var items = new ObservableCollection <TabItem>()
            {
                new TabItem
                {
                    Name = "first"
                },
                new TabItem
                {
                    Name = "second"
                },
                new TabItem
                {
                    Name = "3rd"
                },
            };

            var target = new TabStrip
            {
                Template = new FuncControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = items
            };

            target.ApplyTemplate();
            target.SelectedItem = items[1];
            Assert.Same(items[1], target.SelectedItem);
            items.RemoveAt(1);

            // Assert for former element [2] now [1] == "3rd"
            Assert.Equal(1, target.SelectedIndex);
            Assert.Same(items[1], target.SelectedItem);
            Assert.Same("3rd", ((TabItem)target.SelectedItem).Name);
        }
예제 #3
0
        public void First_Tab_Should_Be_Selected_By_Default()
        {
            var items = new[]
            {
                new TabItem
                {
                    Name = "first"
                },
                new TabItem
                {
                    Name = "second"
                },
            };

            var target = new TabStrip
            {
                Template = new FuncControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = items,
            };

            target.ApplyTemplate();

            Assert.Equal(0, target.SelectedIndex);
            Assert.Same(items[0], target.SelectedItem);
        }
예제 #4
0
        public void Removing_Selected_Should_Select_Next()
        {
            var list = new ObservableCollection <TabItem>()
            {
                new TabItem
                {
                    Name = "first"
                },
                new TabItem
                {
                    Name = "second"
                },
                new TabItem
                {
                    Name = "3rd"
                },
            };

            var target = new TabStrip
            {
                Template = new ControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = list
            };

            target.ApplyTemplate();
            target.SelectedTab = list[1];
            Assert.Same(list[1], target.SelectedTab);
            list.RemoveAt(1);

            // Assert for former element [2] now [1] == "3rd"
            Assert.Same(list[1], target.SelectedTab);
            Assert.Same("3rd", target.SelectedTab.Name);
        }
        public void Header_Of_IHeadered_Items_Should_Be_Used()
        {
            var items = new[]
            {
#pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast
                Mock.Of <IHeadered>(x => x.Header == "foo"),
                Mock.Of <IHeadered>(x => x.Header == "bar"),
#pragma warning restore CS0252 // Possible unintended reference comparison; left hand side needs cast
            };

            var target = new TabStrip
            {
                Template = new FuncControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = items,
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            var result = target.GetLogicalChildren()
                         .OfType <TabStripItem>()
                         .Select(x => x.Content)
                         .ToList();

            Assert.Equal(new[] { "foo", "bar" }, result);
        }
예제 #6
0
        public void Setting_SelectedTab_Should_Set_SelectedItem()
        {
            var target = new TabStrip
            {
                Template = new ControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = new[]
                {
                    new TabItem
                    {
                        Name = "first"
                    },
                    new TabItem
                    {
                        Name = "second"
                    },
                }
            };

            target.ApplyTemplate();
            target.SelectedTab = target.Items.Cast <TabItem>().ElementAt(1);

            Assert.Same(target.SelectedItem, target.SelectedTab);
        }
예제 #7
0
        public void First_Tab_Should_Be_Selected_By_Default()
        {
            var target = new TabStrip
            {
                Template = new ControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = new[]
                {
                    new TabItem
                    {
                        Name = "first"
                    },
                    new TabItem
                    {
                        Name = "second"
                    },
                }
            };

            target.ApplyTemplate();

            Assert.Equal(target.Items.Cast <TabItem>().First(), target.SelectedItem);
            Assert.Equal(target.Items.Cast <TabItem>().First(), target.SelectedTab);
        }
예제 #8
0
        public void Data_Of_Non_IHeadered_Items_Should_Be_Used()
        {
            var items = new[]
            {
                "foo",
                "bar"
            };

            var target = new TabStrip
            {
                Template = new FuncControlTemplate <TabStrip>(CreateTabStripTemplate),
                Items    = items,
            };

            target.ApplyTemplate();

            var result = target.GetLogicalChildren()
                         .OfType <TabStripItem>()
                         .Select(x => x.Content)
                         .ToList();

            Assert.Equal(new[] { "foo", "bar" }, result);
        }