Example #1
0
        public void AddToSecondLayoutRemovesFromOriginal()
        {
            var child   = new BoxView();
            var layout1 = new NaiveLayout();
            var layout2 = new NaiveLayout();

            layout1.Children.Add(child);
            layout2.Children.Add(child);

            Assert.False(layout1.Children.Contains(child));
        }
Example #2
0
        public void TestDoubleSetParent()
        {
            var view   = new ParentSignalView();
            var parent = new NaiveLayout {
                Children = { view }
            };

            view.ParentSet = false;
            view.Parent    = parent;

            Assert.False(view.ParentSet, "OnParentSet should not be called in the event the parent is already properly set");
        }
Example #3
0
        public void TestBindingContextChaining()
        {
            View child;
            var  group = new NaiveLayout {
                Children = { (child = new View()) }
            };

            var context = new object();

            group.BindingContext = context;

            Assert.AreEqual(context, child.BindingContext);
        }
Example #4
0
        public void TestAdd()
        {
            var view   = new NaiveLayout();
            var child1 = new View();

            bool added = false;

            view.ChildAdded += (sender, args) => added = true;

            view.Children.Add(child1);

            Assert.True(added);
            Assert.AreEqual(child1, ((IElementController)view).LogicalChildren [0]);
        }
Example #5
0
        public void TestAncestorAdded()
        {
            var child = new NaiveLayout();
            var view  = new NaiveLayout {
                Children = { child }
            };

            bool added = false;

            view.DescendantAdded += (sender, arg) => added = true;

            child.Children.Add(new View());

            Assert.True(added, "AncestorAdded must fire when adding a child to an ancestor of a view.");
        }
Example #6
0
        public void TestChildren()
        {
            View view1, view2;
            var  group = new NaiveLayout {
                Children =
                {
                    (view1 = new View()),
                    (view2 = new View())
                }
            };

            Assert.AreEqual(2, group.Children.Count);
            Assert.IsTrue(group.Children.Contains(view1));
            Assert.IsTrue(group.Children.Contains(view2));
            Assert.AreEqual(view1, group.Children[0]);
        }
Example #7
0
        public void TestInitializerSyntax()
        {
            View view1, view2;
            var  group = new NaiveLayout {
                Children =
                {
                    (view1 = new View()),
                    (view2 = new View())
                }
            };

            Assert.AreEqual(2, ((IElementController)group).LogicalChildren.Count);
            Assert.IsTrue(((IElementController)group).LogicalChildren.Contains(view1));
            Assert.IsTrue(((IElementController)group).LogicalChildren.Contains(view2));
            Assert.AreEqual(view1, ((IElementController)group).LogicalChildren[0]);
        }
Example #8
0
        public void TestRemove()
        {
            var view   = new NaiveLayout();
            var child1 = new View();

            view.Children.Add(child1);

            bool removed = false;

            view.ChildRemoved += (sender, args) => removed = true;

            view.Children.Remove(child1);

            Assert.True(removed);
            Assert.False(((IElementController)view).LogicalChildren.Any());
        }
        public void TestDoubleAdd()
        {
            var view   = new NaiveLayout();
            var child1 = new View();

            view.Children.Add(child1);

            bool added = false;

            view.ChildAdded += (sender, args) => added = true;

            view.Children.Add(child1);

            Assert.False(added);
            Assert.AreEqual(child1, view.LogicalChildren [0]);
        }
Example #10
0
        public void TestPackWithoutChild()
        {
            Frame frame = new Frame();

            var parent = new NaiveLayout();

            bool thrown = false;

            try {
                parent.Children.Add(frame);
            } catch {
                thrown = true;
            }

            Assert.False(thrown);
        }
Example #11
0
        public void BindingsApplyAfterViewAddedToParentWithContextSet()
        {
            var parent = new NaiveLayout();

            parent.BindingContext = new MockViewModel {
                Text = "test"
            };

            var child = new Entry();

            child.SetBinding(Entry.TextProperty, new Binding("Text"));

            parent.Children.Add(child);

            Assert.That(child.BindingContext, Is.SameAs(parent.BindingContext));
            Assert.That(child.Text, Is.EqualTo("test"));
        }
