diff --git a/Tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj b/Tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj index 954fa4725c..75cfa71f6b 100644 --- a/Tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj +++ b/Tests/Perspex.Styling.UnitTests/Perspex.Styling.UnitTests.csproj @@ -40,6 +40,10 @@ False ..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll + + False + ..\..\packages\Splat.1.5.1\lib\Net45\Splat.dll + False @@ -87,10 +91,30 @@ + + {d211e587-d8bc-45b9-95a4-f297c8fa5200} + Perspex.Animation + {b09b78d8-9b26-48b0-9149-d64a2f120f3f} Perspex.Base + + {d2221c82-4a25-4583-9b43-d791e3f6820c} + Perspex.Controls + + + {62024b2d-53eb-4638-b26b-85eeaa54866e} + Perspex.Input + + + {6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b} + Perspex.Interactivity + + + {42472427-4774-4c81-8aff-9f27b8e31721} + Perspex.Layout + {eb582467-6abb-43a1-b052-e981ba910e3a} Perspex.SceneGraph diff --git a/Tests/Perspex.Styling.UnitTests/StyleTests.cs b/Tests/Perspex.Styling.UnitTests/StyleTests.cs index af599d7dd0..ad67cefaba 100644 --- a/Tests/Perspex.Styling.UnitTests/StyleTests.cs +++ b/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()) - //// { - //// 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().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()) - //// { - //// 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().Class("foo")) - //// { - //// Setters = new[] - //// { - //// new Setter(Class1.FooProperty, "Foo"), - //// }, - //// }, - - //// new Style(x => x.OfType().Class("foo")) - //// { - //// Setters = new[] - //// { - //// new Setter(Class1.FooProperty, "Bar"), - //// }, - //// } - //// }; - - //// var target = new Class1(); - - //// List values = new List(); - //// 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 FooProperty = - //// PerspexProperty.Register("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()) + { + 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().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()) + { + 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().Class("foo")) + { + Setters = new[] + { + new Setter(Class1.FooProperty, "Foo"), + }, + }, + + new Style(x => x.OfType().Class("foo")) + { + Setters = new[] + { + new Setter(Class1.FooProperty, "Bar"), + }, + } + }; + + var target = new Class1(); + + List values = new List(); + 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 FooProperty = + PerspexProperty.Register("Foo", "foodefault"); + + public string Foo + { + get { return this.GetValue(FooProperty); } + set { this.SetValue(FooProperty, value); } + } + + protected override Size MeasureOverride(Size availableSize) + { + throw new NotImplementedException(); + } + } + } } diff --git a/Tests/Perspex.Styling.UnitTests/packages.config b/Tests/Perspex.Styling.UnitTests/packages.config index fa44aa3f2d..58efc28c01 100644 --- a/Tests/Perspex.Styling.UnitTests/packages.config +++ b/Tests/Perspex.Styling.UnitTests/packages.config @@ -6,6 +6,7 @@ + \ No newline at end of file