public void Clearing_Content_Should_Remove_From_LogicalChildren()
        {
            var target = new ContentPresenter();
            var child = new Control();

            target.Content = child;
            target.ApplyTemplate();
            target.Content = null;
            target.ApplyTemplate();

            Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
        }
        public void Clearing_Content_Clear_Childs_Parent()
        {
            var target = new ContentPresenter();
            var child = new Control();

            target.Content = child;
            target.ApplyTemplate();
            target.Content = null;
            target.ApplyTemplate();

            Assert.Null(child.Parent);
            Assert.Null(child.GetLogicalParent());
        }
        public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ContentPresenter();
            var child = new Control();
            var called = false;

            target.Content = child;
            target.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;

            target.Content = null;
            target.ApplyTemplate();

            Assert.True(called);
        }
        public void Setting_Content_Should_Make_Control_Appear_In_LogicalChildren()
        {
            var target = new ContentPresenter();
            var child = new Control();

            target.Content = child;
            target.ApplyTemplate();

            Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
        }
        public void Adding_To_Logical_Tree_Should_Reevaluate_DataTemplates()
        {
            var target = new ContentPresenter
            {
                Content = "Foo",
            };

            target.ApplyTemplate();
            Assert.IsType<TextBlock>(target.Child);

            var root = new TestRoot
            {
                DataTemplates = new DataTemplates
                {
                    new FuncDataTemplate<string>(x => new Decorator()),
                },
            };

            root.Child = target;
            target.ApplyTemplate();
            Assert.IsType<Decorator>(target.Child);
        }
        public void Setting_Content_To_String_Should_Create_TextBlock()
        {
            var target = new ContentPresenter();

            target.Content = "Foo";

            // Child should not update until ApplyTemplate called.
            Assert.Null(target.Child);

            target.ApplyTemplate();

            Assert.IsType<TextBlock>(target.Child);
            Assert.Equal("Foo", ((TextBlock)target.Child).Text);
        }
        public void Setting_Content_To_Control_Should_Set_Child()
        {
            var target = new ContentPresenter();
            var child = new Border();

            target.Content = child;

            // Child should not update until ApplyTemplate called.
            Assert.Null(target.Child);

            target.ApplyTemplate();

            Assert.Equal(child, target.Child);
        }