Exemplo n.º 1
0
        public void Added_Child_Should_Have_VisualParent_Set()
        {
            var target = new TestVisual();
            var child  = new Visual();

            target.AddChild(child);

            Assert.Equal(target, child.GetVisualParent());
        }
Exemplo n.º 2
0
        public void Removed_Child_Should_Have_VisualParent_Cleared()
        {
            var target = new TestVisual();
            var child  = new Visual();

            target.AddChild(child);
            target.RemoveChild(child);

            Assert.Null(child.GetVisualParent());
        }
Exemplo n.º 3
0
        public void Adding_Already_Parented_Control_Should_Throw()
        {
            var root1 = new TestRoot();
            var root2 = new TestRoot();
            var child = new TestVisual();

            root1.AddChild(child);

            Assert.Throws <InvalidOperationException>(() => root2.AddChild(child));
            Assert.Equal(0, root2.GetVisualChildren().Count());
        }
Exemplo n.º 4
0
        public void Clearing_Children_Should_Clear_VisualParent()
        {
            var children = new[] { new Visual(), new Visual() };
            var target   = new TestVisual();

            target.AddChildren(children);
            target.ClearChildren();

            var result = children.Select(x => x.GetVisualParent()).ToList();

            Assert.Equal(new Visual[] { null, null }, result);
        }
Exemplo n.º 5
0
        public void Added_Child_Should_Notify_VisualParent_Changed()
        {
            var target  = new TestVisual();
            var child   = new TestVisual();
            var parents = new List <IVisual>();

            child.GetObservable(Visual.VisualParentProperty).Subscribe(x => parents.Add(x));
            target.AddChild(child);
            target.RemoveChild(child);

            Assert.Equal(new IVisual[] { null, target, null }, parents);
        }
Exemplo n.º 6
0
        public void Removing_Children_Should_Fire_OnDetachedFromVisualTree()
        {
            var child2 = new TestVisual();
            var child1 = new TestVisual {
                Child = child2
            };
            var root    = new TestRoot();
            var called1 = false;
            var called2 = false;

            root.Child = child1;
            child1.DetachedFromVisualTree += (s, e) => called1 = true;
            child2.DetachedFromVisualTree += (s, e) => called2 = true;
            root.Child = null;

            Assert.True(called1);
            Assert.True(called2);
        }
Exemplo n.º 7
0
        public void Adding_Children_Should_Fire_OnAttachedToVisualTree()
        {
            var child2 = new TestVisual();
            var child1 = new TestVisual {
                Child = child2
            };
            var root    = new TestRoot();
            var called1 = false;
            var called2 = false;

            child1.AttachedToVisualTree += (s, e) => called1 = true;
            child2.AttachedToVisualTree += (s, e) => called2 = true;

            root.Child = child1;

            Assert.True(called1);
            Assert.True(called2);
        }