diff --git a/Perspex.Controls.UnitTests/ItemsControlTests.cs b/Perspex.Controls.UnitTests/ItemsControlTests.cs index 494d226ee8..1a0f8e838d 100644 --- a/Perspex.Controls.UnitTests/ItemsControlTests.cs +++ b/Perspex.Controls.UnitTests/ItemsControlTests.cs @@ -25,68 +25,6 @@ namespace Perspex.Controls.UnitTests [TestClass] public class ItemsControlTests { - [TestMethod] - public void Template_Should_Be_Instantiated() - { - using (var ctx = this.RegisterServices()) - { - var target = new ItemsControl(); - target.Items = new[] { "Foo" }; - target.Template = this.GetTemplate(); - - target.Measure(new Size(100, 100)); - - var child = ((IVisual)target).VisualChildren.Single(); - Assert.IsInstanceOfType(child, typeof(Border)); - child = child.VisualChildren.Single(); - Assert.IsInstanceOfType(child, typeof(ItemsPresenter)); - child = child.VisualChildren.Single(); - Assert.IsInstanceOfType(child, typeof(StackPanel)); - child = child.VisualChildren.Single(); - Assert.IsInstanceOfType(child, typeof(TextBlock)); - } - } - - [TestMethod] - public void Templated_Children_Should_Be_Styled() - { - using (var ctx = this.RegisterServices()) - { - var root = new TestRoot(); - var target = new ItemsControl(); - var styler = new Mock(); - - Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); - target.Items = new[] { "Foo" }; - target.Template = this.GetTemplate(); - root.Content = target; - - target.ApplyTemplate(); - - styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); - styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); - styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); - styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); - styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); - } - } - - [TestMethod] - public void ItemsPresenter_And_Panel_Should_Have_TemplatedParent_Set() - { - var target = new ItemsControl(); - - target.Template = this.GetTemplate(); - target.Items = new[] { "Foo" }; - target.ApplyTemplate(); - - var presenter = target.GetTemplateControls().OfType().Single(); - var panel = target.GetTemplateControls().OfType().Single(); - - Assert.AreEqual(target, presenter.TemplatedParent); - Assert.AreEqual(target, panel.TemplatedParent); - } - [TestMethod] public void Item_Should_Have_TemplatedParent_Set_To_Null() { @@ -103,7 +41,7 @@ namespace Perspex.Controls.UnitTests } [TestMethod] - public void Control_Item_Should_Set_Control_Parent() + public void Control_Item_Should_Have_Parent_Set() { var target = new ItemsControl(); var child = new Control(); @@ -132,7 +70,7 @@ namespace Perspex.Controls.UnitTests } [TestMethod] - public void Control_Item_Should_Make_Control_Appear_In_LogicalChildren() + public void Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren() { var target = new ItemsControl(); var child = new Control(); @@ -145,7 +83,7 @@ namespace Perspex.Controls.UnitTests } [TestMethod] - public void String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren() + public void Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren() { var target = new ItemsControl(); var child = new Control(); diff --git a/Perspex.Controls.UnitTests/TemplatedControlTests.cs b/Perspex.Controls.UnitTests/TemplatedControlTests.cs index 510b99cf99..b6ce272081 100644 --- a/Perspex.Controls.UnitTests/TemplatedControlTests.cs +++ b/Perspex.Controls.UnitTests/TemplatedControlTests.cs @@ -4,6 +4,7 @@ // // ----------------------------------------------------------------------- +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Perspex.Controls.UnitTests { using System; @@ -12,9 +13,12 @@ namespace Perspex.Controls.UnitTests using System.Text; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; using Perspex.Controls; using Perspex.Controls.Primitives; + using Perspex.Styling; using Perspex.VisualTree; + using Splat; [TestClass] public class TemplatedControlTests @@ -115,6 +119,100 @@ namespace Perspex.Controls.UnitTests Assert.IsTrue(target.OnTemplateAppliedCalled); } + + [TestMethod] + public void Template_Should_Be_Instantated() + { + var target = new TestTemplatedControl + { + Template = new ControlTemplate(_ => + { + return new StackPanel + { + Children = new Controls + { + new TextBlock + { + } + } + }; + }), + }; + + target.ApplyTemplate(); + + var child = target.GetVisualChildren().Single(); + Assert.IsInstanceOfType(child, typeof(StackPanel)); + child = child.VisualChildren.Single(); + Assert.IsInstanceOfType(child, typeof(TextBlock)); + } + + [TestMethod] + public void Templated_Children_Should_Be_Styled() + { + using (Locator.Current.WithResolver()) + { + var styler = new Mock(); + Locator.CurrentMutable.Register(() => styler.Object, typeof(IStyler)); + + TestTemplatedControl target; + + var root = new TestRoot + { + Content = (target = new TestTemplatedControl + { + Template = new ControlTemplate(_ => + { + return new StackPanel + { + Children = new Controls + { + new TextBlock + { + } + } + }; + }), + }) + }; + + + target.ApplyTemplate(); + + styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); + styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); + styler.Verify(x => x.ApplyStyles(It.IsAny()), Times.Once()); + } + } + + [TestMethod] + public void Templated_Children_Should_Have_TemplatedParent_Set() + { + var target = new TestTemplatedControl + { + Template = new ControlTemplate(_ => + { + return new StackPanel + { + Children = new Controls + { + new TextBlock + { + } + } + }; + }), + }; + + target.ApplyTemplate(); + + var panel = target.GetTemplateControls().OfType().Single(); + var textBlock = target.GetTemplateControls().OfType().Single(); + + Assert.AreEqual(target, panel.TemplatedParent); + Assert.AreEqual(target, textBlock.TemplatedParent); + } + } }