summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-23 09:01:22 +0200
committerJason Smith <jason.smith@xamarin.com>2016-09-23 00:01:22 -0700
commita5183bed8d38db411549733934b53380b93773b5 (patch)
tree51953e228a71cb59600c8c5ab001a959ee811a27 /Xamarin.Forms.Xaml.UnitTests
parent1076e735697d393c7b10654f8dc7d9a91c7c13e1 (diff)
downloadxamarin-forms-a5183bed8d38db411549733934b53380b93773b5.tar.gz
xamarin-forms-a5183bed8d38db411549733934b53380b93773b5.tar.bz2
xamarin-forms-a5183bed8d38db411549733934b53380b93773b5.zip
[XamlC] Implement IValueProvider.PropertyType (#345)
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs6
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml18
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs72
3 files changed, 83 insertions, 13 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs b/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs
index 7361235c..a026eda2 100644
--- a/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs
@@ -177,11 +177,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
}
}
- public object TargetProperty {
- get {
- throw new NotImplementedException ();
- }
- }
+ public object TargetProperty { get; } = null;
}
[Test]
diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml
index bf44299b..7f470a4a 100644
--- a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml
@@ -1,9 +1,23 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Xaml.UnitTests.OnPlatform">
+ <ContentPage.Resources>
+ <ResourceDictionary>
+ <OnPlatform x:TypeArguments="FontAttributes" x:Key="fontAttributes">
+ <OnPlatform.iOS>Bold</OnPlatform.iOS>
+ <OnPlatform.Android>Italic</OnPlatform.Android>
+ </OnPlatform>
+ <OnPlatform x:Key="phone" x:TypeArguments="x:Double" iOS="20" Android="20" WinPhone="30"/>
+ <OnPlatform x:Key="tablet" x:TypeArguments="x:Double" iOS="40" Android="40" WinPhone="60"/>
+ <OnIdiom x:Key="fontSize" x:TypeArguments="x:Double"
+ Phone="{StaticResource phone}"
+ Tablet="{StaticResource tablet}"/>
+
+ </ResourceDictionary>
+ </ContentPage.Resources>
<StackLayout>
- <Label x:Name="label0">
+ <Label x:Name="label0" FontAttributes="{StaticResource fontAttributes}" FontSize="{StaticResource fontSize}">
<Label.IsVisible>
<OnPlatform x:TypeArguments="x:Boolean">
<OnPlatform.iOS>true</OnPlatform.iOS>
diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
index 2c2c6482..6d9dad6e 100644
--- a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
@@ -22,6 +22,18 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestFixture]
public class Tests
{
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
[TestCase (false)]
[TestCase (true)]
public void BoolToVisibility (bool useCompiledXaml)
@@ -34,13 +46,61 @@ namespace Xamarin.Forms.Xaml.UnitTests
layout = new OnPlatform (useCompiledXaml);
Assert.AreEqual (false, layout.label0.IsVisible);
}
- }
- public void T ()
- {
- var onplat = new OnPlatform<bool> ();
- var label = new Label ();
- label.IsVisible = onplat;
+ [TestCase(false)]
+ [TestCase(true)]
+ public void DoubleToWidth(bool useCompiledXaml)
+ {
+ Device.OS = TargetPlatform.iOS;
+ var layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual(20, layout.label0.WidthRequest);
+
+ Device.OS = TargetPlatform.Android;
+ layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual(30, layout.label0.WidthRequest);
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void StringToText(bool useCompiledXaml)
+ {
+ Device.OS = TargetPlatform.iOS;
+ var layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual("Foo", layout.label0.Text);
+
+ Device.OS = TargetPlatform.Android;
+ layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual("Bar", layout.label0.Text);
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void OnPlatformAsResource(bool useCompiledXaml)
+ {
+ var layout = new OnPlatform(useCompiledXaml);
+ var onplat = layout.Resources ["fontAttributes"] as OnPlatform<FontAttributes>;
+ Assert.NotNull(onplat);
+ Assert.AreEqual(FontAttributes.Bold, onplat.iOS);
+
+ Assert.AreEqual(FontAttributes.Italic, onplat.Android);
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void OnPlatformAsResourceAreApplied(bool useCompiledXaml)
+ {
+ Device.OS = TargetPlatform.iOS;
+ var layout = new OnPlatform(useCompiledXaml);
+ var onidiom = layout.Resources ["fontSize"] as OnIdiom<double>;
+ Assert.NotNull(onidiom);
+ Assert.That(onidiom.Phone, Is.TypeOf<double>());
+ Assert.AreEqual(20, onidiom.Phone);
+ Assert.AreEqual(FontAttributes.Bold, layout.label0.FontAttributes);
+
+ Device.OS = TargetPlatform.Android;
+ layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual(FontAttributes.Italic, layout.label0.FontAttributes);
+ }
}
}
} \ No newline at end of file