示例#1
0
        public void GetSelfAndChildren_WhenNoChildren_ReturnsOnlySelf()
        {
            var s = new Child();

            CollectionAssert.AreEqual(
                new[] { s },
                ScreenTreeHelper.GetChildrenOf(s, includeSelf: true).ToArray()
                );
        }
示例#2
0
        public void GetSelfAndChildren_WithChildren_ReturnsSelfAndChildren()
        {
            var p = new Parent();
            var c = new Child();

            p.Children.Attach(c);

            var result = ScreenTreeHelper.GetChildrenOf(p, includeSelf: true).ToArray();

            CollectionAssert.Contains(result, p);
            CollectionAssert.Contains(result, c);
        }
示例#3
0
        public void GetSelfAndChildren_WithGrandchildren_ReturnsSelfAndChildrenOnly()
        {
            var p     = new Parent();
            var child = new Parent();
            var grand = new Child();

            p.Children.Attach(child);
            child.Children.Attach(grand);

            var result = ScreenTreeHelper.GetChildrenOf(p, includeSelf: true).ToArray();

            CollectionAssert.Contains(result, p);
            CollectionAssert.Contains(result, child);
            CollectionAssert.DoesNotContain(result, grand);
        }
示例#4
0
        public void GetDescendantsOfWithoutSelf_ReturnsChildrenAndGrandchildren()
        {
            var p     = new Parent();
            var child = new Parent();
            var grand = new Child();

            p.Children.Attach(child);
            child.Children.Attach(grand);

            var result = ScreenTreeHelper.GetDescendantsOf(p, includeSelf: false);

            CollectionAssert.AreEqual(
                new IScreenBase[] { child, grand },
                result.ToArray()
                );
        }
示例#5
0
        public Window GetAssociatedWindow(IScreenBase screen)
        {
            if (screen == null)
            {
                return(null);
            }

            WindowLifecycle lf = ScreenTreeHelper
                                 .GetAncestorsOf(screen, includeSelf: true)
                                 .SelectMany(s => s.Children.OfType <WindowLifecycle>())
                                 .FirstOrDefault();

            if (lf != null)
            {
                return(lf.Window);
            }

            throw new ArgumentException(ExceptionTexts.NoAssociatedWindow);
        }