summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-01-12 21:05:41 +0100
committerJason Smith <jason.smith@xamarin.com>2017-01-12 12:05:41 -0800
commitb6cb64e4930de9b16309f2d30c6bb0a2177048fd (patch)
treeae15f36d3e0e60cac6305f90520ad778de9c6ee3 /Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
parent3af99cbbe145a876cc9839af0adead83695b5445 (diff)
downloadxamarin-forms-b6cb64e4930de9b16309f2d30c6bb0a2177048fd.tar.gz
xamarin-forms-b6cb64e4930de9b16309f2d30c6bb0a2177048fd.tar.bz2
xamarin-forms-b6cb64e4930de9b16309f2d30c6bb0a2177048fd.zip
[C] new OnPlatform mechanism (#658)
* [C] Obsolete TargetPlatform * [Xaml] support and test the new syntax * blind fix windows platforms
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs39
1 files changed, 30 insertions, 9 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
index d53a51c2..edfb695f 100644
--- a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs
@@ -39,11 +39,11 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestCase (true)]
public void BoolToVisibility (bool useCompiledXaml)
{
- Device.OS = TargetPlatform.iOS;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS;
var layout = new OnPlatform (useCompiledXaml);
Assert.AreEqual (true, layout.label0.IsVisible);
- Device.OS = TargetPlatform.Android;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android;
layout = new OnPlatform (useCompiledXaml);
Assert.AreEqual (false, layout.label0.IsVisible);
}
@@ -52,11 +52,11 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestCase(true)]
public void DoubleToWidth(bool useCompiledXaml)
{
- Device.OS = TargetPlatform.iOS;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS;
var layout = new OnPlatform(useCompiledXaml);
Assert.AreEqual(20, layout.label0.WidthRequest);
- Device.OS = TargetPlatform.Android;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android;
layout = new OnPlatform(useCompiledXaml);
Assert.AreEqual(30, layout.label0.WidthRequest);
}
@@ -65,11 +65,11 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestCase(true)]
public void StringToText(bool useCompiledXaml)
{
- Device.OS = TargetPlatform.iOS;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS;
var layout = new OnPlatform(useCompiledXaml);
Assert.AreEqual("Foo", layout.label0.Text);
- Device.OS = TargetPlatform.Android;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android;
layout = new OnPlatform(useCompiledXaml);
Assert.AreEqual("Bar", layout.label0.Text);
}
@@ -81,16 +81,18 @@ namespace Xamarin.Forms.Xaml.UnitTests
var layout = new OnPlatform(useCompiledXaml);
var onplat = layout.Resources ["fontAttributes"] as OnPlatform<FontAttributes>;
Assert.NotNull(onplat);
+#pragma warning disable 612
Assert.AreEqual(FontAttributes.Bold, onplat.iOS);
-
Assert.AreEqual(FontAttributes.Italic, onplat.Android);
+#pragma warning restore 612
+
}
[TestCase(false)]
[TestCase(true)]
public void OnPlatformAsResourceAreApplied(bool useCompiledXaml)
{
- Device.OS = TargetPlatform.iOS;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS;
var layout = new OnPlatform(useCompiledXaml);
var onidiom = layout.Resources ["fontSize"] as OnIdiom<double>;
Assert.NotNull(onidiom);
@@ -98,10 +100,29 @@ namespace Xamarin.Forms.Xaml.UnitTests
Assert.AreEqual(20, onidiom.Phone);
Assert.AreEqual(FontAttributes.Bold, layout.label0.FontAttributes);
- Device.OS = TargetPlatform.Android;
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android;
layout = new OnPlatform(useCompiledXaml);
Assert.AreEqual(FontAttributes.Italic, layout.label0.FontAttributes);
}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void OnPlatform2Syntax(bool useCompiledXaml)
+ {
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android;
+ var layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual(42, layout.label0.HeightRequest);
+
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS;
+ layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual(21, layout.label0.HeightRequest);
+
+
+ ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = "FooBar";
+ layout = new OnPlatform(useCompiledXaml);
+ Assert.AreEqual(42, layout.label0.HeightRequest);
+
+ }
}
}
} \ No newline at end of file