Browse Source

Moved some TemplatedControl test to right place.

pull/39/head
Steven Kirk 12 years ago
parent
commit
a54f962df2
  1. 68
      Perspex.Controls.UnitTests/ItemsControlTests.cs
  2. 98
      Perspex.Controls.UnitTests/TemplatedControlTests.cs

68
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<IStyler>();
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<ItemsControl>()), Times.Once());
styler.Verify(x => x.ApplyStyles(It.IsAny<Border>()), Times.Once());
styler.Verify(x => x.ApplyStyles(It.IsAny<ItemsPresenter>()), Times.Once());
styler.Verify(x => x.ApplyStyles(It.IsAny<StackPanel>()), Times.Once());
styler.Verify(x => x.ApplyStyles(It.IsAny<TextBlock>()), 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<ItemsPresenter>().Single();
var panel = target.GetTemplateControls().OfType<StackPanel>().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();

98
Perspex.Controls.UnitTests/TemplatedControlTests.cs

@ -4,6 +4,7 @@
// </copyright>
// -----------------------------------------------------------------------
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<IStyler>();
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<TestTemplatedControl>()), Times.Once());
styler.Verify(x => x.ApplyStyles(It.IsAny<StackPanel>()), Times.Once());
styler.Verify(x => x.ApplyStyles(It.IsAny<TextBlock>()), 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<StackPanel>().Single();
var textBlock = target.GetTemplateControls().OfType<TextBlock>().Single();
Assert.AreEqual(target, panel.TemplatedParent);
Assert.AreEqual(target, textBlock.TemplatedParent);
}
}
}

Loading…
Cancel
Save