10 changed files with 426 additions and 7 deletions
@ -0,0 +1,102 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{76716382-3159-460E-BDA6-C5715CF606D7}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.SceneGraph.UnitTests</RootNamespace> |
|||
<AssemblyName>Perspex.SceneGraph.UnitTests</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> |
|||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> |
|||
<IsCodedUITest>False</IsCodedUITest> |
|||
<TestProjectType>UnitTest</TestProjectType> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Splat, Version=1.3.3.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<SpecificVersion>False</SpecificVersion> |
|||
<HintPath>..\packages\Splat.1.3.3\lib\Net45\Splat.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
|||
</ItemGroup> |
|||
</When> |
|||
<Otherwise> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> |
|||
</ItemGroup> |
|||
</Otherwise> |
|||
</Choose> |
|||
<ItemGroup> |
|||
<Compile Include="TestRoot.cs" /> |
|||
<Compile Include="TestVisual.cs" /> |
|||
<Compile Include="VisualTests.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
</ItemGroup> |
|||
</When> |
|||
</Choose> |
|||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.SceneGraph.UnitTests")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.SceneGraph.UnitTests")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("9b18d549-61cc-46b3-a3f2-80a0b68b747f")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,20 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TestVisual.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
namespace Perspex.SceneGraph.UnitTests |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Perspex.Rendering; |
|||
|
|||
public class TestRoot : TestVisual, IRenderRoot |
|||
{ |
|||
public IRenderManager RenderManager |
|||
{ |
|||
get { throw new NotImplementedException(); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TestVisual.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
namespace Perspex.SceneGraph.UnitTests |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Perspex.Rendering; |
|||
|
|||
public class ParamEventArgs<T> : EventArgs |
|||
{ |
|||
public ParamEventArgs(T param) |
|||
{ |
|||
this.Param = param; |
|||
} |
|||
|
|||
public T Param { get; set; } |
|||
} |
|||
|
|||
public class TestVisual : Visual |
|||
{ |
|||
public Visual[] InitialChildren { get; set; } |
|||
|
|||
public event EventHandler<ParamEventArgs<Visual>> VisualParentChangedCalled; |
|||
|
|||
public event EventHandler<ParamEventArgs<IRenderRoot>> AttachedToVisualTreeCalled; |
|||
|
|||
public event EventHandler<ParamEventArgs<IRenderRoot>> DetachedFromVisualTreeCalled; |
|||
|
|||
public void AddChild(Visual v) |
|||
{ |
|||
this.AddVisualChild(v); |
|||
} |
|||
|
|||
public void RemoveChild(Visual v) |
|||
{ |
|||
this.RemoveVisualChild(v); |
|||
} |
|||
|
|||
public void ClearChildren() |
|||
{ |
|||
this.ClearVisualChildren(); |
|||
} |
|||
|
|||
protected override IEnumerable<Visual> CreateVisualChildren() |
|||
{ |
|||
return this.InitialChildren ?? Enumerable.Empty<Visual>(); |
|||
} |
|||
|
|||
protected override void OnVisualParentChanged(Visual oldParent) |
|||
{ |
|||
if (this.VisualParentChangedCalled != null) |
|||
{ |
|||
this.VisualParentChangedCalled(this, new ParamEventArgs<Visual>(oldParent)); |
|||
} |
|||
} |
|||
|
|||
protected override void OnAttachedToVisualTree(IRenderRoot root) |
|||
{ |
|||
if (this.AttachedToVisualTreeCalled != null) |
|||
{ |
|||
this.AttachedToVisualTreeCalled(this, new ParamEventArgs<IRenderRoot>(root)); |
|||
} |
|||
} |
|||
|
|||
protected override void OnDetachedFromVisualTree(IRenderRoot oldRoot) |
|||
{ |
|||
if (this.DetachedFromVisualTreeCalled != null) |
|||
{ |
|||
this.DetachedFromVisualTreeCalled(this, new ParamEventArgs<IRenderRoot>(oldRoot)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,119 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="VisualTests.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
namespace Perspex.SceneGraph.UnitTests |
|||
{ |
|||
using System.Linq; |
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
|
|||
[TestClass] |
|||
public class VisualTests |
|||
{ |
|||
[TestMethod] |
|||
public void Initial_Children_Should_Be_Created() |
|||
{ |
|||
var target = new TestVisual |
|||
{ |
|||
InitialChildren = new[] { new Visual(), new Visual() } |
|||
}; |
|||
|
|||
var result = target.GetVisualChildren().ToList(); |
|||
|
|||
CollectionAssert.AreEqual(target.InitialChildren.ToList(), result); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void Initial_Children_Should_Have_VisualParent_Set() |
|||
{ |
|||
var target = new TestVisual |
|||
{ |
|||
InitialChildren = new[] { new Visual(), new Visual() } |
|||
}; |
|||
|
|||
var result = target.GetVisualChildren().Select(x => x.GetVisualParent()).ToList(); |
|||
|
|||
CollectionAssert.AreEqual(new[] { target, target }, result); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void Added_Child_Should_Have_VisualParent_Set() |
|||
{ |
|||
var target = new TestVisual(); |
|||
var child = new Visual(); |
|||
|
|||
target.AddChild(child); |
|||
|
|||
Assert.AreEqual(target, child.GetVisualParent()); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void Removed_Child_Should_Have_VisualParent_Cleared() |
|||
{ |
|||
var target = new TestVisual(); |
|||
var child = new Visual(); |
|||
|
|||
target.AddChild(child); |
|||
target.RemoveChild(child); |
|||
|
|||
Assert.IsNull(child.GetVisualParent()); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void Clearing_Children_Should_Clear_VisualParent() |
|||
{ |
|||
var target = new TestVisual |
|||
{ |
|||
InitialChildren = new[] { new Visual(), new Visual() } |
|||
}; |
|||
|
|||
target.ClearChildren(); |
|||
|
|||
var result = target.InitialChildren.Select(x => x.GetVisualParent()).ToList(); |
|||
|
|||
CollectionAssert.AreEqual(new Visual[] { null, null }, result); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void ParentChanged_Attached_Methods_Should_Be_Called_In_Right_Order() |
|||
{ |
|||
var target = new TestRoot(); |
|||
var child = new TestVisual(); |
|||
int changed = 0; |
|||
int attched = 0; |
|||
int i = 1; |
|||
|
|||
target.InitialChildren = new[] { child }; |
|||
child.VisualParentChangedCalled += (s, e) => changed = i++; |
|||
child.AttachedToVisualTreeCalled += (s, e) => attched = i++; |
|||
|
|||
target.GetVisualChildren().First(); |
|||
|
|||
Assert.AreEqual(1, changed); |
|||
Assert.AreEqual(2, attched); |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void ParentChanged_Detached_Methods_Should_Be_Called_In_Right_Order() |
|||
{ |
|||
var target = new TestRoot(); |
|||
var child = new TestVisual(); |
|||
int changed = 0; |
|||
int detached = 0; |
|||
int i = 1; |
|||
|
|||
target.InitialChildren = new[] { child }; |
|||
target.GetVisualChildren().First(); |
|||
|
|||
child.VisualParentChangedCalled += (s, e) => changed = i++; |
|||
child.DetachedFromVisualTreeCalled += (s, e) => detached = i++; |
|||
|
|||
target.ClearChildren(); |
|||
|
|||
Assert.AreEqual(1, changed); |
|||
Assert.AreEqual(2, detached); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Splat" version="1.3.3" targetFramework="net45" /> |
|||
</packages> |
|||
Loading…
Reference in new issue