Example #12
0
        public void TestAncestorRemoved()
        {
            var ancestor = new View();
            var child    = new NaiveLayout {
                Children = { ancestor }
            };
            var view = new NaiveLayout {
                Children = { child }
            };

            bool removed = false;

            view.DescendantRemoved += (sender, arg) => removed = true;

            child.Children.Remove(ancestor);
            Assert.True(removed, "AncestorRemoved must fire when removing a child from an ancestor of a view.");
        }
Example #13
0
        public void TestRaiseUnownedChild()
        {
            var view = new NaiveLayout();

            var child1 = new View();
            var child2 = new View();
            var child3 = new View();

            view.Children.Add(child1);
            view.Children.Add(child3);

            bool reordered = false;

            view.ChildrenReordered += (sender, args) => reordered = true;

            view.RaiseChild(child2);

            Assert.False(reordered);
        }
Example #14
0
        public void TestDefaultLayout()
        {
            View view;
            var  group = new NaiveLayout {
                IsPlatformEnabled = true,
                Children          =
                {
                    (view                 = new View {
                        WidthRequest      =     50,
                        HeightRequest     = 20,
                        IsPlatformEnabled = true,
                    })
                }
            };

            group.Layout(new Rectangle(0, 0, 400, 400));

            Assert.AreEqual(new Rectangle(0, 0, 50, 20), view.Bounds);
        }
Example #15
0
        public void ReorderChildrenDoesNotRaiseChildAddedOrRemoved()
        {
            var child1 = new BoxView();
            var child2 = new BoxView();
            var layout = new NaiveLayout {
                Children = { child1, child2 }
            };

            var added   = false;
            var removed = false;

            layout.ChildAdded   += (sender, args) => added = true;
            layout.ChildRemoved += (sender, args) => removed = true;

            layout.RaiseChild(child1);

            Assert.False(added);
            Assert.False(removed);
        }
Example #16
0
        public void TestGenericEnumerator()
        {
            var view = new NaiveLayout();

            var children = new[] {
                new View(),
                new View(),
                new View()
            };

            foreach (var child in children)
            {
                view.Children.Add(child);
            }

            int i = 0;

            foreach (var child in ((IElementController)view).LogicalChildren)
            {
                Assert.AreEqual(children[i], child);
                i++;
            }
        }
        public void TestRaiseChild()
        {
            var view = new NaiveLayout();

            var child1 = new View();
            var child2 = new View();
            var child3 = new View();

            view.Children.Add(child1);
            view.Children.Add(child2);
            view.Children.Add(child3);

            bool reordered = false;

            view.ChildrenReordered += (sender, args) => reordered = true;

            view.RaiseChild(child1);

            Assert.AreEqual(child1, view.LogicalChildren [2]);
            Assert.True(reordered);

            view.RaiseChild(child2);
            Assert.AreEqual(child2, view.LogicalChildren [2]);
        }
Example #18
0
        public void TestEnumerator()
        {
            var view = new NaiveLayout();

            var children = new [] {
                new View(),
                new View(),
                new View()
            };

            foreach (var child in children)
            {
                view.Children.Add(child);
            }

            int i          = 0;
            var enumerator = (((IElementController)view).LogicalChildren as IEnumerable).GetEnumerator();

            while (enumerator.MoveNext())
            {
                Assert.AreEqual(children [i], enumerator.Current as View);
                i++;
            }
        }
Example #19
0
        public void TestLowerChild()
        {
            var view = new NaiveLayout();

            var child1 = new View();
            var child2 = new View();
            var child3 = new View();

            view.Children.Add(child1);
            view.Children.Add(child2);
            view.Children.Add(child3);

            bool reordered = false;

            view.ChildrenReordered += (sender, args) => reordered = true;

            view.LowerChild(child3);

            Assert.AreEqual(child3, ((IElementController)view).LogicalChildren [0]);
            Assert.True(reordered);

            view.LowerChild(child2);
            Assert.AreEqual(child2, ((IElementController)view).LogicalChildren [0]);
        }
Example #20
0
        public void ThrowsInvalidOperationOnSelfAdd()
        {
            var group = new NaiveLayout();

            Assert.Throws <InvalidOperationException> (() => group.Children.Add(group));
        }