Browse Source

Reinstated commented out StyleTests.

pull/39/head
Steven Kirk 11 years ago
parent
commit
c06fccefc2
  1. 24
      Tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj
  2. 229
      Tests/Perspex.Styling.UnitTests/StyleTests.cs
  3. 1
      Tests/Perspex.Styling.UnitTests/packages.config

24
Tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj

@ -40,6 +40,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="Splat, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Splat.1.5.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Reactive.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@ -87,10 +91,30 @@
<Compile Include="TestTemplatedControl.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Perspex.Animation\Perspex.Animation.csproj">
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project>
<Name>Perspex.Animation</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Base\Perspex.Base.csproj">
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project>
<Name>Perspex.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Controls\Perspex.Controls.csproj">
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project>
<Name>Perspex.Controls</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Input\Perspex.Input.csproj">
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project>
<Name>Perspex.Input</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Interactivity\Perspex.Interactivity.csproj">
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project>
<Name>Perspex.Interactivity</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.Layout\Perspex.Layout.csproj">
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project>
<Name>Perspex.Layout</Name>
</ProjectReference>
<ProjectReference Include="..\..\Perspex.SceneGraph\Perspex.SceneGraph.csproj">
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project>
<Name>Perspex.SceneGraph</Name>

229
Tests/Perspex.Styling.UnitTests/StyleTests.cs

@ -8,119 +8,120 @@ namespace Perspex.Styling.UnitTests
{
using System;
using System.Collections.Generic;
using Perspex.Controls;
using Perspex.Styling;
////[TestFixture]
////public class StyleTests
////{
//// [Fact]
//// public void Style_With_Only_Type_Selector_Should_Update_Value()
//// {
//// Style style = new Style(x => x.OfType<Class1>())
//// {
//// Setters = new[]
//// {
//// new Setter(Class1.FooProperty, "Foo"),
//// },
//// };
//// var target = new Class1();
//// style.Attach(target);
//// Assert.Equal("Foo", target.Foo);
//// }
//// [Fact]
//// public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
//// {
//// Style style = new Style(x => x.OfType<Class1>().Class("foo"))
//// {
//// Setters = new[]
//// {
//// new Setter(Class1.FooProperty, "Foo"),
//// },
//// };
//// var target = new Class1();
//// style.Attach(target);
//// Assert.Equal("foodefault", target.Foo);
//// target.Classes.Add("foo");
//// Assert.Equal("Foo", target.Foo);
//// target.Classes.Remove("foo");
//// Assert.Equal("foodefault", target.Foo);
//// }
//// [Fact]
//// public void LocalValue_Should_Override_Style()
//// {
//// Style style = new Style(x => x.OfType<Class1>())
//// {
//// Setters = new[]
//// {
//// new Setter(Class1.FooProperty, "Foo"),
//// },
//// };
//// var target = new Class1
//// {
//// Foo = "Original",
//// };
//// style.Attach(target);
//// Assert.Equal("Original", target.Foo);
//// }
//// [Fact]
//// public void Later_Styles_Should_Override_Earlier()
//// {
//// Styles styles = new Styles
//// {
//// new Style(x => x.OfType<Class1>().Class("foo"))
//// {
//// Setters = new[]
//// {
//// new Setter(Class1.FooProperty, "Foo"),
//// },
//// },
//// new Style(x => x.OfType<Class1>().Class("foo"))
//// {
//// Setters = new[]
//// {
//// new Setter(Class1.FooProperty, "Bar"),
//// },
//// }
//// };
//// var target = new Class1();
//// List<string> values = new List<string>();
//// target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
//// styles.Attach(target);
//// target.Classes.Add("foo");
//// target.Classes.Remove("foo");
//// Assert.Equal(new[] { "foodefault", "Foo", "Bar", "foodefault" }, values);
//// }
//// private class Class1 : Control
//// {
//// public static readonly PerspexProperty<string> FooProperty =
//// PerspexProperty.Register<Class1, string>("Foo", "foodefault");
//// public string Foo
//// {
//// get { return this.GetValue(FooProperty); }
//// set { this.SetValue(FooProperty, value); }
//// }
//// protected override Size MeasureOverride(Size availableSize)
//// {
//// throw new NotImplementedException();
//// }
//// }
////}
using Xunit;
public class StyleTests
{
[Fact]
public void Style_With_Only_Type_Selector_Should_Update_Value()
{
Style style = new Style(x => x.OfType<Class1>())
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Foo"),
},
};
var target = new Class1();
style.Attach(target);
Assert.Equal("Foo", target.Foo);
}
[Fact]
public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
{
Style style = new Style(x => x.OfType<Class1>().Class("foo"))
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Foo"),
},
};
var target = new Class1();
style.Attach(target);
Assert.Equal("foodefault", target.Foo);
target.Classes.Add("foo");
Assert.Equal("Foo", target.Foo);
target.Classes.Remove("foo");
Assert.Equal("foodefault", target.Foo);
}
[Fact]
public void LocalValue_Should_Override_Style()
{
Style style = new Style(x => x.OfType<Class1>())
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Foo"),
},
};
var target = new Class1
{
Foo = "Original",
};
style.Attach(target);
Assert.Equal("Original", target.Foo);
}
[Fact]
public void Later_Styles_Should_Override_Earlier()
{
Styles styles = new Styles
{
new Style(x => x.OfType<Class1>().Class("foo"))
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Foo"),
},
},
new Style(x => x.OfType<Class1>().Class("foo"))
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Bar"),
},
}
};
var target = new Class1();
List<string> values = new List<string>();
target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
styles.Attach(target);
target.Classes.Add("foo");
target.Classes.Remove("foo");
Assert.Equal(new[] { "foodefault", "Foo", "Bar", "foodefault" }, values);
}
private class Class1 : Control
{
public static readonly PerspexProperty<string> FooProperty =
PerspexProperty.Register<Class1, string>("Foo", "foodefault");
public string Foo
{
get { return this.GetValue(FooProperty); }
set { this.SetValue(FooProperty, value); }
}
protected override Size MeasureOverride(Size availableSize)
{
throw new NotImplementedException();
}
}
}
}

1
Tests/Perspex.Styling.UnitTests/packages.config

@ -6,6 +6,7 @@
<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="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