diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-01-12 21:05:41 +0100 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-01-12 12:05:41 -0800 |
commit | b6cb64e4930de9b16309f2d30c6bb0a2177048fd (patch) | |
tree | ae15f36d3e0e60cac6305f90520ad778de9c6ee3 /Xamarin.Forms.Core.UnitTests | |
parent | 3af99cbbe145a876cc9839af0adead83695b5445 (diff) | |
download | xamarin-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.Core.UnitTests')
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/DataTemplateSelectorTests.cs | 14 | ||||
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/ListViewTests.cs | 26 | ||||
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/MockPlatformServices.cs | 2 | ||||
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/ViewUnitTests.cs | 26 |
4 files changed, 42 insertions, 26 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/DataTemplateSelectorTests.cs b/Xamarin.Forms.Core.UnitTests/DataTemplateSelectorTests.cs index 85779956..552f784b 100644 --- a/Xamarin.Forms.Core.UnitTests/DataTemplateSelectorTests.cs +++ b/Xamarin.Forms.Core.UnitTests/DataTemplateSelectorTests.cs @@ -7,6 +7,20 @@ namespace Xamarin.Forms.Core.UnitTests [TestFixture] public class DataTemplateSelectorTests : BaseTestFixture { + [TearDown] + public override void TearDown() + { + base.TearDown(); + Device.PlatformServices = null; + } + + [SetUp] + public override void Setup() + { + base.Setup(); + Device.PlatformServices = new MockPlatformServices(); + } + class TemplateOne : DataTemplate { public TemplateOne () : base (typeof (ViewCell)) diff --git a/Xamarin.Forms.Core.UnitTests/ListViewTests.cs b/Xamarin.Forms.Core.UnitTests/ListViewTests.cs index b373696a..329ba86c 100644 --- a/Xamarin.Forms.Core.UnitTests/ListViewTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ListViewTests.cs @@ -1472,20 +1472,20 @@ namespace Xamarin.Forms.Core.UnitTests Assert.That (cell.Parent, Is.Null); } - [TestCase (TargetPlatform.Android, ListViewCachingStrategy.RecycleElement)] - [TestCase (TargetPlatform.iOS, ListViewCachingStrategy.RecycleElement)] - [TestCase (TargetPlatform.Windows, ListViewCachingStrategy.RetainElement)] - [TestCase (TargetPlatform.Other, ListViewCachingStrategy.RetainElement)] - [TestCase (TargetPlatform.WinPhone, ListViewCachingStrategy.RetainElement)] - public void EnforcesCachingStrategy (TargetPlatform platform, ListViewCachingStrategy expected) - { - var oldOS = Device.OS; + [TestCase (Device.Android, ListViewCachingStrategy.RecycleElement)] + [TestCase (Device.iOS, ListViewCachingStrategy.RecycleElement)] + [TestCase (Device.Windows, ListViewCachingStrategy.RetainElement)] + [TestCase ("Other", ListViewCachingStrategy.RetainElement)] + [TestCase (Device.WinPhone, ListViewCachingStrategy.RetainElement)] + public void EnforcesCachingStrategy (string platform, ListViewCachingStrategy expected) + { + var oldOS = Device.RuntimePlatform; // we need to do this because otherwise we cant set the caching strategy - Device.OS = platform; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = platform; var listView = new ListView (ListViewCachingStrategy.RecycleElement); Assert.AreEqual (expected, listView.CachingStrategy); - Device.OS = oldOS; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = oldOS; } [Test] @@ -1504,9 +1504,9 @@ namespace Xamarin.Forms.Core.UnitTests "Bar" }; - var oldOS = Device.OS; + var oldOS = Device.RuntimePlatform; // we need to do this because otherwise we cant set the caching strategy - Device.OS = TargetPlatform.Android; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android; var bindable = new ListView (ListViewCachingStrategy.RecycleElement); bindable.ItemTemplate = new DataTemplate (typeof (TextCell)) { @@ -1521,7 +1521,7 @@ namespace Xamarin.Forms.Core.UnitTests Assert.False(ReferenceEquals (item1, item2)); - Device.OS = oldOS; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = oldOS; } } } diff --git a/Xamarin.Forms.Core.UnitTests/MockPlatformServices.cs b/Xamarin.Forms.Core.UnitTests/MockPlatformServices.cs index e8519b9e..3d6ddb92 100644 --- a/Xamarin.Forms.Core.UnitTests/MockPlatformServices.cs +++ b/Xamarin.Forms.Core.UnitTests/MockPlatformServices.cs @@ -82,6 +82,8 @@ namespace Xamarin.Forms.Core.UnitTests get { return false; } } + public string RuntimePlatform { get; set; } + public void BeginInvokeOnMainThread (Action action) { if (invokeOnMainThread == null) diff --git a/Xamarin.Forms.Core.UnitTests/ViewUnitTests.cs b/Xamarin.Forms.Core.UnitTests/ViewUnitTests.cs index 9e7f0546..3bea3725 100644 --- a/Xamarin.Forms.Core.UnitTests/ViewUnitTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ViewUnitTests.cs @@ -103,7 +103,7 @@ namespace Xamarin.Forms.Core.UnitTests bool android = false; bool winphone = false; - Device.OS = TargetPlatform.iOS; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS; Device.OnPlatform ( iOS: () => ios = true, @@ -124,7 +124,7 @@ namespace Xamarin.Forms.Core.UnitTests bool android = false; bool winphone = false; - Device.OS = TargetPlatform.Android; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android; Device.OnPlatform ( iOS: () => ios = true, @@ -145,7 +145,7 @@ namespace Xamarin.Forms.Core.UnitTests bool android = false; bool winphone = false; - Device.OS = TargetPlatform.WinPhone; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.WinPhone; Device.OnPlatform ( iOS: () => ios = true, @@ -165,7 +165,7 @@ namespace Xamarin.Forms.Core.UnitTests bool ios = false; bool android = false; - Device.OS = TargetPlatform.Android; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android; Device.OnPlatform ( iOS: () => ios = false, @@ -179,7 +179,7 @@ namespace Xamarin.Forms.Core.UnitTests public void TestOnPlatformNoOpWithoutDefault () { bool any = false; - Device.OS = TargetPlatform.Other; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = "Other"; Device.OnPlatform ( iOS: () => any = true, @@ -194,7 +194,7 @@ namespace Xamarin.Forms.Core.UnitTests { bool defaultExecuted = false; - Device.OS = TargetPlatform.iOS; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS; Device.OnPlatform ( Android: () => { }, @@ -209,7 +209,7 @@ namespace Xamarin.Forms.Core.UnitTests { bool defaultExecuted = false; - Device.OS = TargetPlatform.Android; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android; Device.OnPlatform ( iOS: () => { }, @@ -224,7 +224,7 @@ namespace Xamarin.Forms.Core.UnitTests { bool defaultExecuted = false; - Device.OS = TargetPlatform.WinPhone; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.WinPhone; Device.OnPlatform ( iOS: () => { }, @@ -239,7 +239,7 @@ namespace Xamarin.Forms.Core.UnitTests { bool defaultExecuted = false; - Device.OS = TargetPlatform.Other; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = "Other"; Device.OnPlatform ( iOS: () => { }, @@ -432,16 +432,16 @@ namespace Xamarin.Forms.Core.UnitTests [Test] public void TestOnPlatformGeneric () { - Device.OS = TargetPlatform.WinPhone; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.WinPhone; Assert.AreEqual (3, Device.OnPlatform (1, 2, 3)); - Device.OS = TargetPlatform.iOS; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.iOS; Assert.AreEqual (1, Device.OnPlatform (1, 2, 3)); - Device.OS = TargetPlatform.Android; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = Device.Android; Assert.AreEqual (2, Device.OnPlatform (1, 2, 3)); - Device.OS = TargetPlatform.Other; + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = "Other"; Assert.AreEqual (1, Device.OnPlatform (1, 2, 3)); } |