Beispiel #1
0
        public TestCaseTabControl()
        {
            List <KeyValuePair <string, TestEnum> > items = new List <KeyValuePair <string, TestEnum> >();

            foreach (var val in (TestEnum[])Enum.GetValues(typeof(TestEnum)))
            {
                items.Add(new KeyValuePair <string, TestEnum>(val.GetDescription(), val));
            }

            StyledTabControl simpleTabcontrol = new StyledTabControl
            {
                Position = new Vector2(200, 50),
                Size     = new Vector2(200, 30),
            };

            items.AsEnumerable().ForEach(item => simpleTabcontrol.AddItem(item.Value));

            StyledTabControl pinnedAndAutoSort = new StyledTabControl
            {
                Position = new Vector2(500, 50),
                Size     = new Vector2(200, 30),
                AutoSort = true
            };

            items.GetRange(0, 7).AsEnumerable().ForEach(item => pinnedAndAutoSort.AddItem(item.Value));
            pinnedAndAutoSort.PinItem(TestEnum.Test5);

            Add(simpleTabcontrol);
            Add(pinnedAndAutoSort);

            var nextTest = new Func <TestEnum>(() => items.AsEnumerable()
                                               .Select(item => item.Value)
                                               .FirstOrDefault(test => !pinnedAndAutoSort.Items.Contains(test)));

            Stack <TestEnum> pinned = new Stack <TestEnum>();

            AddStep("AddItem", () =>
            {
                var item = nextTest.Invoke();
                if (!pinnedAndAutoSort.Items.Contains(item))
                {
                    pinnedAndAutoSort.AddItem(item);
                }
            });

            AddStep("RemoveItem", () =>
            {
                if (pinnedAndAutoSort.Any())
                {
                    pinnedAndAutoSort.RemoveItem(pinnedAndAutoSort.Items.Last());
                }
            });

            AddStep("PinItem", () =>
            {
                var item = nextTest.Invoke();

                if (!pinnedAndAutoSort.Items.Contains(item))
                {
                    pinned.Push(item);
                    pinnedAndAutoSort.AddItem(item);
                    pinnedAndAutoSort.PinItem(item);
                }
            });

            AddStep("UnpinItem", () =>
            {
                if (pinned.Count > 0)
                {
                    pinnedAndAutoSort.UnpinItem(pinned.Pop());
                }
            });
        }
        public TestCaseTabControl()
        {
            List <KeyValuePair <string, TestEnum> > items = new List <KeyValuePair <string, TestEnum> >();

            foreach (var val in (TestEnum[])Enum.GetValues(typeof(TestEnum)))
            {
                items.Add(new KeyValuePair <string, TestEnum>(val.GetDescription(), val));
            }

            StyledTabControl simpleTabcontrol = new StyledTabControl
            {
                Position = new Vector2(200, 50),
                Size     = new Vector2(200, 30),
            };

            items.AsEnumerable().ForEach(item => simpleTabcontrol.AddItem(item.Value));

            StyledTabControl pinnedAndAutoSort = new StyledTabControl
            {
                Position = new Vector2(200, 150),
                Size     = new Vector2(200, 30),
                AutoSort = true
            };

            items.GetRange(0, 7).AsEnumerable().ForEach(item => pinnedAndAutoSort.AddItem(item.Value));
            pinnedAndAutoSort.PinItem(TestEnum.Test5);

            StyledTabControl        switchingTabControl;
            PlatformActionContainer platformActionContainer = new PlatformActionContainer
            {
                Child = switchingTabControl = new StyledTabControl
                {
                    Position = new Vector2(200, 250),
                    Size     = new Vector2(200, 30),
                }
            };

            items.AsEnumerable().ForEach(item => switchingTabControl.AddItem(item.Value));

            StyledTabControl removeAllTabControl = new StyledTabControl
            {
                Position = new Vector2(200, 350),
                Size     = new Vector2(200, 30)
            };

            var withoutDropdownTabControl = new StyledTabControlWithoutDropdown
            {
                Position = new Vector2(200, 450),
                Size     = new Vector2(200, 30)
            };

            items.AsEnumerable().ForEach(item => withoutDropdownTabControl.AddItem(item.Value));

            Add(simpleTabcontrol);
            Add(pinnedAndAutoSort);
            Add(platformActionContainer);
            Add(removeAllTabControl);
            Add(withoutDropdownTabControl);

            var nextTest = new Func <TestEnum>(() => items.AsEnumerable()
                                               .Select(item => item.Value)
                                               .FirstOrDefault(test => !pinnedAndAutoSort.Items.Contains(test)));

            Stack <TestEnum> pinned = new Stack <TestEnum>();

            AddStep("AddItem", () =>
            {
                var item = nextTest.Invoke();
                if (!pinnedAndAutoSort.Items.Contains(item))
                {
                    pinnedAndAutoSort.AddItem(item);
                }
            });

            AddStep("RemoveItem", () =>
            {
                if (pinnedAndAutoSort.Items.Any())
                {
                    pinnedAndAutoSort.RemoveItem(pinnedAndAutoSort.Items.First());
                }
            });

            AddStep("PinItem", () =>
            {
                var item = nextTest.Invoke();

                if (!pinnedAndAutoSort.Items.Contains(item))
                {
                    pinned.Push(item);
                    pinnedAndAutoSort.AddItem(item);
                    pinnedAndAutoSort.PinItem(item);
                }
            });

            AddStep("UnpinItem", () =>
            {
                if (pinned.Count > 0)
                {
                    pinnedAndAutoSort.UnpinItem(pinned.Pop());
                }
            });

            AddStep("Set first tab", () => switchingTabControl.Current.Value = switchingTabControl.VisibleItems.First());
            AddStep("Switch forward", () => platformActionContainer.TriggerPressed(new PlatformAction(PlatformActionType.DocumentNext)));
            AddAssert("Ensure second tab", () => switchingTabControl.Current.Value == switchingTabControl.VisibleItems.ElementAt(1));

            AddStep("Switch backward", () => platformActionContainer.TriggerPressed(new PlatformAction(PlatformActionType.DocumentPrevious)));
            AddAssert("Ensure first Tab", () => switchingTabControl.Current.Value == switchingTabControl.VisibleItems.First());

            AddStep("Switch backward", () => platformActionContainer.TriggerPressed(new PlatformAction(PlatformActionType.DocumentPrevious)));
            AddAssert("Ensure last tab", () => switchingTabControl.Current.Value == switchingTabControl.VisibleItems.Last());

            AddStep("Switch forward", () => platformActionContainer.TriggerPressed(new PlatformAction(PlatformActionType.DocumentNext)));
            AddAssert("Ensure first tab", () => switchingTabControl.Current.Value == switchingTabControl.VisibleItems.First());

            AddStep("Add all items", () => items.AsEnumerable().ForEach(item => removeAllTabControl.AddItem(item.Value)));
            AddAssert("Ensure all items", () => removeAllTabControl.Items.Count() == items.Count);

            AddStep("Remove all items", () => removeAllTabControl.Clear());
            AddAssert("Ensure no items", () => !removeAllTabControl.Items.Any());

            AddAssert("Ensure any items", () => withoutDropdownTabControl.Items.Any());
            AddStep("Remove all items", () => withoutDropdownTabControl.Clear());
            AddAssert("Ensure no items", () => !withoutDropdownTabControl.Items.Any());
        }