Browse Source

Converted tests to run with xUnit.

pull/39/head
Steven Kirk 12 years ago
parent
commit
1a3a78847b
  1. 18
      Perspex.Base.UnitTests/Perspex.Base.UnitTests.csproj
  2. 190
      Perspex.Base.UnitTests/PerspexObjectTests.cs
  3. 37
      Perspex.Base.UnitTests/PerspexPropertyTests.cs
  4. 69
      Perspex.Base.UnitTests/PriorityValueTEsts.cs
  5. 2
      Perspex.Base.UnitTests/packages.config
  6. 59
      Perspex.Controls.UnitTests/ContentControlTests.cs
  7. 12
      Perspex.Controls.UnitTests/ControlTests.cs
  8. 35
      Perspex.Controls.UnitTests/DecoratorTests.cs
  9. 59
      Perspex.Controls.UnitTests/DropDownTests.cs
  10. 57
      Perspex.Controls.UnitTests/ItemsControlTests.cs
  11. 53
      Perspex.Controls.UnitTests/PanelTests.cs
  12. 18
      Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj
  13. 58
      Perspex.Controls.UnitTests/TemplatedControlTests.cs
  14. 2
      Perspex.Controls.UnitTests/packages.config
  15. 38
      Perspex.Layout.UnitTests/FullLayoutTests.cs
  16. 18
      Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj
  17. 2
      Perspex.Layout.UnitTests/packages.config
  18. 18
      Perspex.SceneGraph.UnitTests/Perspex.SceneGraph.UnitTests.csproj
  19. 35
      Perspex.SceneGraph.UnitTests/VisualTests.cs
  20. 2
      Perspex.SceneGraph.UnitTests/packages.config
  21. 18
      Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj
  22. 41
      Perspex.Styling.UnitTests/SelectorTests_Class.cs
  23. 19
      Perspex.Styling.UnitTests/SelectorTests_Descendent.cs
  24. 27
      Perspex.Styling.UnitTests/SelectorTests_Id.cs
  25. 11
      Perspex.Styling.UnitTests/SelectorTests_Multiple.cs
  26. 27
      Perspex.Styling.UnitTests/SelectorTests_OfType.cs
  27. 23
      Perspex.Styling.UnitTests/SelectorTests_Template.cs
  28. 117
      Perspex.Styling.UnitTests/StyleActivatorTests.cs
  29. 23
      Perspex.Styling.UnitTests/StyleTests.cs
  30. 2
      Perspex.Styling.UnitTests/packages.config
  31. 2
      Perspex.sln
  32. 33
      Windows/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs
  33. 11
      Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs
  34. 18
      Windows/Perspex.Direct2D1.RenderTests/Perspex.Direct2D1.RenderTests.csproj
  35. 5
      Windows/Perspex.Direct2D1.RenderTests/Shapes/EllipseTests.cs
  36. 9
      Windows/Perspex.Direct2D1.RenderTests/Shapes/PathTests.cs
  37. 9
      Windows/Perspex.Direct2D1.RenderTests/Shapes/RectangleTests.cs
  38. 6
      Windows/Perspex.Direct2D1.RenderTests/TestBase.cs
  39. 2
      Windows/Perspex.Direct2D1.RenderTests/packages.config

18
Perspex.Base.UnitTests/Perspex.Base.UnitTests.csproj

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,12 +11,12 @@
<AssemblyName>Perspex.Base.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>
<NuGetPackageImportStamp>d6a0929f</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -56,6 +57,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -63,11 +67,7 @@
<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>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="PerspexPropertyTests.cs" />
@ -106,6 +106,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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">

190
Perspex.Base.UnitTests/PerspexObjectTests.cs

