Browse Source

Started adding TemplateExtensions tests.

pull/39/head
Steven Kirk 11 years ago
parent
commit
7aa634cbe7
  1. 3
      Perspex.Controls/Properties/AssemblyInfo.cs
  2. 1
      Tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj
  3. 45
      Tests/Perspex.Controls.UnitTests/Templates/TemplateExtensionsTests.cs
  4. 5
      Tests/Perspex.Controls.UnitTests/TestTemplatedControl.cs

3
Perspex.Controls/Properties/AssemblyInfo.cs

@ -6,6 +6,7 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@ -32,3 +33,5 @@ using System.Resources;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: InternalsVisibleTo("Perspex.Controls.UnitTests")]

1
Tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

@ -93,6 +93,7 @@
<Compile Include="ControlTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TemplatedControlTests.cs" />
<Compile Include="Templates\TemplateExtensionsTests.cs" />
<Compile Include="TestTemplatedControl.cs" />
<Compile Include="TestRoot.cs" />
</ItemGroup>

45
Tests/Perspex.Controls.UnitTests/Templates/TemplateExtensionsTests.cs

@ -0,0 +1,45 @@
// -----------------------------------------------------------------------
// <copyright file="TemplateExtensionsTests.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls.Templates.UnitTests
{
using System.Linq;
using Perspex.Controls;
using Perspex.Controls.Templates;
using Perspex.Controls.UnitTests;
using Xunit;
public class TemplateExtensionsTests
{
/// <summary>
/// Control templates can themselves contain templated controls. Make sure that
/// GetTemplateChildren returns only controls that have a TemplatedParent of the
/// control that is being searched.
/// </summary>
[Fact]
public void GetTemplateChildren_Should_Not_Return_Nested_Template_Controls()
{
var target = new TestTemplatedControl();
var border1 = new Border { Id = "border1", TemplatedParent = target };
var inner = new TestTemplatedControl { Id = "inner", TemplatedParent = target };
var border2 = new Border { Id = "border2", TemplatedParent = inner };
var border3 = new Border { Id = "border3", TemplatedParent = inner };
var border4 = new Border { Id = "border4", TemplatedParent = target };
var border5 = new Border { Id = "border5", TemplatedParent = null };
target.AddVisualChild(border1);
border1.Content = inner;
inner.AddVisualChild(border2);
inner.AddVisualChild(border3);
border3.Content = border4;
border4.Content = border5;
var result = target.GetTemplateChildren().Select(x => x.Id).ToArray();
Assert.Equal(new[] { "border1", "inner", "border4" }, result);
}
}
}

5
Tests/Perspex.Controls.UnitTests/TestTemplatedControl.cs

@ -12,6 +12,11 @@ namespace Perspex.Controls.UnitTests
{
public bool OnTemplateAppliedCalled { get; private set; }
public new void AddVisualChild(Visual visual)
{
base.AddVisualChild(visual);
}
protected override void OnTemplateApplied()
{
this.OnTemplateAppliedCalled = true;

Loading…
Cancel
Save