Browse Source

Styley style.

pull/4/head
grokys 12 years ago
parent
commit
ae79a51d72
  1. 103
      Perspex.UnitTests/StyleTests.cs

103
Perspex.UnitTests/StyleTests.cs

@ -18,80 +18,111 @@ namespace Perspex.UnitTests
[TestMethod] [TestMethod]
public void Style_With_Only_Type_Selector_Should_Update_Value() public void Style_With_Only_Type_Selector_Should_Update_Value()
{ {
Style style = new Style(x => x.Select().OfType<TextBlock>()) Style style = new Style(x => x.Select().OfType<Class1>())
{ {
Setters = new[] Setters = new[]
{ {
new Setter(TextBlock.TextProperty, "Foo"), new Setter(Class1.FooProperty, "Foo"),
}, },
}; };
TextBlock textBlock = new TextBlock var target = new Class1();
{
Text = "Original",
};
style.Attach(textBlock); style.Attach(target);
Assert.AreEqual("Foo", textBlock.Text);
Assert.AreEqual("Foo", target.Foo);
} }
[TestMethod] [TestMethod]
public void Style_With_Class_Selector_Should_Update_And_Restore_Value() public void Style_With_Class_Selector_Should_Update_And_Restore_Value()
{ {
Style style = new Style(x => x.Select().OfType<TextBlock>().Class("foo")) Style style = new Style(x => x.Select().OfType<Class1>().Class("foo"))
{ {
Setters = new[] Setters = new[]
{ {
new Setter(TextBlock.TextProperty, "Foo"), new Setter(Class1.FooProperty, "Foo"),
}, },
}; };
TextBlock textBlock = new TextBlock var target = new Class1();
{
Text = "Original",
};
style.Attach(textBlock); style.Attach(target);
Assert.AreEqual("Original", textBlock.Text); Assert.AreEqual("foodefault", target.Foo);
textBlock.Classes.Add("foo"); target.Classes.Add("foo");
Assert.AreEqual("Foo", textBlock.Text); Assert.AreEqual("Foo", target.Foo);
textBlock.Classes.Remove("foo"); target.Classes.Remove("foo");
Assert.AreEqual("Original", textBlock.Text); Assert.AreEqual("foodefault", target.Foo);
} }
[TestMethod] [TestMethod]
public void Later_Styles_Should_Override_Earlier() public void LocalValue_Should_Override_Style()
{ {
Style style1 = new Style(x => x.Select().OfType<TextBlock>().Class("foo")) Style style = new Style(x => x.Select().OfType<Class1>())
{ {
Setters = new[] Setters = new[]
{ {
new Setter(TextBlock.TextProperty, "Foo"), new Setter(Class1.FooProperty, "Foo"),
}, },
}; };
Style style2 = new Style(x => x.Select().OfType<TextBlock>().Class("foo")) var target = new Class1
{ {
Setters = new[] Foo = "Original",
{
new Setter(TextBlock.TextProperty, "Bar"),
},
}; };
TextBlock textBlock = new TextBlock style.Attach(target);
Assert.AreEqual("Original", target.Foo);
}
[TestMethod]
public void Later_Styles_Should_Override_Earlier()
{
Styles styles = new Styles
{ {
Text = "Original", new Style(x => x.Select().OfType<Class1>().Class("foo"))
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Foo"),
},
},
new Style(x => x.Select().OfType<Class1>().Class("foo"))
{
Setters = new[]
{
new Setter(Class1.FooProperty, "Bar"),
},
}
}; };
var target = new Class1();
List<string> values = new List<string>(); List<string> values = new List<string>();
textBlock.GetObservable(TextBlock.TextProperty).Subscribe(x => values.Add(x)); target.GetObservable(Class1.FooProperty).Subscribe(x => values.Add(x));
style1.Attach(textBlock); styles.Attach(target);
style2.Attach(textBlock); target.Classes.Add("foo");
textBlock.Classes.Add("foo"); target.Classes.Remove("foo");
textBlock.Classes.Remove("foo");
CollectionAssert.AreEqual(new[] { "Original", "Bar", "Original" }, values); CollectionAssert.AreEqual(new[] { "foodefault", "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 MeasureContent(Size availableSize)
{
throw new NotImplementedException();
}
} }
} }
} }

Loading…
Cancel
Save