diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-09-27 20:10:39 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-09-27 11:10:39 -0700 |
commit | 3e0ee965d710768f1c434b469f8c1c8371b7659a (patch) | |
tree | 1c5fe29f542e098ec68f3f0a029df380e07c41e6 /Xamarin.Forms.Xaml.UnitTests | |
parent | 0f7b22f49d767c3ae522641c324e7ef6928719b4 (diff) | |
download | xamarin-forms-3e0ee965d710768f1c434b469f8c1c8371b7659a.tar.gz xamarin-forms-3e0ee965d710768f1c434b469f8c1c8371b7659a.tar.bz2 xamarin-forms-3e0ee965d710768f1c434b469f8c1c8371b7659a.zip |
[Xaml] more primitive types (#385)
* [Xaml] more builtin conversion, and more type primitives
* [XamlC] more builtin conversion, more type primitives
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/SetValue.xaml | 1 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs | 28 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs | 69 |
4 files changed, 86 insertions, 16 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml index da844ed0..75784273 100644 --- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml @@ -83,5 +83,6 @@ <d:IgnorableElement /> </ContentView.Content> </ContentView> + <local:MockViewWithValues x:Name="mockView0" UShort="32" ADecimal="42" /> </StackLayout> </ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs index 2226402c..3343ed7a 100644 --- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs @@ -2,6 +2,7 @@ using System.Linq; using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; namespace Xamarin.Forms.Xaml.UnitTests { @@ -13,6 +14,12 @@ namespace Xamarin.Forms.Xaml.UnitTests } } + public class MockViewWithValues : View + { + public UInt16 UShort { get; set; } + public decimal ADecimal { get; set; } + } + public partial class SetValue : ContentPage { public SetValue () @@ -34,6 +41,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 SetValueToBP (bool useCompiledXaml) @@ -215,6 +234,15 @@ namespace Xamarin.Forms.Xaml.UnitTests var page = new SetValue(useCompiledXaml); Assert.That(page.contentview2.Content, Is.TypeOf<Label>()); } + + [TestCase(false)] + [TestCase(true)] + public void MorePrimitiveTypes(bool useCompiledXaml) + { + var page = new SetValue(useCompiledXaml); + Assert.AreEqual((ushort)32, page.mockView0.UShort); + Assert.AreEqual((decimal)42, page.mockView0.ADecimal); + } } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml index a7a91edc..c9efad23 100644 --- a/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml @@ -37,6 +37,10 @@ <x:TimeSpan x:Key="defaultTimeSpan"/> <x:Uri x:Key="anUri">http://xamarin.com/forms</x:Uri> <x:Uri x:Key="defaultUri"/> + <x:SByte x:Key="aSByte">42</x:SByte> + <x:UInt16 x:Key="aUInt16">43</x:UInt16> + <x:UInt32 x:Key="aUInt32">44</x:UInt32> + <x:UInt64 x:Key="aUInt64">45</x:UInt64> </ResourceDictionary> </ContentPage.Resources> </ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs index 60ead7ca..d7ef6eac 100644 --- a/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using NUnit.Framework; using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; namespace Xamarin.Forms.Xaml.UnitTests { @@ -22,6 +23,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 SupportsXString (bool useCompiledXaml) @@ -144,11 +157,17 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.That (defaultDouble, Is.TypeOf<double> ()); Assert.AreEqual (default(double), (double)defaultDouble, .0001d); - Assert.True (layout.Resources.ContainsKey ("aByte")); + Assert.True(layout.Resources.ContainsKey("aByte")); var aByte = layout.Resources ["aByte"]; - Assert.NotNull (aByte); - Assert.That (aByte, Is.TypeOf<byte> ()); - Assert.AreEqual (54, (byte)aByte); + Assert.NotNull(aByte); + Assert.That(aByte, Is.TypeOf<byte>()); + Assert.AreEqual(54, (byte)aByte); + + Assert.True(layout.Resources.ContainsKey("aSByte")); + var aSByte = layout.Resources ["aSByte"]; + Assert.NotNull(aSByte); + Assert.That(aSByte, Is.TypeOf<sbyte>()); + Assert.AreEqual(42, (sbyte)aSByte); Assert.True (layout.Resources.ContainsKey ("defaultByte")); var defaultByte = layout.Resources ["defaultByte"]; @@ -156,11 +175,17 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.That (defaultByte, Is.TypeOf<byte> ()); Assert.AreEqual (default(byte), (byte)defaultByte); - Assert.True (layout.Resources.ContainsKey ("anInt16")); + Assert.True(layout.Resources.ContainsKey("anInt16")); var anInt16 = layout.Resources ["anInt16"]; - Assert.NotNull (anInt16); - Assert.That (anInt16, Is.TypeOf<short> ()); - Assert.AreEqual (43, (short)anInt16); + Assert.NotNull(anInt16); + Assert.That(anInt16, Is.TypeOf<short>()); + Assert.AreEqual(43, (short)anInt16); + + Assert.True(layout.Resources.ContainsKey("aUInt16")); + var aUInt16 = layout.Resources ["aUInt16"]; + Assert.NotNull(aUInt16); + Assert.That(aUInt16, Is.TypeOf<ushort>()); + Assert.AreEqual(43, (ushort)aUInt16); Assert.True (layout.Resources.ContainsKey ("defaultInt16")); var defaultInt16 = layout.Resources ["defaultInt16"]; @@ -168,11 +193,17 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.That (defaultInt16, Is.TypeOf<short> ()); Assert.AreEqual (default(short), (short)defaultInt16); - Assert.True (layout.Resources.ContainsKey ("anInt32")); + Assert.True(layout.Resources.ContainsKey("anInt32")); var anInt32 = layout.Resources ["anInt32"]; - Assert.NotNull (anInt32); - Assert.That (anInt32, Is.TypeOf<int> ()); - Assert.AreEqual (44, (int)anInt32); + Assert.NotNull(anInt32); + Assert.That(anInt32, Is.TypeOf<int>()); + Assert.AreEqual(44, (int)anInt32); + + Assert.True(layout.Resources.ContainsKey("aUInt32")); + var aUInt32 = layout.Resources ["aUInt32"]; + Assert.NotNull(aUInt32); + Assert.That(aUInt32, Is.TypeOf<uint>()); + Assert.AreEqual(44, (uint)aUInt32); Assert.True (layout.Resources.ContainsKey ("defaultInt32")); var defaultInt32 = layout.Resources ["defaultInt32"]; @@ -180,11 +211,17 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.That (defaultInt32, Is.TypeOf<int> ()); Assert.AreEqual (default(int), (int)defaultInt32); - Assert.True (layout.Resources.ContainsKey ("anInt64")); + Assert.True(layout.Resources.ContainsKey("anInt64")); var anInt64 = layout.Resources ["anInt64"]; - Assert.NotNull (anInt64); - Assert.That (anInt64, Is.TypeOf<long> ()); - Assert.AreEqual (45, (long)anInt64); + Assert.NotNull(anInt64); + Assert.That(anInt64, Is.TypeOf<long>()); + Assert.AreEqual(45, (long)anInt64); + + Assert.True(layout.Resources.ContainsKey("aUInt64")); + var aUInt64 = layout.Resources ["aUInt64"]; + Assert.NotNull(aUInt64); + Assert.That(aUInt64, Is.TypeOf<ulong>()); + Assert.AreEqual(45, (ulong)aUInt64); Assert.True (layout.Resources.ContainsKey ("defaultInt64")); var defaultInt64 = layout.Resources ["defaultInt64"]; |