summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs117
1 files changed, 117 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs
new file mode 100644
index 00000000..7041ff77
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs
@@ -0,0 +1,117 @@
+using System.Linq;
+
+using NUnit.Framework;
+
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml.UnitTests;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class StyleTests : ContentPage
+ {
+ public StyleTests ()
+ {
+ InitializeComponent ();
+ }
+
+ public StyleTests (bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [SetUp]
+ public void SetUp ()
+ {
+ Device.PlatformServices = new MockPlatformServices ();
+ Application.Current = new MockApplication ();
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void TestStyle (bool useCompiledXaml)
+ {
+ var layout = new StyleTests (useCompiledXaml);
+ Assert.That (layout.style0, Is.InstanceOf<Style> ());
+ Assert.AreSame (layout.style0, layout.label0.Style);
+ Assert.AreEqual ("FooBar", layout.label0.Text);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void TestConversionOnSetters (bool useCompiledXaml)
+ {
+ var layout = new StyleTests (useCompiledXaml);
+ Style style = layout.style1;
+ Setter setter;
+
+ //Test built-in conversions
+ setter = style.Setters.Single (s => s.Property == HeightProperty);
+ Assert.That (setter.Value, Is.TypeOf<double> ());
+ Assert.AreEqual (42d, (double)setter.Value);
+
+ //Test TypeConverters
+ setter = style.Setters.Single (s => s.Property == BackgroundColorProperty);
+ Assert.That (setter.Value, Is.TypeOf<Color> ());
+ Assert.AreEqual (Color.Pink, (Color)setter.Value);
+
+ //Test implicit cast operator
+ setter = style.Setters.Single (s => s.Property == Image.SourceProperty);
+ Assert.That (setter.Value, Is.TypeOf<FileImageSource> ());
+ Assert.AreEqual ("foo.png", ((FileImageSource)setter.Value).File);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void ImplicitStyleAreApplied (bool useCompiledXaml)
+ {
+ var layout = new StyleTests (useCompiledXaml);
+ Assert.AreEqual (Color.Red, layout.label1.TextColor);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void PropertyDoesNotNeedTypes (bool useCompiledXaml)
+ {
+ var layout = new StyleTests (useCompiledXaml);
+ Style style2 = layout.style2;
+ var s0 = style2.Setters [0];
+ var s1 = style2.Setters [1];
+ Assert.AreEqual (Label.TextProperty, s0.Property);
+ Assert.AreEqual (BackgroundColorProperty, s1.Property);
+ Assert.AreEqual (Color.Red, s1.Value);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ //issue #2406
+ public void StylesDerivedFromDynamicStylesThroughStaticResource (bool useCompiledXaml)
+ {
+ var layout = new StyleTests (useCompiledXaml);
+ Application.Current.MainPage = layout;
+
+ var label = layout.labelWithStyleDerivedFromDynamic_StaticResource;
+
+ Assert.AreEqual (50, label.FontSize);
+ Assert.AreEqual (Color.Red, label.TextColor);
+ }
+
+ [TestCase (false)]
+ [TestCase (true)]
+ //issue #2406
+ public void StylesDerivedFromDynamicStylesThroughDynamicResource (bool useCompiledXaml)
+ {
+ var layout = new StyleTests (useCompiledXaml);
+ Application.Current.MainPage = layout;
+
+ var label = layout.labelWithStyleDerivedFromDynamic_DynamicResource;
+
+ Assert.AreEqual (50, label.FontSize);
+ Assert.AreEqual (Color.Red, label.TextColor);
+ }
+ }
+ }
+} \ No newline at end of file