Browse Source

Added some style tests.

pull/4/head
grokys 12 years ago
parent
commit
730c8b4f48
  1. 1
      Perspex.UnitTests/Perspex.UnitTests.csproj
  2. 91
      Perspex.UnitTests/StyleTests.cs
  3. 2
      Perspex/Setter.cs

1
Perspex.UnitTests/Perspex.UnitTests.csproj

@ -65,6 +65,7 @@
<Compile Include="PerspexPropertyTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PerspexObjectTests.cs" />
<Compile Include="StyleTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Perspex\Perspex.csproj">

91
Perspex.UnitTests/StyleTests.cs

@ -0,0 +1,91 @@
// -----------------------------------------------------------------------
// <copyright file="StyleTests.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.UnitTests
{
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
[TestClass]
public class StyleTests
{
[TestMethod]
public void Style_Should_Update_And_Restore_Value()
{
Style style = new Style
{
Selector = x => x.Select<TextBlock>().Class("foo"),
Setters = new[]
{
new Setter
{
Property = TextBlock.TextProperty,
Value = "Foo",
}
},
};
TextBlock textBlock = new TextBlock
{
Text = "Original",
};
style.Attach(textBlock);
Assert.AreEqual("Original", textBlock.Text);
textBlock.Classes.Add("foo");
Assert.AreEqual("Foo", textBlock.Text);
textBlock.Classes.Remove("foo");
Assert.AreEqual("Original", textBlock.Text);
}
[TestMethod]
public void Later_Styles_Should_Override_Earlier()
{
Style style1 = new Style
{
Selector = x => x.Select<TextBlock>().Class("foo"),
Setters = new[]
{
new Setter
{
Property = TextBlock.TextProperty,
Value = "Foo",
}
},
};
Style style2 = new Style
{
Selector = x => x.Select<TextBlock>().Class("foo"),
Setters = new[]
{
new Setter
{
Property = TextBlock.TextProperty,
Value = "Bar",
}
},
};
TextBlock textBlock = new TextBlock
{
Text = "Original",
};
List<string> values = new List<string>();
textBlock.GetObservable(TextBlock.TextProperty).Subscribe(x => values.Add(x));
style1.Attach(textBlock);
style2.Attach(textBlock);
textBlock.Classes.Add("foo");
textBlock.Classes.Remove("foo");
CollectionAssert.AreEqual(new[] { "Original", "Bar", "Original" }, values);
}
}
}

2
Perspex/Setter.cs

@ -63,7 +63,7 @@ namespace Perspex
internal SetterSubject CreateSubject(Control control)
{
object oldValue = control.ExtractBinding(this.Property) ?? control.GetValue(this.Property);
object oldValue = control.GetValue(this.Property);
return new SetterSubject(control, this.Value, oldValue);
}
}

Loading…
Cancel
Save