From 19459f9c5bd76ffc321d6aba30b4f3b97d32b6b0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 14 Sep 2014 02:41:49 +0200 Subject: [PATCH] Added some more tests. Still don't show up the bug I'm looking for... --- .../Controls/ContentControlTests.cs | 32 ++++++++++++++++--- .../Styling/SelectorTests_Template.cs | 3 +- Perspex/Controls/ContentPresenter.cs | 24 ++++---------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Perspex.UnitTests/Controls/ContentControlTests.cs b/Perspex.UnitTests/Controls/ContentControlTests.cs index 985757d189..1a291f00a1 100644 --- a/Perspex.UnitTests/Controls/ContentControlTests.cs +++ b/Perspex.UnitTests/Controls/ContentControlTests.cs @@ -106,12 +106,36 @@ namespace Perspex.UnitTests.Controls Assert.IsFalse(((ILogical)target).LogicalChildren.Any()); } + [TestMethod] + public void ContentPresenter_Should_Have_TemplatedParent_Set() + { + var target = new ContentControl(); + var child = new Border(); + + target.Template = this.GetTemplate(); + target.Content = child; + this.ApplyTemplate(target); + + var contentPresenter = (ContentPresenter)((IVisual)child).VisualParent; + Assert.AreEqual(target, contentPresenter.TemplatedParent); + } + + [TestMethod] + public void Content_Should_Have_TemplatedParent_Set_To_Null() + { + var target = new ContentControl(); + var child = new Border(); + + target.Template = this.GetTemplate(); + target.Content = child; + this.ApplyTemplate(target); + + Assert.IsNull(child.TemplatedParent); + } + private void ApplyTemplate(IVisual visual) { - foreach (IVisual child in visual.VisualChildren) - { - this.ApplyTemplate(child); - } + var c = visual.GetVisualDescendents().ToList(); } private ControlTemplate GetTemplate() diff --git a/Perspex.UnitTests/Styling/SelectorTests_Template.cs b/Perspex.UnitTests/Styling/SelectorTests_Template.cs index e123fa14d0..74fd594535 100644 --- a/Perspex.UnitTests/Styling/SelectorTests_Template.cs +++ b/Perspex.UnitTests/Styling/SelectorTests_Template.cs @@ -4,6 +4,7 @@ // // ----------------------------------------------------------------------- +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Perspex.UnitTests.Styling { using System.Linq; @@ -80,7 +81,7 @@ namespace Perspex.UnitTests.Styling templatedControl.Setup(x => x.Classes).Returns(new Classes("bar")); var border = (Border)templatedControl.Object.VisualChildren.Single(); - var selector = new Selector().OfType().Class("foo").Template().OfType(); + var selector = new Selector().OfType(templatedControl.Object.GetType()).Class("foo").Template().OfType(); Assert.IsFalse(ActivatorValue(selector, border)); } diff --git a/Perspex/Controls/ContentPresenter.cs b/Perspex/Controls/ContentPresenter.cs index 00158efbab..54d12fb455 100644 --- a/Perspex/Controls/ContentPresenter.cs +++ b/Perspex/Controls/ContentPresenter.cs @@ -25,19 +25,6 @@ namespace Perspex.Controls public ContentPresenter() { this.GetObservableWithHistory(ContentProperty).Subscribe(this.ContentChanged); - //{ - // if (x.Item1 is Control) - // { - // ((IVisual)x.Item1).VisualParent = null; - // ((ILogical)x.Item1).LogicalParent = null; - // } - - // if (x.Item2 is Control) - // { - // ((IVisual)x.Item2).VisualParent = this; - // ((ILogical)x.Item2).LogicalParent = this; - // } - //}); } public object Content @@ -176,15 +163,16 @@ namespace Perspex.Controls if (content.Item2 != null) { - IVisual visual = content.Item2 as IVisual; + Control control = content.Item2 as Control; - if (visual == null) + if (control == null) { - visual = this.GetDataTemplate(content.Item2).Build(content.Item2); + control = this.GetDataTemplate(content.Item2).Build(content.Item2); } - visual.VisualParent = this; - this.visualChild = visual; + control.TemplatedParent = null; + ((IVisual)control).VisualParent = this; + this.visualChild = control; ILogical logical = content.Item2 as ILogical;