@ -10,13 +10,11 @@ namespace Perspex.Base.UnitTests
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
[TestClass]
public class PerspexObjectTests
{
[TestInitialize]
public void Initialize()
public PerspexObjectTests()
{
// Ensure properties are registered.
PerspexProperty p;
@ -24,49 +22,49 @@ namespace Perspex.Base.UnitTests
p = Class2.BarProperty;
}
[TestMethod]
[Fact]
public void GetProperties_Returns_Registered_Properties()
{
string[] names = PerspexObject.GetProperties(typeof(Class1)).Select(x => x.Name).ToArray();
CollectionAssert.AreEqual(new[] { "Foo", "Baz", "Qux" }, names);
Assert.Equal(new[] { "Foo", "Baz", "Qux" }, names);
}
[TestMethod]
[Fact]
public void GetProperties_Returns_Registered_Properties_For_Base_Types()
{
string[] names = PerspexObject.GetProperties(typeof(Class2)).Select(x => x.Name).ToArray();
CollectionAssert.AreEqual(new[] { "Bar", "Foo", "Baz", "Qux" }, names);
Assert.Equal(new[] { "Bar", "Foo", "Baz", "Qux" }, names);
}
[TestMethod]
[Fact]
public void GetValue_Returns_Default_Value()
{
Class1 target = new Class1();
Assert.AreEqual("foodefault", target.GetValue(Class1.FooProperty));
Assert.Equal("foodefault", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void GetValue_Returns_Overridden_Default_Value()
{
Class2 target = new Class2();
Assert.AreEqual("foooverride", target.GetValue(Class1.FooProperty));
Assert.Equal("foooverride", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void GetValue_Returns_Set_Value()
{
Class1 target = new Class1();
target.SetValue(Class1.FooProperty, "newvalue");
Assert.AreEqual("newvalue", target.GetValue(Class1.FooProperty));
Assert.Equal("newvalue", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void GetValue_Returns_Inherited_Value()
{
Class1 parent = new Class1();
@ -74,10 +72,10 @@ namespace Perspex.Base.UnitTests
parent.SetValue(Class1.BazProperty, "changed");
Assert.AreEqual("changed", child.GetValue(Class1.BazProperty));
Assert.Equal("changed", child.GetValue(Class1.BazProperty));
}
[TestMethod]
[Fact]
public void ClearValue_Clears_Value()
{
Class1 target = new Class1();
@ -85,20 +83,20 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "newvalue");
target.ClearValue(Class1.FooProperty);
Assert.AreEqual("foodefault", target.GetValue(Class1.FooProperty));
Assert.Equal("foodefault", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void SetValue_Sets_Value()
{
Class1 target = new Class1();
target.SetValue(Class1.FooProperty, "newvalue");
Assert.AreEqual("newvalue", target.GetValue(Class1.FooProperty));
Assert.Equal("newvalue", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void SetValue_Raises_PropertyChanged()
{
Class1 target = new Class1();
@ -114,10 +112,10 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "newvalue");
Assert.IsTrue(raised);
Assert.True(raised);
}
[TestMethod]
[Fact]
public void SetValue_Doesnt_Raise_PropertyChanged_If_Value_Not_Changed()
{
Class1 target = new Class1();
@ -132,10 +130,10 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "bar");
Assert.IsFalse(raised);
Assert.False(raised);
}
[TestMethod]
[Fact]
public void SetValue_Doesnt_Raise_PropertyChanged_If_Value_Not_Changed_From_Default()
{
Class1 target = new Class1();
@ -148,52 +146,56 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "foodefault");
Assert.IsFalse(raised);
Assert.False(raised);
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
[Fact]
public void SetValue_Throws_Exception_For_Unregistered_Property()
{
Class1 target = new Class1();
target.SetValue(Class2.BarProperty, "invalid");
Assert.Throws<InvalidOperationException>(() =>
{
target.SetValue(Class2.BarProperty, "invalid");
});
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
[Fact]
public void SetValue_Throws_Exception_For_Invalid_Value_Type()
{
Class1 target = new Class1();
target.SetValue(Class1.FooProperty, 123);
Assert.Throws<InvalidOperationException>(() =>
{
target.SetValue(Class1.FooProperty, 123);
});
}
[TestMethod]
[Fact]
public void SetValue_Causes_Coercion()
{
Class1 target = new Class1();
target.SetValue(Class1.QuxProperty, 5);
Assert.AreEqual(5, target.GetValue(Class1.QuxProperty));
Assert.Equal(5, target.GetValue(Class1.QuxProperty));
target.SetValue(Class1.QuxProperty, -5);
Assert.AreEqual(0, target.GetValue(Class1.QuxProperty));
Assert.Equal(0, target.GetValue(Class1.QuxProperty));
target.SetValue(Class1.QuxProperty, 15);
Assert.AreEqual(10, target.GetValue(Class1.QuxProperty));
Assert.Equal(10, target.GetValue(Class1.QuxProperty));
}
[TestMethod]
[Fact]
public void CoerceValue_Causes_Recoercion()
{
Class1 target = new Class1();
target.SetValue(Class1.QuxProperty, 7);
Assert.AreEqual(7, target.GetValue(Class1.QuxProperty));
Assert.Equal(7, target.GetValue(Class1.QuxProperty));
target.MaxQux = 5;
target.CoerceValue(Class1.QuxProperty);
}
[TestMethod]
[Fact]
public void GetObservable_Returns_Initial_Value()
{
Class1 target = new Class1();
@ -207,10 +209,10 @@ namespace Perspex.Base.UnitTests
}
});
Assert.AreEqual(1, raised);
Assert.Equal(1, raised);
}
[TestMethod]
[Fact]
public void GetObservable_Returns_Property_Change()
{
Class1 target = new Class1();
@ -220,10 +222,10 @@ namespace Perspex.Base.UnitTests
raised = false;
target.SetValue(Class1.FooProperty, "newvalue");
Assert.IsTrue(raised);
Assert.True(raised);
}
[TestMethod]
[Fact]
public void GetObservable_Returns_Property_Change_Only_For_Correct_Property()
{
Class2 target = new Class2();
@ -233,10 +235,10 @@ namespace Perspex.Base.UnitTests
raised = false;
target.SetValue(Class2.BarProperty, "newvalue");
Assert.IsFalse(raised);
Assert.False(raised);
}
[TestMethod]
[Fact]
public void GetObservable_Dispose_Stops_Property_Changes()
{
Class1 target = new Class1();
@ -248,10 +250,10 @@ namespace Perspex.Base.UnitTests
raised = false;
target.SetValue(Class1.FooProperty, "newvalue");
Assert.IsFalse(raised);
Assert.False(raised);
}
[TestMethod]
[Fact]
public void Setting_InheritanceParent_Raises_PropertyChanged_When_Value_Changed_In_Parent()
{
bool raised = false;
@ -268,10 +270,10 @@ namespace Perspex.Base.UnitTests
child.Parent = parent;
Assert.IsTrue(raised);
Assert.True(raised);
}
[TestMethod]
[Fact]
public void Setting_InheritanceParent_Doesnt_Raise_PropertyChanged_When_Local_Value_Set()
{
bool raised = false;
@ -285,10 +287,10 @@ namespace Perspex.Base.UnitTests
child.Parent = parent;
Assert.IsFalse(raised);
Assert.False(raised);
}
[TestMethod]
[Fact]
public void Setting_Value_In_InheritanceParent_Raises_PropertyChanged()
{
bool raised = false;
@ -305,10 +307,10 @@ namespace Perspex.Base.UnitTests
parent.SetValue(Class1.BazProperty, "changed");
Assert.IsTrue(raised);
Assert.True(raised);
}
[TestMethod]
[Fact]
public void Bind_Sets_Current_Value()
{
Class1 target = new Class1();
@ -317,10 +319,10 @@ namespace Perspex.Base.UnitTests
source.SetValue(Class1.FooProperty, "initial");
target.Bind(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
Assert.AreEqual("initial", target.GetValue(Class1.FooProperty));
Assert.Equal("initial", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void Bind_NonGeneric_Sets_Current_Value()
{
Class1 target = new Class1();
@ -329,10 +331,10 @@ namespace Perspex.Base.UnitTests
source.SetValue(Class1.FooProperty, "initial");
target.Bind((PerspexProperty)Class1.FooProperty, source.GetObservable(Class1.FooProperty));
Assert.AreEqual("initial", target.GetValue(Class1.FooProperty));
Assert.Equal("initial", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void Bind_Sets_Subsequent_Value()
{
Class1 target = new Class1();
@ -342,10 +344,10 @@ namespace Perspex.Base.UnitTests
target.Bind(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
source.SetValue(Class1.FooProperty, "subsequent");
Assert.AreEqual("subsequent", target.GetValue(Class1.FooProperty));
Assert.Equal("subsequent", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void Binding_Doesnt_Set_Value_After_Clear()
{
Class1 target = new Class1();
@ -356,10 +358,10 @@ namespace Perspex.Base.UnitTests
target.ClearValue(Class1.FooProperty);
source.SetValue(Class1.FooProperty, "newvalue");
Assert.AreEqual("foodefault", target.GetValue(Class1.FooProperty));
Assert.Equal("foodefault", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void Bind_Doesnt_Set_Value_After_Reset()
{
Class1 target = new Class1();
@ -370,19 +372,21 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "reset");
source.SetValue(Class1.FooProperty, "newvalue");
Assert.AreEqual("reset", target.GetValue(Class1.FooProperty));
Assert.Equal("reset", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
[Fact]
public void Bind_Throws_Exception_For_Invalid_Value_Type()
{
Class1 target = new Class1();
target.Bind((PerspexProperty)Class1.FooProperty, Observable.Return((object)123));
Assert.Throws<InvalidOperationException>(() =>
{
target.Bind((PerspexProperty)Class1.FooProperty, Observable.Return((object)123));
});
}
[TestMethod]
[Fact]
public void BindTwoWay_Gets_Initial_Value_From_Source()
{
Class1 source = new Class1();
@ -391,10 +395,10 @@ namespace Perspex.Base.UnitTests
source.SetValue(Class1.FooProperty, "initial");
target.BindTwoWay(Class1.FooProperty, source, Class1.FooProperty);
Assert.AreEqual("initial", target.GetValue(Class1.FooProperty));
Assert.Equal("initial", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void BindTwoWay_Updates_Values()
{
Class1 source = new Class1();
@ -403,14 +407,14 @@ namespace Perspex.Base.UnitTests
source.SetValue(Class1.FooProperty, "first");
target.BindTwoWay(Class1.FooProperty, source, Class1.FooProperty);
Assert.AreEqual("first", target.GetValue(Class1.FooProperty));
Assert.Equal("first", target.GetValue(Class1.FooProperty));
source.SetValue(Class1.FooProperty, "second");
Assert.AreEqual("second", target.GetValue(Class1.FooProperty));
Assert.Equal("second", target.GetValue(Class1.FooProperty));
target.SetValue(Class1.FooProperty, "third");
Assert.AreEqual("third", source.GetValue(Class1.FooProperty));
Assert.Equal("third", source.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void Setting_UnsetValue_Reverts_To_Default_Value()
{
Class1 target = new Class1();
@ -418,20 +422,20 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "newvalue");
target.SetValue(Class1.FooProperty, PerspexProperty.UnsetValue);
Assert.AreEqual("foodefault", target.GetValue(Class1.FooProperty));
Assert.Equal("foodefault", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void StyleBinding_Overrides_Default_Value()
{
Class1 target = new Class1();
target.Bind(Class1.FooProperty, this.Single("stylevalue"), BindingPriority.Style);
Assert.AreEqual("stylevalue", target.GetValue(Class1.FooProperty));
Assert.Equal("stylevalue", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void StyleBinding_Doesnt_Override_Local_Value()
{
Class1 target = new Class1();
@ -439,39 +443,41 @@ namespace Perspex.Base.UnitTests
target.SetValue(Class1.FooProperty, "newvalue");
target.Bind(Class1.FooProperty, this.Single("stylevalue"), BindingPriority.Style);
Assert.AreEqual("newvalue", target.GetValue(Class1.FooProperty));
Assert.Equal("newvalue", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void this_Operator_Returns_Value_Property()
{
Class1 target = new Class1();
target.SetValue(Class1.FooProperty, "newvalue");
Assert.AreEqual("newvalue", target[Class1.FooProperty]);
Assert.Equal("newvalue", target[Class1.FooProperty]);
}
[TestMethod]
[Fact]
public void this_Operator_Sets_Value_Property()
{
Class1 target = new Class1();
target[Class1.FooProperty] = "newvalue";
Assert.AreEqual("newvalue", target.GetValue(Class1.FooProperty));
Assert.Equal("newvalue", target.GetValue(Class1.FooProperty));
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
[Fact]
public void this_Operator_Doesnt_Accept_Observable()
{
Class1 target = new Class1();
target[Class1.FooProperty] = Observable.Return("newvalue");
Assert.Throws<InvalidOperationException>(() =>
{
target[Class1.FooProperty] = Observable.Return("newvalue");
});
}
[TestMethod]
[Fact]
public void this_Operator_Binds_One_Way()
{
Class1 target1 = new Class1();
@ -482,10 +488,10 @@ namespace Perspex.Base.UnitTests
target2[binding] = target1[!Class1.FooProperty];
target1.SetValue(Class1.FooProperty, "second");
Assert.AreEqual("second", target2.GetValue(Class1.FooProperty));
Assert.Equal("second", target2.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void this_Operator_Binds_Two_Way()
{
Class1 target1 = new Class1();
@ -494,14 +500,14 @@ namespace Perspex.Base.UnitTests
target1.SetValue(Class1.FooProperty, "first");
target2[binding] = target1[!Class1.FooProperty];
Assert.AreEqual("first", target2.GetValue(Class1.FooProperty));
Assert.Equal("first", target2.GetValue(Class1.FooProperty));
target1.SetValue(Class1.FooProperty, "second");
Assert.AreEqual("second", target2.GetValue(Class1.FooProperty));
Assert.Equal("second", target2.GetValue(Class1.FooProperty));
target2.SetValue(Class1.FooProperty, "third");
Assert.AreEqual("third", target1.GetValue(Class1.FooProperty));
Assert.Equal("third", target1.GetValue(Class1.FooProperty));
}
[TestMethod]
[Fact]
public void this_Operator_Binds_One_Time()
{
Class1 target1 = new Class1();
@ -512,7 +518,7 @@ namespace Perspex.Base.UnitTests
target2[binding] = target1[!Class1.FooProperty];
target1.SetValue(Class1.FooProperty, "second");
Assert.AreEqual("first", target2.GetValue(Class1.FooProperty));
Assert.Equal("first", target2.GetValue(Class1.FooProperty));
}
/// <summary>

37
Perspex.Base.UnitTests/PerspexPropertyTests.cs

@ -7,12 +7,11 @@
namespace Perspex.Base.UnitTests
{
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
[TestClass]
public class PerspexPropertyTests
{
[TestMethod]
[Fact]
public void Constructor_Sets_Properties()
{
PerspexProperty<string> target = new PerspexProperty<string>(
@ -23,13 +22,13 @@ namespace Perspex.Base.UnitTests
BindingMode.OneWay,
null);
Assert.AreEqual("test", target.Name);
Assert.AreEqual(typeof(string), target.PropertyType);
Assert.AreEqual(typeof(Class1), target.OwnerType);
Assert.AreEqual(false, target.Inherits);
Assert.Equal("test", target.Name);
Assert.Equal(typeof(string), target.PropertyType);
Assert.Equal(typeof(Class1), target.OwnerType);
Assert.Equal(false, target.Inherits);
}
[TestMethod]
[Fact]
public void GetDefaultValue_Returns_Registered_Value()
{
PerspexProperty<string> target = new PerspexProperty<string>(
@ -40,10 +39,10 @@ namespace Perspex.Base.UnitTests
BindingMode.OneWay,
null);
Assert.AreEqual("Foo", target.GetDefaultValue<Class1>());
Assert.Equal("Foo", target.GetDefaultValue<Class1>());
}
[TestMethod]
[Fact]
public void GetDefaultValue_Returns_Registered_Value_For_Not_Overridden_Class()
{
PerspexProperty<string> target = new PerspexProperty<string>(
@ -54,10 +53,10 @@ namespace Perspex.Base.UnitTests
BindingMode.OneWay,
null);
Assert.AreEqual("Foo", target.GetDefaultValue<Class2>());
Assert.Equal("Foo", target.GetDefaultValue<Class2>());
}
[TestMethod]
[Fact]
public void GetDefaultValue_Returns_Registered_Value_For_Unrelated_Class()
{
PerspexProperty<string> target = new PerspexProperty<string>(
@ -68,10 +67,10 @@ namespace Perspex.Base.UnitTests
BindingMode.OneWay,
null);
Assert.AreEqual("Foo", target.GetDefaultValue<Class2>());
Assert.Equal("Foo", target.GetDefaultValue<Class2>());
}
[TestMethod]
[Fact]
public void GetDefaultValue_Returns_Overridden_Value()
{
PerspexProperty<string> target = new PerspexProperty<string>(
@ -84,10 +83,10 @@ namespace Perspex.Base.UnitTests
target.OverrideDefaultValue(typeof(Class2), "Bar");
Assert.AreEqual("Bar", target.GetDefaultValue<Class2>());
Assert.Equal("Bar", target.GetDefaultValue<Class2>());
}
[TestMethod]
[Fact]
public void Initialized_Observable_Fired()
{
string value = null;
@ -95,10 +94,10 @@ namespace Perspex.Base.UnitTests
Class1.FooProperty.Initialized.Subscribe(x => value = (string)x.NewValue);
var target = new Class1();
Assert.AreEqual("default", value);
Assert.Equal("default", value);
}
[TestMethod]
[Fact]
public void Changed_Observable_Fired()
{
var target = new Class1();
@ -107,7 +106,7 @@ namespace Perspex.Base.UnitTests
Class1.FooProperty.Changed.Subscribe(x => value = (string)x.NewValue);
target.SetValue(Class1.FooProperty, "newvalue");
Assert.AreEqual("newvalue", value);
Assert.Equal("newvalue", value);
}
private class Class1 : PerspexObject

69
Perspex.Base.UnitTests/PriorityValueTEsts.cs

@ -10,42 +10,41 @@ namespace Perspex.Base.UnitTests
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
[TestClass]
public class PriorityValueTests
{
[TestMethod]
[Fact]
public void Initial_Value_Should_Be_UnsetValue()
{
var target = new PriorityValue("Test", typeof(string));
Assert.AreSame(PerspexProperty.UnsetValue, target.Value);
Assert.Same(PerspexProperty.UnsetValue, target.Value);
}
[TestMethod]
[Fact]
public void First_Binding_Sets_Value()
{
var target = new PriorityValue("Test", typeof(string));
target.Add(this.Single("foo"), 0);
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
}
[TestMethod]
[Fact]
public void Changing_Binding_Should_Set_Value()
{
var target = new PriorityValue("Test", typeof(string));
var subject = new BehaviorSubject<string>("foo");
target.Add(subject, 0);
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
subject.OnNext("bar");
Assert.AreEqual("bar", target.Value);
Assert.Equal("bar", target.Value);
}
[TestMethod]
[Fact]
public void Binding_With_Lower_Priority_Has_Precedence()
{
var target = new PriorityValue("Test", typeof(string));
@ -54,10 +53,10 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("bar"), 0);
target.Add(this.Single("baz"), 1);
Assert.AreEqual("bar", target.Value);
Assert.Equal("bar", target.Value);
}
[TestMethod]
[Fact]
public void Later_Binding_With_Same_Priority_Should_Take_Precedence()
{
var target = new PriorityValue("Test", typeof(string));
@ -67,10 +66,10 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("baz"), 0);
target.Add(this.Single("qux"), 1);
Assert.AreEqual("baz", target.Value);
Assert.Equal("baz", target.Value);
}
[TestMethod]
[Fact]
public void Changing_Binding_With_Lower_Priority_Should_Set_Not_Value()
{
var target = new PriorityValue("Test", typeof(string));
@ -78,12 +77,12 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("foo"), 0);
target.Add(subject, 1);
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
subject.OnNext("baz");
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
}
[TestMethod]
[Fact]
public void UnsetValue_Should_Fall_Back_To_Next_Binding()
{
var target = new PriorityValue("Test", typeof(string));
@ -92,14 +91,14 @@ namespace Perspex.Base.UnitTests
target.Add(subject, 0);
target.Add(this.Single("foo"), 1);
Assert.AreEqual("bar", target.Value);
Assert.Equal("bar", target.Value);
subject.OnNext(PerspexProperty.UnsetValue);
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
}
[TestMethod]
[Fact]
public void Adding_Value_Should_Call_OnNext()
{
var target = new PriorityValue("Test", typeof(string));
@ -108,10 +107,10 @@ namespace Perspex.Base.UnitTests
target.Changed.Subscribe(value => called = (value.Item1 == PerspexProperty.UnsetValue && (string)value.Item2 == "foo"));
target.Add(this.Single("foo"), 0);
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Changing_Value_Should_Call_OnNext()
{
var target = new PriorityValue("Test", typeof(string));
@ -122,10 +121,10 @@ namespace Perspex.Base.UnitTests
target.Changed.Subscribe(value => called = ((string)value.Item1 == "foo" && (string)value.Item2 == "bar"));
subject.OnNext("bar");
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Disposing_A_Binding_Should_Revert_To_Next_Value()
{
var target = new PriorityValue("Test", typeof(string));
@ -133,12 +132,12 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("foo"), 0);
var disposable = target.Add(this.Single("bar"), 0);
Assert.AreEqual("bar", target.Value);
Assert.Equal("bar", target.Value);
disposable.Dispose();
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
}
[TestMethod]
[Fact]
public void Disposing_A_Binding_Should_Remove_BindingEntry()
{
var target = new PriorityValue("Test", typeof(string));
@ -146,12 +145,12 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("foo"), 0);
var disposable = target.Add(this.Single("bar"), 0);
Assert.AreEqual(2, target.GetBindings().Count());
Assert.Equal(2, target.GetBindings().Count());
disposable.Dispose();
Assert.AreEqual(1, target.GetBindings().Count());
Assert.Equal(1, target.GetBindings().Count());
}
[TestMethod]
[Fact]
public void Completing_A_Binding_Should_Revert_To_Next_Value()
{
var target = new PriorityValue("Test", typeof(string));
@ -160,12 +159,12 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("foo"), 0);
target.Add(subject, 0);
Assert.AreEqual("bar", target.Value);
Assert.Equal("bar", target.Value);
subject.OnCompleted();
Assert.AreEqual("foo", target.Value);
Assert.Equal("foo", target.Value);
}
[TestMethod]
[Fact]
public void Completing_A_Binding_Should_Remove_BindingEntry()
{
var target = new PriorityValue("Test", typeof(string));
@ -174,9 +173,9 @@ namespace Perspex.Base.UnitTests
target.Add(this.Single("foo"), 0);
target.Add(subject, 0);
Assert.AreEqual(2, target.GetBindings().Count());
Assert.Equal(2, target.GetBindings().Count());
subject.OnCompleted();
Assert.AreEqual(1, target.GetBindings().Count());
Assert.Equal(1, target.GetBindings().Count());
}
/// <summary>

2
Perspex.Base.UnitTests/packages.config

@ -5,4 +5,6 @@
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" />
<package id="Rx-Linq" version="2.2.5" targetFramework="net45" />
<package id="Splat" version="1.5.1" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0-rc1-build1030" targetFramework="net45" />
</packages>

59
Perspex.Controls.UnitTests/ContentControlTests.cs

@ -9,7 +9,6 @@ namespace Perspex.Controls.UnitTests
using System;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
@ -20,11 +19,11 @@ namespace Perspex.Controls.UnitTests
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Splat;
using Xunit;
[TestClass]
public class ContentControlTests
{
[TestMethod]
[Fact]
public void Template_Should_Be_Instantiated()
{
using (var ctx = this.RegisterServices())
@ -36,15 +35,15 @@ namespace Perspex.Controls.UnitTests
target.Measure(new Size(100, 100));
var child = ((IVisual)target).VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(Border));
Assert.IsType<Border>(child);
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(ContentPresenter));
Assert.IsType<ContentPresenter>(child);
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(TextBlock));
Assert.IsType<TextBlock>(child);
}
}
[TestMethod]
[Fact]
public void Templated_Children_Should_Be_Styled()
{
using (var ctx = this.RegisterServices())
@ -67,7 +66,7 @@ namespace Perspex.Controls.UnitTests
}
}
[TestMethod]
[Fact]
public void ContentPresenter_Should_Have_TemplatedParent_Set()
{
var target = new ContentControl();
@ -78,10 +77,10 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
var contentPresenter = child.GetVisualParent<ContentPresenter>();
Assert.AreEqual(target, contentPresenter.TemplatedParent);
Assert.Equal(target, contentPresenter.TemplatedParent);
}
[TestMethod]
[Fact]
public void Content_Should_Have_TemplatedParent_Set_To_Null()
{
var target = new ContentControl();
@ -91,10 +90,10 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.ApplyTemplate();
Assert.IsNull(child.TemplatedParent);
Assert.Null(child.TemplatedParent);
}
[TestMethod]
[Fact]
public void Setting_Content_Should_Set_Child_Controls_Parent()
{
var target = new ContentControl();
@ -102,11 +101,11 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
Assert.AreEqual(child.Parent, target);
Assert.AreEqual(((ILogical)child).LogicalParent, target);
Assert.Equal(child.Parent, target);
Assert.Equal(((ILogical)child).LogicalParent, target);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Clear_Child_Controls_Parent()
{
var target = new ContentControl();
@ -115,11 +114,11 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.Content = null;
Assert.IsNull(child.Parent);
Assert.IsNull(((ILogical)child).LogicalParent);
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
[TestMethod]
[Fact]
public void Setting_Content_To_Control_Should_Make_Control_Appear_In_LogicalChildren()
{
var target = new ContentControl();
@ -129,10 +128,10 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.ApplyTemplate();
CollectionAssert.AreEqual(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Setting_Content_To_String_Should_Make_TextBlock_Appear_In_LogicalChildren()
{
var target = new ContentControl();
@ -143,11 +142,11 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
var logical = (ILogical)target;
Assert.AreEqual(1, logical.LogicalChildren.Count);
Assert.IsInstanceOfType(logical.LogicalChildren[0], typeof(TextBlock));
Assert.Equal(1, logical.LogicalChildren.Count);
Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Remove_From_LogicalChildren()
{
var contentControl = new ContentControl();
@ -156,10 +155,10 @@ namespace Perspex.Controls.UnitTests
contentControl.Content = child;
contentControl.Content = null;
CollectionAssert.AreEqual(new ILogical[0], ((ILogical)contentControl).LogicalChildren.ToList());
Assert.Equal(new ILogical[0], ((ILogical)contentControl).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Setting_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var contentControl = new ContentControl();
@ -177,10 +176,10 @@ namespace Perspex.Controls.UnitTests
var presenter = contentControl.GetTemplateControls().Single(x => x.Id == "contentPresenter");
presenter.ApplyTemplate();
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var contentControl = new ContentControl();
@ -200,10 +199,10 @@ namespace Perspex.Controls.UnitTests
var presenter = contentControl.GetTemplateControls().Single(x => x.Id == "contentPresenter");
presenter.ApplyTemplate();
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var contentControl = new ContentControl();
@ -224,7 +223,7 @@ namespace Perspex.Controls.UnitTests
var presenter = contentControl.GetTemplateControls().Single(x => x.Id == "contentPresenter");
presenter.ApplyTemplate();
Assert.IsTrue(called);
Assert.True(called);
}
private ControlTemplate GetTemplate()

12
Perspex.Controls.UnitTests/ControlTests.cs

@ -7,8 +7,6 @@
namespace Perspex.Controls.UnitTests
{
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Controls;
using Perspex.Layout;
@ -16,19 +14,19 @@ namespace Perspex.Controls.UnitTests
using Perspex.Rendering;
using Perspex.Styling;
using Splat;
using Xunit;
[TestClass]
public class ControlTests
{
[TestMethod]
[Fact]
public void Classes_Should_Initially_Be_Empty()
{
var target = new Control();
Assert.AreEqual(0, target.Classes.Count);
Assert.Equal(0, target.Classes.Count);
}
[TestMethod]
[Fact]
public void Adding_Control_To_IRenderRoot_Should_Style_Control()
{
using (Locator.CurrentMutable.WithResolver())
@ -45,7 +43,7 @@ namespace Perspex.Controls.UnitTests
}
}
[TestMethod]
[Fact]
public void Adding_Tree_To_ILayoutRoot_Should_Style_Controls()
{
using (Locator.CurrentMutable.WithResolver())

35
Perspex.Controls.UnitTests/DecoratorTests.cs

@ -8,12 +8,11 @@ namespace Perspex.Controls.UnitTests
{
using System.Collections.Specialized;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
[TestClass]
public class DecoratorTests
{
[TestMethod]
[Fact]
public void Setting_Content_Should_Set_Child_Controls_Parent()
{
var decorator = new Decorator();
@ -21,11 +20,11 @@ namespace Perspex.Controls.UnitTests
decorator.Content = child;
Assert.AreEqual(child.Parent, decorator);
Assert.AreEqual(((ILogical)child).LogicalParent, decorator);
Assert.Equal(child.Parent, decorator);
Assert.Equal(((ILogical)child).LogicalParent, decorator);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Clear_Child_Controls_Parent()
{
var decorator = new Decorator();
@ -34,11 +33,11 @@ namespace Perspex.Controls.UnitTests
decorator.Content = child;
decorator.Content = null;
Assert.IsNull(child.Parent);
Assert.IsNull(((ILogical)child).LogicalParent);
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
[TestMethod]
[Fact]
public void Content_Control_Should_Appear_In_LogicalChildren()
{
var decorator = new Decorator();
@ -46,10 +45,10 @@ namespace Perspex.Controls.UnitTests
decorator.Content = child;
CollectionAssert.AreEqual(new[] { child }, ((ILogical)decorator).LogicalChildren.ToList());
Assert.Equal(new[] { child }, ((ILogical)decorator).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Remove_From_LogicalChildren()
{
var decorator = new Decorator();
@ -58,10 +57,10 @@ namespace Perspex.Controls.UnitTests
decorator.Content = child;
decorator.Content = null;
CollectionAssert.AreEqual(new ILogical[0], ((ILogical)decorator).LogicalChildren.ToList());
Assert.Equal(new ILogical[0], ((ILogical)decorator).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Setting_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var decorator = new Decorator();
@ -73,10 +72,10 @@ namespace Perspex.Controls.UnitTests
decorator.Content = child;
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var decorator = new Decorator();
@ -90,10 +89,10 @@ namespace Perspex.Controls.UnitTests
decorator.Content = null;
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var decorator = new Decorator();
@ -108,7 +107,7 @@ namespace Perspex.Controls.UnitTests
decorator.Content = child2;
Assert.IsTrue(called);
Assert.True(called);
}
}
}

59
Perspex.Controls.UnitTests/DropDownTests.cs

@ -9,7 +9,6 @@ namespace Perspex.Controls.UnitTests
using System;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
@ -19,11 +18,11 @@ namespace Perspex.Controls.UnitTests
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Splat;
using Xunit;
[TestClass]
public class DropDownTests
{
[TestMethod]
[Fact]
public void Template_Should_Be_Instantiated()
{
using (var ctx = this.RegisterServices())
@ -35,15 +34,15 @@ namespace Perspex.Controls.UnitTests
target.Measure(new Size(100, 100));
var child = ((IVisual)target).VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(Border));
Assert.IsType<Border>(child);
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(ContentPresenter));
Assert.IsType<ContentPresenter>(child);
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(TextBlock));
Assert.IsType<TextBlock>(child);
}
}
[TestMethod]
[Fact]
public void Templated_Children_Should_Be_Styled()
{
using (var ctx = this.RegisterServices())
@ -66,7 +65,7 @@ namespace Perspex.Controls.UnitTests
}
}
[TestMethod]
[Fact]
public void ContentPresenter_Should_Have_TemplatedParent_Set()
{
var target = new DropDown();
@ -77,10 +76,10 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
var contentPresenter = child.GetVisualParent<ContentPresenter>();
Assert.AreEqual(target, contentPresenter.TemplatedParent);
Assert.Equal(target, contentPresenter.TemplatedParent);
}
[TestMethod]
[Fact]
public void Content_Should_Have_TemplatedParent_Set_To_Null()
{
var target = new DropDown();
@ -90,10 +89,10 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.ApplyTemplate();
Assert.IsNull(child.TemplatedParent);
Assert.Null(child.TemplatedParent);
}
[TestMethod]
[Fact]
public void Setting_Content_Should_Set_Child_Controls_Parent()
{
var target = new DropDown();
@ -101,11 +100,11 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
Assert.AreEqual(child.Parent, target);
Assert.AreEqual(((ILogical)child).LogicalParent, target);
Assert.Equal(child.Parent, target);
Assert.Equal(((ILogical)child).LogicalParent, target);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Clear_Child_Controls_Parent()
{
var target = new DropDown();
@ -114,11 +113,11 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.Content = null;
Assert.IsNull(child.Parent);
Assert.IsNull(((ILogical)child).LogicalParent);
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
[TestMethod]
[Fact]
public void Setting_Content_To_Control_Should_Make_Control_Appear_In_LogicalChildren()
{
var target = new DropDown();
@ -128,10 +127,10 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.ApplyTemplate();
CollectionAssert.AreEqual(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Setting_Content_To_String_Should_Make_TextBlock_Appear_In_LogicalChildren()
{
var target = new DropDown();
@ -142,11 +141,11 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
var logical = (ILogical)target;
Assert.AreEqual(1, logical.LogicalChildren.Count);
Assert.IsInstanceOfType(logical.LogicalChildren[0], typeof(TextBlock));
Assert.Equal(1, logical.LogicalChildren.Count);
Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Remove_From_LogicalChildren()
{
var target = new DropDown();
@ -155,10 +154,10 @@ namespace Perspex.Controls.UnitTests
target.Content = child;
target.Content = null;
CollectionAssert.AreEqual(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Setting_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new DropDown();
@ -176,10 +175,10 @@ namespace Perspex.Controls.UnitTests
var presenter = target.GetTemplateControls().Single(x => x.Id == "contentPresenter");
presenter.ApplyTemplate();
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Clearing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new DropDown();
@ -199,10 +198,10 @@ namespace Perspex.Controls.UnitTests
var presenter = target.GetTemplateControls().Single(x => x.Id == "contentPresenter");
presenter.ApplyTemplate();
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Changing_Content_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new DropDown();
@ -223,7 +222,7 @@ namespace Perspex.Controls.UnitTests
var presenter = target.GetTemplateControls().Single(x => x.Id == "contentPresenter");
presenter.ApplyTemplate();
Assert.IsTrue(called);
Assert.True(called);
}
private ControlTemplate GetTemplate()

57
Perspex.Controls.UnitTests/ItemsControlTests.cs

@ -9,7 +9,6 @@ namespace Perspex.Controls.UnitTests
using System;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Collections;
using Perspex.Controls;
using Perspex.Controls.Presenters;
@ -19,11 +18,11 @@ namespace Perspex.Controls.UnitTests
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Splat;
using Xunit;
[TestClass]
public class ItemsControlTests
{
[TestMethod]
[Fact]
public void Panel_Should_Have_TemplatedParent_Set_To_ItemsPresenter()
{
var target = new ItemsControl();
@ -35,10 +34,10 @@ namespace Perspex.Controls.UnitTests
var presenter = target.GetTemplateControls().OfType<ItemsPresenter>().Single();
var panel = presenter.GetTemplateControls().OfType<StackPanel>().Single();
Assert.AreEqual(presenter, panel.TemplatedParent);
Assert.Equal(presenter, panel.TemplatedParent);
}
[TestMethod]
[Fact]
public void Item_Should_Have_TemplatedParent_Set_To_Null()
{
var target = new ItemsControl();
@ -51,10 +50,10 @@ namespace Perspex.Controls.UnitTests
var panel = presenter.GetTemplateControls().OfType<StackPanel>().Single();
var item = (TextBlock)panel.GetVisualChildren().First();
Assert.IsNull(item.TemplatedParent);
Assert.Null(item.TemplatedParent);
}
[TestMethod]
[Fact]
public void Control_Item_Should_Have_Parent_Set()
{
var target = new ItemsControl();
@ -64,11 +63,11 @@ namespace Perspex.Controls.UnitTests
target.Items = new[] { child };
target.ApplyTemplate();
Assert.AreEqual(target, child.Parent);
Assert.AreEqual(target, ((ILogical)child).LogicalParent);
Assert.Equal(target, child.Parent);
Assert.Equal(target, ((ILogical)child).LogicalParent);
}
[TestMethod]
[Fact]
public void Clearing_Control_Item_Should_Clear_Child_Controls_Parent()
{
var target = new ItemsControl();
@ -79,11 +78,11 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
target.Items = null;
Assert.IsNull(child.Parent);
Assert.IsNull(((ILogical)child).LogicalParent);
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
[TestMethod]
[Fact]
public void Adding_Control_Item_Should_Make_Control_Appear_In_LogicalChildren()
{
var target = new ItemsControl();
@ -93,10 +92,10 @@ namespace Perspex.Controls.UnitTests
target.Items = new[] { child };
target.ApplyTemplate();
CollectionAssert.AreEqual(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
Assert.Equal(new[] { child }, ((ILogical)target).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Adding_String_Item_Should_Make_TextBlock_Appear_In_LogicalChildren()
{
var target = new ItemsControl();
@ -107,11 +106,11 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
var logical = (ILogical)target;
Assert.AreEqual(1, logical.LogicalChildren.Count);
Assert.IsInstanceOfType(logical.LogicalChildren[0], typeof(TextBlock));
Assert.Equal(1, logical.LogicalChildren.Count);
Assert.IsType<TextBlock>(logical.LogicalChildren[0]);
}
[TestMethod]
[Fact]
public void Setting_Items_To_Null_Should_Remove_LogicalChildren()
{
var target = new ItemsControl();
@ -122,10 +121,10 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
target.Items = null;
CollectionAssert.AreEqual(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
Assert.Equal(new ILogical[0], ((ILogical)target).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Setting_Items_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
@ -140,10 +139,10 @@ namespace Perspex.Controls.UnitTests
target.Items = new[] { child };
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Setting_Items_To_Null_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
@ -159,10 +158,10 @@ namespace Perspex.Controls.UnitTests
target.Items = null;
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Changing_Items_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
@ -177,10 +176,10 @@ namespace Perspex.Controls.UnitTests
target.Items = new[] { "Foo" };
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Adding_Items_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
@ -196,10 +195,10 @@ namespace Perspex.Controls.UnitTests
items.Add("Bar");
Assert.IsTrue(called);
Assert.True(called);
}
[TestMethod]
[Fact]
public void Removing_Items_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
@ -215,7 +214,7 @@ namespace Perspex.Controls.UnitTests
items.Remove("Bar");
Assert.IsTrue(called);
Assert.True(called);
}
private ControlTemplate GetTemplate()

53
Perspex.Controls.UnitTests/PanelTests.cs

@ -7,12 +7,11 @@
namespace Perspex.Controls.UnitTests
{
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
[TestClass]
public class PanelTests
{
[TestMethod]
[Fact]
public void Adding_Control_To_Panel_Should_Set_Child_Controls_Parent()
{
var panel = new Panel();
@ -20,11 +19,11 @@ namespace Perspex.Controls.UnitTests
panel.Children.Add(child);
Assert.AreEqual(child.Parent, panel);
Assert.AreEqual(((ILogical)child).LogicalParent, panel);
Assert.Equal(child.Parent, panel);
Assert.Equal(((ILogical)child).LogicalParent, panel);
}
[TestMethod]
[Fact]
public void Setting_Controls_Should_Set_Child_Controls_Parent()
{
var panel = new Panel();
@ -32,11 +31,11 @@ namespace Perspex.Controls.UnitTests
panel.Children = new Controls { child };
Assert.AreEqual(child.Parent, panel);
Assert.AreEqual(((ILogical)child).LogicalParent, panel);
Assert.Equal(child.Parent, panel);
Assert.Equal(((ILogical)child).LogicalParent, panel);
}
[TestMethod]
[Fact]
public void Removing_Control_From_Panel_Should_Clear_Child_Controls_Parent()
{
var panel = new Panel();
@ -45,11 +44,11 @@ namespace Perspex.Controls.UnitTests
panel.Children.Add(child);
panel.Children.Remove(child);
Assert.IsNull(child.Parent);
Assert.IsNull(((ILogical)child).LogicalParent);
Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent);
}
[TestMethod]
[Fact]
public void Clearing_Panel_Children_Should_Clear_Child_Controls_Parent()
{
var panel = new Panel();
@ -60,13 +59,13 @@ namespace Perspex.Controls.UnitTests
panel.Children.Add(child2);
panel.Children.Clear();
Assert.IsNull(child1.Parent);
Assert.IsNull(((ILogical)child1).LogicalParent);
Assert.IsNull(child2.Parent);
Assert.IsNull(((ILogical)child2).LogicalParent);
Assert.Null(child1.Parent);
Assert.Null(((ILogical)child1).LogicalParent);
Assert.Null(child2.Parent);
Assert.Null(((ILogical)child2).LogicalParent);
}
[TestMethod]
[Fact]
public void Resetting_Panel_Children_Should_Clear_Child_Controls_Parent()
{
var panel = new Panel();
@ -77,13 +76,13 @@ namespace Perspex.Controls.UnitTests
panel.Children.Add(child2);
panel.Children = new Controls();
Assert.IsNull(child1.Parent);
Assert.IsNull(((ILogical)child1).LogicalParent);
Assert.IsNull(child2.Parent);
Assert.IsNull(((ILogical)child2).LogicalParent);
Assert.Null(child1.Parent);
Assert.Null(((ILogical)child1).LogicalParent);
Assert.Null(child2.Parent);
Assert.Null(((ILogical)child2).LogicalParent);
}
[TestMethod]
[Fact]
public void Child_Control_Should_Appear_In_Panel_Children()
{
var panel = new Panel();
@ -91,11 +90,11 @@ namespace Perspex.Controls.UnitTests
panel.Children.Add(child);
CollectionAssert.AreEqual(new[] { child }, panel.Children);
CollectionAssert.AreEqual(new[] { child }, ((ILogical)panel).LogicalChildren.ToList());
Assert.Equal(new[] { child }, panel.Children);
Assert.Equal(new[] { child }, ((ILogical)panel).LogicalChildren.ToList());
}
[TestMethod]
[Fact]
public void Removing_Child_Control_Should_Remove_From_Panel_Children()
{
var panel = new Panel();
@ -104,8 +103,8 @@ namespace Perspex.Controls.UnitTests
panel.Children.Add(child);
panel.Children.Remove(child);
CollectionAssert.AreEqual(new Control[0], panel.Children);
CollectionAssert.AreEqual(new ILogical[0], ((ILogical)panel).LogicalChildren.ToList());
Assert.Equal(new Control[0], panel.Children);
Assert.Equal(new ILogical[0], ((ILogical)panel).LogicalChildren.ToList());
}
}
}

18
Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,12 +11,12 @@
<AssemblyName>Perspex.Controls.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>
<NuGetPackageImportStamp>e1f08d4e</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -50,6 +51,9 @@
<HintPath>..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -57,11 +61,7 @@
<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>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="DropDownTests.cs" />
@ -133,6 +133,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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">

58
Perspex.Controls.UnitTests/TemplatedControlTests.cs

@ -4,15 +4,9 @@
// </copyright>
// -----------------------------------------------------------------------
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Perspex.Controls.UnitTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
@ -20,11 +14,11 @@ namespace Perspex.Controls.UnitTests
using Perspex.Styling;
using Perspex.VisualTree;
using Splat;
using Xunit;
[TestClass]
public class TemplatedControlTests
{
[TestMethod]
[Fact]
public void Template_Doesnt_Get_Executed_On_Set()
{
bool executed = false;
@ -40,10 +34,10 @@ namespace Perspex.Controls.UnitTests
Template = template,
};
Assert.IsFalse(executed);
Assert.False(executed);
}
[TestMethod]
[Fact]
public void Template_Gets_Executed_On_Measure()
{
bool executed = false;
@ -61,10 +55,10 @@ namespace Perspex.Controls.UnitTests
target.Measure(new Size(100, 100));
Assert.IsTrue(executed);
Assert.True(executed);
}
[TestMethod]
[Fact]
public void Template_Result_Becomes_Visual_Child()
{
Control templateResult = new Control();
@ -82,10 +76,10 @@ namespace Perspex.Controls.UnitTests
target.Measure(new Size(100, 100));
var children = target.GetVisualChildren().ToList();
CollectionAssert.AreEqual(new[] { templateResult }, children);
Assert.Equal(new[] { templateResult }, children);
}
[TestMethod]
[Fact]
public void TemplatedParent_Is_Set_On_Generated_Template()
{
Control templateResult = new Control();
@ -102,10 +96,10 @@ namespace Perspex.Controls.UnitTests
target.Measure(new Size(100, 100));
Assert.AreEqual(target, templateResult.TemplatedParent);
Assert.Equal(target, templateResult.TemplatedParent);
}
[TestMethod]
[Fact]
public void OnTemplateApplied_Is_Called()
{
var target = new TestTemplatedControl
@ -118,10 +112,10 @@ namespace Perspex.Controls.UnitTests
target.Measure(new Size(100, 100));
Assert.IsTrue(target.OnTemplateAppliedCalled);
Assert.True(target.OnTemplateAppliedCalled);
}
[TestMethod]
[Fact]
public void Template_Should_Be_Instantated()
{
var target = new TestTemplatedControl
@ -143,12 +137,12 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
var child = target.GetVisualChildren().Single();
Assert.IsInstanceOfType(child, typeof(StackPanel));
Assert.IsType<StackPanel>(child);
child = child.VisualChildren.Single();
Assert.IsInstanceOfType(child, typeof(TextBlock));
Assert.IsType<TextBlock>(child);
}
[TestMethod]
[Fact]
public void Templated_Children_Should_Be_Styled()
{
using (Locator.Current.WithResolver())
@ -186,7 +180,7 @@ namespace Perspex.Controls.UnitTests
}
}
[TestMethod]
[Fact]
public void Templated_Children_Should_Have_TemplatedParent_Set()
{
var target = new TestTemplatedControl
@ -210,11 +204,11 @@ namespace Perspex.Controls.UnitTests
var panel = target.GetTemplateControls().OfType<StackPanel>().Single();
var textBlock = target.GetTemplateControls().OfType<TextBlock>().Single();
Assert.AreEqual(target, panel.TemplatedParent);
Assert.AreEqual(target, textBlock.TemplatedParent);
Assert.Equal(target, panel.TemplatedParent);
Assert.Equal(target, textBlock.TemplatedParent);
}
[TestMethod]
[Fact]
public void Presenter_Children_Should_Not_Have_TemplatedParent_Set()
{
var target = new TestTemplatedControl
@ -235,11 +229,11 @@ namespace Perspex.Controls.UnitTests
var presenter = target.GetTemplateControls().OfType<ContentPresenter>().Single();
var textBlock = (TextBlock)presenter.Child;
Assert.AreEqual(target, presenter.TemplatedParent);
Assert.IsNull(textBlock.TemplatedParent);
Assert.Equal(target, presenter.TemplatedParent);
Assert.Null(textBlock.TemplatedParent);
}
[TestMethod]
[Fact]
public void Nested_Templated_Controls_Have_Correct_TemplatedParent()
{
var target = new TestTemplatedControl
@ -272,10 +266,10 @@ namespace Perspex.Controls.UnitTests
var presenter = contentControl.GetTemplateControls().OfType<ContentPresenter>().Single();
var textBlock = (TextBlock)presenter.Content;
Assert.AreEqual(target, contentControl.TemplatedParent);
Assert.AreEqual(contentControl, border.TemplatedParent);
Assert.AreEqual(contentControl, presenter.TemplatedParent);
Assert.AreEqual(target, textBlock.TemplatedParent);
Assert.Equal(target, contentControl.TemplatedParent);
Assert.Equal(contentControl, border.TemplatedParent);
Assert.Equal(contentControl, presenter.TemplatedParent);
Assert.Equal(target, textBlock.TemplatedParent);
}
}
}

2
Perspex.Controls.UnitTests/packages.config

@ -4,4 +4,6 @@
<package id="AutoFixture.AutoMoq" version="3.21.1" targetFramework="net45" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" />
<package id="Splat" version="1.5.1" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0-rc1-build1030" targetFramework="net45" />
</packages>

38
Perspex.Layout.UnitTests/FullLayoutTests.cs

@ -4,11 +4,9 @@
// </copyright>
// -----------------------------------------------------------------------
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Perspex.Layout.UnitTests
{
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
@ -21,11 +19,11 @@ namespace Perspex.Layout.UnitTests
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Splat;
using Xunit;
[TestClass]
public class FullLayoutTests
{
[TestMethod]
[Fact]
public void Grandchild_Size_Changed()
{
using (var context = Locator.CurrentMutable.WithResolver())
@ -55,15 +53,15 @@ namespace Perspex.Layout.UnitTests
window.LayoutManager.ExecuteLayoutPass();
Assert.AreEqual(new Size(400, 400), border.ActualSize);
Assert.Equal(new Size(400, 400), border.ActualSize);
textBlock.Width = 200;
window.LayoutManager.ExecuteLayoutPass();
Assert.AreEqual(new Size(200, 400), border.ActualSize);
Assert.Equal(new Size(200, 400), border.ActualSize);
}
}
[TestMethod]
[Fact]
public void Test_ScrollViewer_With_TextBlock()
{
using (var context = Locator.CurrentMutable.WithResolver())
@ -95,29 +93,29 @@ namespace Perspex.Layout.UnitTests
window.LayoutManager.ExecuteLayoutPass();
Assert.AreEqual(new Size(800, 600), window.ActualSize);
Assert.AreEqual(new Size(200, 200), scrollViewer.ActualSize);
Assert.AreEqual(new Point(300, 200), Position(scrollViewer));
Assert.AreEqual(new Size(400, 400), textBlock.ActualSize);
Assert.Equal(new Size(800, 600), window.ActualSize);
Assert.Equal(new Size(200, 200), scrollViewer.ActualSize);
Assert.Equal(new Point(300, 200), Position(scrollViewer));
Assert.Equal(new Size(400, 400), textBlock.ActualSize);
var scrollBars = scrollViewer.GetTemplateControls().OfType<ScrollBar>().ToList();
var presenters = scrollViewer.GetTemplateControls().OfType<ScrollContentPresenter>().ToList();
Assert.AreEqual(2, scrollBars.Count);
Assert.AreEqual(1, presenters.Count);
Assert.Equal(2, scrollBars.Count);
Assert.Equal(1, presenters.Count);
var presenter = presenters[0];
Assert.AreEqual(new Size(190, 190), presenter.ActualSize);
Assert.Equal(new Size(190, 190), presenter.ActualSize);
var horzScroll = scrollBars.Single(x => x.Orientation == Orientation.Horizontal);
var vertScroll = scrollBars.Single(x => x.Orientation == Orientation.Vertical);
Assert.IsTrue(horzScroll.IsVisible);
Assert.IsTrue(vertScroll.IsVisible);
Assert.AreEqual(new Size(190, 10), horzScroll.ActualSize);
Assert.AreEqual(new Size(10, 190), vertScroll.ActualSize);
Assert.AreEqual(new Point(0, 190), Position(horzScroll));
Assert.AreEqual(new Point(190, 0), Position(vertScroll));
Assert.True(horzScroll.IsVisible);
Assert.True(vertScroll.IsVisible);
Assert.Equal(new Size(190, 10), horzScroll.ActualSize);
Assert.Equal(new Size(10, 190), vertScroll.ActualSize);
Assert.Equal(new Point(0, 190), Position(horzScroll));
Assert.Equal(new Point(190, 0), Position(vertScroll));
}
}

18
Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,12 +11,12 @@
<AssemblyName>Perspex.Layout.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>
<NuGetPackageImportStamp>b0a273ef</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -49,6 +50,9 @@
<HintPath>..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -56,11 +60,7 @@
<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>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="FullLayoutTests.cs" />
@ -128,6 +128,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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">

2
Perspex.Layout.UnitTests/packages.config

@ -4,4 +4,6 @@
<package id="AutoFixture.AutoMoq" version="3.21.1" targetFramework="net45" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net45" />
<package id="Splat" version="1.5.1" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0-rc1-build1030" targetFramework="net45" />
</packages>

18
Perspex.SceneGraph.UnitTests/Perspex.SceneGraph.UnitTests.csproj

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,12 +11,12 @@
<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>
<NuGetPackageImportStamp>404e5813</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -40,6 +41,9 @@
<HintPath>..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -47,11 +51,7 @@
<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>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="TestRoot.cs" />
@ -97,6 +97,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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">

35
Perspex.SceneGraph.UnitTests/VisualTests.cs

@ -7,13 +7,12 @@
namespace Perspex.SceneGraph.UnitTests
{
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.VisualTree;
using Xunit;
[TestClass]
public class VisualTests
{
[TestMethod]
[Fact]
public void Added_Child_Should_Have_VisualParent_Set()
{
var target = new TestVisual();
@ -21,10 +20,10 @@ namespace Perspex.SceneGraph.UnitTests
target.AddChild(child);
Assert.AreEqual(target, child.GetVisualParent());
Assert.Equal(target, child.GetVisualParent());
}
[TestMethod]
[Fact]
public void Added_Child_Should_Have_InheritanceParent_Set()
{
var target = new TestVisual();
@ -32,10 +31,10 @@ namespace Perspex.SceneGraph.UnitTests
target.AddChild(child);
Assert.AreEqual(target, child.InheritanceParent);
Assert.Equal(target, child.InheritanceParent);
}
[TestMethod]
[Fact]
public void Removed_Child_Should_Have_VisualParent_Cleared()
{
var target = new TestVisual();
@ -44,10 +43,10 @@ namespace Perspex.SceneGraph.UnitTests
target.AddChild(child);
target.RemoveChild(child);
Assert.IsNull(child.GetVisualParent());
Assert.Null(child.GetVisualParent());
}
[TestMethod]
[Fact]
public void Removed_Child_Should_Have_InheritanceParent_Cleared()
{
var target = new TestVisual();
@ -56,10 +55,10 @@ namespace Perspex.SceneGraph.UnitTests
target.AddChild(child);
target.RemoveChild(child);
Assert.IsNull(child.InheritanceParent);
Assert.Null(child.InheritanceParent);
}
[TestMethod]
[Fact]
public void Clearing_Children_Should_Clear_VisualParent()
{
var children = new[] { new Visual(), new Visual() };
@ -70,10 +69,10 @@ namespace Perspex.SceneGraph.UnitTests
var result = children.Select(x => x.GetVisualParent()).ToList();
CollectionAssert.AreEqual(new Visual[] { null, null }, result);
Assert.Equal(new Visual[] { null, null }, result);
}
[TestMethod]
[Fact]
public void ParentChanged_Attached_Methods_Should_Be_Called_In_Right_Order()
{
var target = new TestRoot();
@ -87,11 +86,11 @@ namespace Perspex.SceneGraph.UnitTests
target.AddChild(child);
Assert.AreEqual(1, changed);
Assert.AreEqual(2, attched);
Assert.Equal(1, changed);
Assert.Equal(2, attched);
}
[TestMethod]
[Fact]
public void ParentChanged_Detached_Methods_Should_Be_Called_In_Right_Order()
{
var target = new TestRoot();
@ -107,8 +106,8 @@ namespace Perspex.SceneGraph.UnitTests
target.ClearChildren();
Assert.AreEqual(1, changed);
Assert.AreEqual(2, detached);
Assert.Equal(1, changed);
Assert.Equal(2, detached);
}
}
}

2
Perspex.SceneGraph.UnitTests/packages.config

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Splat" version="1.5.1" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0-rc1-build1030" targetFramework="net45" />
</packages>

18
Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,12 +11,12 @@
<AssemblyName>Perspex.Styling.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>
<NuGetPackageImportStamp>3ac3f42c</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -56,6 +57,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="xunit">
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -63,11 +67,7 @@
<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>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@ -124,6 +124,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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">

41
Perspex.Styling.UnitTests/SelectorTests_Class.cs

@ -8,23 +8,22 @@ namespace Perspex.Styling.UnitTests
{
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Styling;
using Xunit;
[TestClass]
public class SelectorTests_Class
{
[TestMethod]
[Fact]
public void Class_Priority_Is_StyleTrigger()
{
var control = new Control1();
var target = new Selector().Class("foo");
Assert.AreEqual(BindingPriority.StyleTrigger, target.Priority);
Assert.Equal(BindingPriority.StyleTrigger, target.Priority);
}
[TestMethod]
[Fact]
public void Class_Matches_Control_With_Class()
{
var control = new Control1
@ -34,10 +33,10 @@ namespace Perspex.Styling.UnitTests
var target = new Selector().Class("foo");
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Class_Doesnt_Match_Control_Without_Class()
{
var control = new Control1
@ -47,10 +46,10 @@ namespace Perspex.Styling.UnitTests
var target = new Selector().Class("foo");
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Class_Matches_Control_With_TemplatedParent()
{
var control = new Control1
@ -61,10 +60,10 @@ namespace Perspex.Styling.UnitTests
var target = new Selector().Class("foo");
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Class_Tracks_Additions()
{
var control = new Control1();
@ -72,12 +71,12 @@ namespace Perspex.Styling.UnitTests
var target = new Selector().Class("foo");
var activator = target.GetActivator(control);
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
control.Classes.Add("foo");
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Class_Tracks_Removals()
{
var control = new Control1
@ -88,25 +87,25 @@ namespace Perspex.Styling.UnitTests
var target = new Selector().Class("foo");
var activator = target.GetActivator(control);
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
control.Classes.Remove("foo");
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Multiple_Classes()
{
var control = new Control1();
var target = new Selector().Class("foo").Class("bar");
var activator = target.GetActivator(control);
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
control.Classes.Add("foo");
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
control.Classes.Add("bar");
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
control.Classes.Remove("bar");
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
}
private static bool ActivatorValue(Selector selector, IStyleable control)

19
Perspex.Styling.UnitTests/SelectorTests_Descendent.cs

@ -9,15 +9,14 @@ namespace Perspex.Styling.UnitTests
using System;
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Collections;
using Perspex.Styling;
using Xunit;
[TestClass]
public class SelectorTests_Descendent
{
[TestMethod]
[Fact]
public void Descendent_Matches_Control_When_It_Is_Child_OfType()
{
var parent = new Mock<TestLogical1>();
@ -28,10 +27,10 @@ namespace Perspex.Styling.UnitTests
var selector = new Selector().OfType(parent.Object.GetType()).Descendent().OfType(child.Object.GetType());
Assert.IsTrue(ActivatorValue(selector, childStyleable.Object));
Assert.True(ActivatorValue(selector, childStyleable.Object));
}
[TestMethod]
[Fact]
public void Descendent_Matches_Control_When_It_Is_Descendent_OfType()
{
var grandparent = new Mock<TestLogical1>();
@ -43,10 +42,10 @@ namespace Perspex.Styling.UnitTests
var selector = new Selector().OfType(grandparent.Object.GetType()).Descendent().OfType(child.Object.GetType());
Assert.IsTrue(ActivatorValue(selector, child.Object));
Assert.True(ActivatorValue(selector, child.Object));
}
[TestMethod]
[Fact]
public void Descendent_Matches_Control_When_It_Is_Descendent_OfType_And_Class()
{
var grandparent = new Mock<TestLogical1>();
@ -60,10 +59,10 @@ namespace Perspex.Styling.UnitTests
var selector = new Selector().OfType(grandparent.Object.GetType()).Class("foo").Descendent().OfType(child.Object.GetType());
Assert.IsTrue(ActivatorValue(selector, child.Object));
Assert.True(ActivatorValue(selector, child.Object));
}
[TestMethod]
[Fact]
public void Descendent_Doesnt_Match_Control_When_It_Is_Descendent_OfType_But_Wrong_Class()
{
var grandparent = new Mock<TestLogical1>();
@ -77,7 +76,7 @@ namespace Perspex.Styling.UnitTests
var selector = new Selector().OfType<TestLogical1>().Class("foo").Descendent().OfType<TestLogical3>();
Assert.IsFalse(ActivatorValue(selector, child.Object));
Assert.False(ActivatorValue(selector, child.Object));
}
private static bool ActivatorValue(Selector selector, IStyleable control)

27
Perspex.Styling.UnitTests/SelectorTests_Id.cs

@ -8,50 +8,49 @@ namespace Perspex.Styling.UnitTests
{
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Styling;
using Xunit;
[TestClass]
public class SelectorTests_Id
{
[TestMethod]
[Fact]
public void Id_Priority_Is_Style()
{
var control = new Control1();
var target = new Selector().Id("foo");
Assert.AreEqual(BindingPriority.Style, target.Priority);
Assert.Equal(BindingPriority.Style, target.Priority);
}
[TestMethod]
[Fact]
public void Id_Matches_Control_With_Correct_Id()
{
var control = new Control1 { Id = "foo" };
var target = new Selector().Id("foo");
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Id_Doesnt_Match_Control_Of_Wrong_Id()
{
var control = new Control1 { Id = "foo" };
var target = new Selector().Id("bar");
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void Id_Doesnt_Match_Control_With_TemplatedParent()
{
var control = new Control1 { TemplatedParent = new Mock<ITemplatedControl>().Object };
var target = new Selector().Id("foo");
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void When_Id_Matches_Control_Other_Selectors_Are_Subscribed()
{
var control = new Control1 { Id = "foo" };
@ -59,10 +58,10 @@ namespace Perspex.Styling.UnitTests
var result = target.GetActivator(control).ToEnumerable().Take(1).ToArray();
Assert.AreEqual(1, control.SubscribeCheckObservable.SubscribedCount);
Assert.Equal(1, control.SubscribeCheckObservable.SubscribedCount);
}
[TestMethod]
[Fact]
public void When_Id_Doesnt_Match_Control_Other_Selectors_Are_Not_Subscribed()
{
var control = new Control1 { Id = "foo" };
@ -70,7 +69,7 @@ namespace Perspex.Styling.UnitTests
var result = target.GetActivator(control).ToEnumerable().Take(1).ToArray();
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
Assert.Equal(0, control.SubscribeCheckObservable.SubscribedCount);
}
private static bool ActivatorValue(Selector selector, IStyleable control)

11
Perspex.Styling.UnitTests/SelectorTests_Multiple.cs

@ -9,13 +9,12 @@ namespace Perspex.Styling.UnitTests
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Styling;
////[TestClass]
////[TestFixture]
////public class SelectorTests_Multiple
////{
//// [TestMethod]
//// [Fact]
//// public void Template_Child_Of_Control_With_Two_Classes()
//// {
//// var template = new ControlTemplate(parent =>
@ -44,11 +43,11 @@ namespace Perspex.Styling.UnitTests
//// activator.Subscribe(x => values.Add(x));
//// CollectionAssert.AreEqual(new[] { false }, values);
//// Assert.Equal(new[] { false }, values);
//// control.Classes.Add("foo", "bar");
//// CollectionAssert.AreEqual(new[] { false, true }, values);
//// Assert.Equal(new[] { false, true }, values);
//// control.Classes.Remove("foo");
//// CollectionAssert.AreEqual(new[] { false, true, false }, values);
//// Assert.Equal(new[] { false, true, false }, values);
//// }
////}
}

27
Perspex.Styling.UnitTests/SelectorTests_OfType.cs

@ -8,50 +8,49 @@ namespace Perspex.Styling.UnitTests
{
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Styling;
using Xunit;
[TestClass]
public class SelectorTests_OfType
{
[TestMethod]
[Fact]
public void OfType_Priority_Is_Style()
{
var control = new Control1();
var target = new Selector().OfType<Control1>();
Assert.AreEqual(BindingPriority.Style, target.Priority);
Assert.Equal(BindingPriority.Style, target.Priority);
}
[TestMethod]
[Fact]
public void OfType_Matches_Control_Of_Correct_Type()
{
var control = new Control1();
var target = new Selector().OfType<Control1>();
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void OfType_Doesnt_Match_Control_Of_Wrong_Type()
{
var control = new Control2();
var target = new Selector().OfType<Control1>();
Assert.IsFalse(ActivatorValue(target, control));
Assert.False(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void OfType_Matches_Control_With_TemplatedParent()
{
var control = new Control1 { TemplatedParent = new Mock<ITemplatedControl>().Object };
var target = new Selector().OfType<Control1>();
Assert.IsTrue(ActivatorValue(target, control));
Assert.True(ActivatorValue(target, control));
}
[TestMethod]
[Fact]
public void When_OfType_Matches_Control_Other_Selectors_Are_Subscribed()
{
var control = new Control1();
@ -59,10 +58,10 @@ namespace Perspex.Styling.UnitTests
var result = target.GetActivator(control).ToEnumerable().Take(1).ToArray();
Assert.AreEqual(1, control.SubscribeCheckObservable.SubscribedCount);
Assert.Equal(1, control.SubscribeCheckObservable.SubscribedCount);
}
[TestMethod]
[Fact]
public void When_OfType_Doesnt_Match_Control_Other_Selectors_Are_Not_Subscribed()
{
var control = new Control1();
@ -70,7 +69,7 @@ namespace Perspex.Styling.UnitTests
var result = target.GetActivator(control).ToEnumerable().Take(1).ToArray();
Assert.AreEqual(0, control.SubscribeCheckObservable.SubscribedCount);
Assert.Equal(0, control.SubscribeCheckObservable.SubscribedCount);
}
private static bool ActivatorValue(Selector selector, IStyleable control)

23
Perspex.Styling.UnitTests/SelectorTests_Template.cs

@ -8,14 +8,13 @@ namespace Perspex.Styling.UnitTests
{
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Perspex.Styling;
////[TestClass]
////[TestFixture]
////public class SelectorTests_Template
////{
//// [TestMethod]
//// [Fact]
//// public void Control_In_Template_Is_Matched_With_Template_Selector()
//// {
//// var templatedControl = new Mock<ITemplatedControl>();
@ -26,10 +25,10 @@ namespace Perspex.Styling.UnitTests
//// var selector = new Selector().Template().OfType<Border>();
//// Assert.IsTrue(ActivatorValue(selector, border));
//// Assert.True(ActivatorValue(selector, border));
//// }
//// [TestMethod]
//// [Fact]
//// public void Nested_Control_In_Template_Is_Matched_With_Template_Selector()
//// {
//// var templatedControl = new Mock<ITemplatedControl>();
@ -40,10 +39,10 @@ namespace Perspex.Styling.UnitTests
//// var selector = new Selector().Template().OfType<TextBlock>();
//// Assert.IsTrue(ActivatorValue(selector, textBlock));
//// Assert.True(ActivatorValue(selector, textBlock));
//// }
//// [TestMethod]
//// [Fact]
//// public void Control_In_Template_Is_Matched_With_TypeOf_TemplatedControl()
//// {
//// var templatedControl = new Mock<TestTemplatedControl>();
@ -53,10 +52,10 @@ namespace Perspex.Styling.UnitTests
//// var selector = new Selector().OfType(templatedControl.Object.GetType()).Template().OfType<Border>();
//// Assert.IsTrue(ActivatorValue(selector,border));
//// Assert.True(ActivatorValue(selector,border));
//// }
//// [TestMethod]
//// [Fact]
//// public void Control_In_Template_Is_Matched_With_Correct_TypeOf_And_Class_Of_TemplatedControl()
//// {
//// var templatedControl = new Mock<TestTemplatedControl>();
@ -67,10 +66,10 @@ namespace Perspex.Styling.UnitTests
//// var selector = new Selector().OfType(templatedControl.Object.GetType()).Class("foo").Template().OfType<Border>();
//// Assert.IsTrue(ActivatorValue(selector, border));
//// Assert.True(ActivatorValue(selector, border));
//// }
//// [TestMethod]
//// [Fact]
//// public void Control_In_Template_Is_Not_Matched_With_Correct_TypeOf_And_Wrong_Class_Of_TemplatedControl()
//// {
//// var templatedControl = new Mock<TestTemplatedControl>();
@ -81,7 +80,7 @@ namespace Perspex.Styling.UnitTests
//// var selector = new Selector().OfType(templatedControl.Object.GetType()).Class("foo").Template().OfType<Border>();
//// Assert.IsFalse(ActivatorValue(selector, border));
//// Assert.False(ActivatorValue(selector, border));
//// }
//// private static bool ActivatorValue(Selector selector, IStyleable control)

117
Perspex.Styling.UnitTests/StyleActivatorTests.cs

@ -1,20 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Perspex.Styling.UnitTests
namespace Perspex.Styling.UnitTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Styling;
using Xunit;
[TestClass]
public class StyleActivatorTests
{
[TestMethod]
[Fact]
public void Activator_And_Should_Follow_Single_Input()
{
var inputs = new[] { new TestSubject<bool>(false) };
@ -22,18 +15,18 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[0].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
Assert.AreEqual(1, inputs[0].SubscriberCount);
Assert.Equal(1, inputs[0].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_And_Should_AND_Multiple_Inputs()
{
var inputs = new[]
@ -46,19 +39,19 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
inputs[1].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[0].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
Assert.AreEqual(1, inputs[0].SubscriberCount);
Assert.AreEqual(1, inputs[1].SubscriberCount);
Assert.AreEqual(1, inputs[2].SubscriberCount);
Assert.Equal(1, inputs[0].SubscriberCount);
Assert.Equal(1, inputs[1].SubscriberCount);
Assert.Equal(1, inputs[2].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_And_Should_Unsubscribe_All_When_Input_Completes_On_False()
{
var inputs = new[]
@ -71,20 +64,20 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
inputs[1].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[0].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnCompleted();
Assert.AreEqual(0, inputs[0].SubscriberCount);
Assert.AreEqual(0, inputs[1].SubscriberCount);
Assert.AreEqual(0, inputs[2].SubscriberCount);
Assert.Equal(0, inputs[0].SubscriberCount);
Assert.Equal(0, inputs[1].SubscriberCount);
Assert.Equal(0, inputs[2].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_And_Should_Not_Unsubscribe_All_When_Input_Completes_On_True()
{
var inputs = new[]
@ -97,16 +90,16 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
inputs[0].OnCompleted();
Assert.AreEqual(1, inputs[0].SubscriberCount);
Assert.AreEqual(1, inputs[1].SubscriberCount);
Assert.AreEqual(1, inputs[2].SubscriberCount);
Assert.Equal(1, inputs[0].SubscriberCount);
Assert.Equal(1, inputs[1].SubscriberCount);
Assert.Equal(1, inputs[2].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_Or_Should_Follow_Single_Input()
{
var inputs = new[] { new TestSubject<bool>(false) };
@ -114,18 +107,18 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[0].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
Assert.AreEqual(1, inputs[0].SubscriberCount);
Assert.Equal(1, inputs[0].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_Or_Should_OR_Multiple_Inputs()
{
var inputs = new[]
@ -138,18 +131,18 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[2].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
Assert.AreEqual(1, inputs[0].SubscriberCount);
Assert.AreEqual(1, inputs[1].SubscriberCount);
Assert.AreEqual(1, inputs[2].SubscriberCount);
Assert.Equal(1, inputs[0].SubscriberCount);
Assert.Equal(1, inputs[1].SubscriberCount);
Assert.Equal(1, inputs[2].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_Or_Should_Unsubscribe_All_When_Input_Completes_On_True()
{
var inputs = new[]
@ -162,19 +155,19 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[2].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[0].OnNext(true);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[0].OnCompleted();
Assert.AreEqual(0, inputs[0].SubscriberCount);
Assert.AreEqual(0, inputs[1].SubscriberCount);
Assert.AreEqual(0, inputs[2].SubscriberCount);
Assert.Equal(0, inputs[0].SubscriberCount);
Assert.Equal(0, inputs[1].SubscriberCount);
Assert.Equal(0, inputs[2].SubscriberCount);
}
[TestMethod]
[Fact]
public void Activator_Or_Should_Not_Unsubscribe_All_When_Input_Completes_On_False()
{
var inputs = new[]
@ -187,17 +180,17 @@ namespace Perspex.Styling.UnitTests
var result = new TestObserver<bool>();
target.Subscribe(result);
Assert.IsTrue(result.GetValue());
Assert.True(result.GetValue());
inputs[2].OnNext(false);
Assert.IsFalse(result.GetValue());
Assert.False(result.GetValue());
inputs[2].OnCompleted();
Assert.AreEqual(1, inputs[0].SubscriberCount);
Assert.AreEqual(1, inputs[1].SubscriberCount);
Assert.AreEqual(1, inputs[2].SubscriberCount);
Assert.Equal(1, inputs[0].SubscriberCount);
Assert.Equal(1, inputs[1].SubscriberCount);
Assert.Equal(1, inputs[2].SubscriberCount);
}
[TestMethod]
[Fact]
public void Completed_Activator_Should_Signal_OnCompleted()
{
var inputs = new[]
@ -210,7 +203,7 @@ namespace Perspex.Styling.UnitTests
target.Subscribe(_ => { }, () => completed = true);
Assert.IsTrue(completed);
Assert.True(completed);
}
}
}

23
Perspex.Styling.UnitTests/StyleTests.cs

@ -8,13 +8,12 @@ namespace Perspex.Styling.UnitTests
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Styling;
////[TestClass]
////[TestFixture]
////public class StyleTests
////{
//// [TestMethod]
//// [Fact]
//// public void Style_With_Only_Type_Selector_Should_Update_Value()
//// {
//// Style style = new Style(x => x.OfType<Class1>())
@ -29,10 +28,10 @@ namespace Perspex.Styling.UnitTests
//// style.Attach(target);
//// Assert.AreEqual("Foo", target.Foo);
//// Assert.Equal("Foo", target.Foo);
//// }
//// [TestMethod]
//// [Fact]
//// public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
//// {
//// Style style = new Style(x => x.OfType<Class1>().Class("foo"))
@ -46,14 +45,14 @@ namespace Perspex.Styling.UnitTests
//// var target = new Class1();
//// style.Attach(target);
//// Assert.AreEqual("foodefault", target.Foo);
//// Assert.Equal("foodefault", target.Foo);
//// target.Classes.Add("foo");
//// Assert.AreEqual("Foo", target.Foo);
//// Assert.Equal("Foo", target.Foo);
//// target.Classes.Remove("foo");
//// Assert.AreEqual("foodefault", target.Foo);
//// Assert.Equal("foodefault", target.Foo);
//// }
//// [TestMethod]
//// [Fact]
//// public void LocalValue_Should_Override_Style()
//// {
//// Style style = new Style(x => x.OfType<Class1>())
@ -70,10 +69,10 @@ namespace Perspex.Styling.UnitTests
//// };
//// style.Attach(target);
//// Assert.AreEqual("Original", target.Foo);
//// Assert.Equal("Original", target.Foo);
//// }
//// [TestMethod]
//// [Fact]
//// public void Later_Styles_Should_Override_Earlier()
//// {
//// Styles styles = new Styles
@ -104,7 +103,7 @@ namespace Perspex.Styling.UnitTests
//// target.Classes.Add("foo");
//// target.Classes.Remove("foo");
//// CollectionAssert.AreEqual(new[] { "foodefault", "Foo", "Bar", "foodefault" }, values);
//// Assert.Equal(new[] { "foodefault", "Foo", "Bar", "foodefault" }, values);
//// }
//// private class Class1 : Control

2
Perspex.Styling.UnitTests/packages.config

@ -6,4 +6,6 @@
<package id="Rx-Linq" version="2.2.5" targetFramework="net45" />
<package id="Rx-Main" version="2.2.5" targetFramework="net45" />
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0-rc1-build1030" targetFramework="net45" />
</packages>

2
Perspex.sln

@ -59,6 +59,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Layout.UnitTests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Animation", "Perspex.Animation\Perspex.Animation.csproj", "{D211E587-D8BC-45B9-95A4-F297C8FA5200}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{596AF748-EAA9-4698-A78C-98724783AFC1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

33
Windows/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs

@ -6,12 +6,11 @@
namespace Perspex.Direct2D1.RenderTests.Controls
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Layout;
using Perspex.Media;
using Xunit;
[TestClass]
public class BorderTests : TestBase
{
public BorderTests()
@ -19,7 +18,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
{
}
[TestMethod]
[Fact]
public void Border_1px_Border()
{
Decorator target = new Decorator
@ -38,7 +37,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_2px_Border()
{
Decorator target = new Decorator
@ -57,7 +56,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Fill()
{
Decorator target = new Decorator
@ -75,7 +74,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Brush_Offsets_Content()
{
Decorator target = new Decorator
@ -98,7 +97,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Padding_Offsets_Content()
{
Decorator target = new Decorator
@ -122,7 +121,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Margin_Offsets_Content()
{
Decorator target = new Decorator
@ -146,7 +145,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Centers_Content_Horizontally()
{
Decorator target = new Decorator
@ -173,7 +172,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Centers_Content_Vertically()
{
Decorator target = new Decorator
@ -200,7 +199,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Stretches_Content_Horizontally()
{
Decorator target = new Decorator
@ -227,7 +226,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Stretches_Content_Vertically()
{
Decorator target = new Decorator
@ -254,7 +253,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Left_Aligns_Content()
{
Decorator target = new Decorator
@ -281,7 +280,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Right_Aligns_Content()
{
Decorator target = new Decorator
@ -308,7 +307,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Top_Aligns_Content()
{
Decorator target = new Decorator
@ -335,7 +334,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Bottom_Aligns_Content()
{
Decorator target = new Decorator
@ -362,7 +361,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Border_Nested_Rotate()
{
Decorator target = new Decorator

11
Windows/Perspex.Direct2D1.RenderTests/Controls/ImageTests.cs

@ -7,12 +7,11 @@
namespace Perspex.Direct2D1.RenderTests.Controls
{
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Media.Imaging;
using Xunit;
[TestClass]
public class ImageTests : TestBase
{
private Bitmap bitmap;
@ -23,7 +22,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.bitmap = new Bitmap(Path.Combine(this.OutputPath, "test.png"));
}
[TestMethod]
[Fact]
public void Image_Stretch_None()
{
Decorator target = new Decorator
@ -46,7 +45,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Image_Stretch_Fill()
{
Decorator target = new Decorator
@ -69,7 +68,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Image_Stretch_Uniform()
{
Decorator target = new Decorator
@ -92,7 +91,7 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.CompareImages();
}
[TestMethod]
[Fact]
public void Image_Stretch_UniformToFill()
{
Decorator target = new Decorator

18
Windows/Perspex.Direct2D1.RenderTests/Perspex.Direct2D1.RenderTests.csproj

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,12 +11,12 @@
<AssemblyName>Perspex.Direct2D1.RenderTests</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>
<NuGetPackageImportStamp>a4c4bf26</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -45,6 +46,9 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="xunit">
<HintPath>..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
@ -52,11 +56,7 @@
<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>
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="Controls\ImageTests.cs" />
@ -129,6 +129,12 @@
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.0.0-rc1-build1030\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- 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">

5
Windows/Perspex.Direct2D1.RenderTests/Shapes/EllipseTests.cs

@ -6,12 +6,11 @@
namespace Perspex.Direct2D1.RenderTests.Shapes
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Controls.Shapes;
using Xunit;
[TestClass]
public class EllipseTests : TestBase
{
public EllipseTests()
@ -19,7 +18,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
{
}
[TestMethod]
[Fact]
public void Circle_1px_Stroke()
{
Decorator target = new Decorator

9
Windows/Perspex.Direct2D1.RenderTests/Shapes/PathTests.cs

@ -6,13 +6,12 @@
namespace Perspex.Direct2D1.RenderTests.Shapes
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Layout;
using Perspex.Media;
using Perspex.Controls.Shapes;
using Xunit;
[TestClass]
public class PathTests : TestBase
{
public PathTests()
@ -20,7 +19,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
{
}
[TestMethod]
[Fact]
public void Path_100px_Triangle_Centered()
{
Decorator target = new Decorator
@ -43,7 +42,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
}
[TestMethod]
[Fact]
public void Path_Tick_Scaled()
{
Decorator target = new Decorator
@ -66,7 +65,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
this.CompareImages();
}
[TestMethod]
[Fact]
public void Path_Expander_With_Border()
{
Decorator target = new Decorator

9
Windows/Perspex.Direct2D1.RenderTests/Shapes/RectangleTests.cs

@ -6,12 +6,11 @@
namespace Perspex.Direct2D1.RenderTests.Shapes
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Controls.Shapes;
using Xunit;
[TestClass]
public class RectangleTests : TestBase
{
public RectangleTests()
@ -19,7 +18,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
{
}
[TestMethod]
[Fact]
public void Rectangle_1px_Stroke()
{
Decorator target = new Decorator
@ -38,7 +37,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
this.CompareImages();
}
[TestMethod]
[Fact]
public void Rectangle_2px_Stroke()
{
Decorator target = new Decorator
@ -57,7 +56,7 @@ namespace Perspex.Direct2D1.RenderTests.Shapes
this.CompareImages();
}
[TestMethod]
[Fact]
public void Rectangle_Stroke_Fill()
{
Decorator target = new Decorator

6
Windows/Perspex.Direct2D1.RenderTests/TestBase.cs

@ -9,9 +9,9 @@ namespace Perspex.Direct2D1.RenderTests
using System.IO;
using System.Runtime.CompilerServices;
using ImageMagick;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Media.Imaging;
using Xunit;
public class TestBase
{
@ -59,11 +59,11 @@ namespace Perspex.Direct2D1.RenderTests
{
if (error.NormalizedMaximumError > 0.15)
{
Assert.Fail("NormalizedMaximumError = " + error.NormalizedMaximumError);
Assert.True(false, "NormalizedMaximumError = " + error.NormalizedMaximumError);
}
else
{
Assert.Inconclusive("Close but no cigar. NormalizedMaximumError = " + error.NormalizedMaximumError);
Assert.True(false, "Close but no cigar. NormalizedMaximumError = " + error.NormalizedMaximumError);
}
}
}

2
Windows/Perspex.Direct2D1.RenderTests/packages.config

@ -2,4 +2,6 @@
<packages>
<package id="Magick.NET-Q16-x86" version="7.0.0.0007" targetFramework="net45" />
<package id="Splat" version="1.5.1" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0-rc1-build1030" targetFramework="net45" />
</packages>
Loading…
Cancel
Save