summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs
blob: 60ead7ca3689910211615dbcfd5bd764a18e88a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using System;
using System.Collections.Generic;

using NUnit.Framework;

using Xamarin.Forms;

namespace Xamarin.Forms.Xaml.UnitTests
{	
	public partial class X2009Primitives : ContentPage
	{	
		public X2009Primitives ()
		{
			InitializeComponent ();
		}

		public X2009Primitives (bool useCompiledXaml)
		{
			//this stub will be replaced at compile time
		}

		[TestFixture]
		public class Tests
		{
			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXString (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);
				Assert.True (layout.Resources.ContainsKey ("aString"));
				Assert.AreEqual ("foobar", layout.Resources ["aString"]);

				Assert.True (layout.Resources.ContainsKey ("defaultString"));
				Assert.AreEqual (String.Empty, layout.Resources ["defaultString"]);

			}

			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXObject (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);
				Assert.True (layout.Resources.ContainsKey ("syncHandle"));
				var value = layout.Resources ["syncHandle"];
				Assert.NotNull (value);
				Assert.That (value, Is.TypeOf<object> ());
			}

			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXBoolean (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);

				Assert.True (layout.Resources.ContainsKey ("falsebool")); 
				var falsebool = layout.Resources ["falsebool"];
				Assert.NotNull (falsebool);
				Assert.That (falsebool, Is.TypeOf<bool> ());
				Assert.AreEqual (false, (bool)falsebool);

				Assert.True (layout.Resources.ContainsKey ("truebool")); 
				var truebool = layout.Resources ["truebool"];
				Assert.NotNull (truebool);
				Assert.That (truebool, Is.TypeOf<bool> ());
				Assert.AreEqual (true, (bool)truebool);

				Assert.True (layout.Resources.ContainsKey ("defaultbool")); 
				var defaultbool = layout.Resources ["defaultbool"];
				Assert.NotNull (defaultbool);
				Assert.That (defaultbool, Is.TypeOf<bool> ());
				Assert.AreEqual (default(bool), (bool)defaultbool);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXChar (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);

				Assert.True (layout.Resources.ContainsKey ("singleChar")); 
				var singleChar = layout.Resources ["singleChar"];
				Assert.NotNull (singleChar);
				Assert.That (singleChar, Is.TypeOf<char> ());
				Assert.AreEqual ('f', (char)singleChar);

				Assert.True (layout.Resources.ContainsKey ("multipleChar")); 
				var multipleChar = layout.Resources ["multipleChar"];
				Assert.NotNull (multipleChar);
				Assert.That (multipleChar, Is.TypeOf<char> ());
				Assert.AreEqual (default(char), (char)multipleChar);

				Assert.True (layout.Resources.ContainsKey ("defaultChar")); 
				var defaultChar = layout.Resources ["defaultChar"];
				Assert.NotNull (defaultChar);
				Assert.That (defaultChar, Is.TypeOf<char> ());
				Assert.AreEqual (default(char), (char)defaultChar);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXNumbers (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);

				Assert.True (layout.Resources.ContainsKey ("aDecimal")); 
				var aDecimal = layout.Resources ["aDecimal"];
				Assert.NotNull (aDecimal);
				Assert.That (aDecimal, Is.TypeOf<decimal> ());
				Assert.AreEqual (1000, (decimal)aDecimal);

				Assert.True (layout.Resources.ContainsKey ("defaultDecimal")); 
				var defaultDecimal = layout.Resources ["defaultDecimal"];
				Assert.NotNull (defaultDecimal);
				Assert.That (defaultDecimal, Is.TypeOf<decimal> ());
				Assert.AreEqual (default(decimal), (decimal)defaultDecimal);

				Assert.True (layout.Resources.ContainsKey ("aSingle")); 
				var aSingle = layout.Resources ["aSingle"];
				Assert.NotNull (aSingle);
				Assert.That (aSingle, Is.TypeOf<float> ());
				Assert.AreEqual (42.2f, (float)aSingle, .0001f);

				Assert.True (layout.Resources.ContainsKey ("defaultSingle")); 
				var defaultSingle = layout.Resources ["defaultSingle"];
				Assert.NotNull (defaultSingle);
				Assert.That (defaultSingle, Is.TypeOf<Single> ());
				Assert.AreEqual (default(float), (float)defaultSingle, .0001f);

				Assert.True (layout.Resources.ContainsKey ("aDouble")); 
				var aDouble = layout.Resources ["aDouble"];
				Assert.NotNull (aDouble);
				Assert.That (aDouble, Is.TypeOf<double> ());
				Assert.AreEqual (42.3d, (double)aDouble, .0001d);

				Assert.True (layout.Resources.ContainsKey ("aNegativeDouble")); 
				var aNegativeDouble = layout.Resources ["aNegativeDouble"];
				Assert.NotNull (aNegativeDouble);
				Assert.That (aNegativeDouble, Is.TypeOf<double> ());
				Assert.AreEqual (-42.3d, (double)aNegativeDouble, .0001d);

				Assert.True (layout.Resources.ContainsKey ("defaultDouble")); 
				var defaultDouble = layout.Resources ["defaultDouble"];
				Assert.NotNull (defaultDouble);
				Assert.That (defaultDouble, Is.TypeOf<double> ());
				Assert.AreEqual (default(double), (double)defaultDouble, .0001d);

				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.True (layout.Resources.ContainsKey ("defaultByte")); 
				var defaultByte = layout.Resources ["defaultByte"];
				Assert.NotNull (defaultByte);
				Assert.That (defaultByte, Is.TypeOf<byte> ());
				Assert.AreEqual (default(byte), (byte)defaultByte);

				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.True (layout.Resources.ContainsKey ("defaultInt16")); 
				var defaultInt16 = layout.Resources ["defaultInt16"];
				Assert.NotNull (defaultInt16);
				Assert.That (defaultInt16, Is.TypeOf<short> ());
				Assert.AreEqual (default(short), (short)defaultInt16);

				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.True (layout.Resources.ContainsKey ("defaultInt32")); 
				var defaultInt32 = layout.Resources ["defaultInt32"];
				Assert.NotNull (defaultInt32);
				Assert.That (defaultInt32, Is.TypeOf<int> ());
				Assert.AreEqual (default(int), (int)defaultInt32);

				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.True (layout.Resources.ContainsKey ("defaultInt64")); 
				var defaultInt64 = layout.Resources ["defaultInt64"];
				Assert.NotNull (defaultInt64);
				Assert.That (defaultInt64, Is.TypeOf<long> ());
				Assert.AreEqual (default(long), (long)defaultInt64);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXTimeSpan (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);

				Assert.True (layout.Resources.ContainsKey ("aTimeSpan")); 
				var aTimeSpan = layout.Resources ["aTimeSpan"];
				Assert.NotNull (aTimeSpan);
				Assert.That (aTimeSpan, Is.TypeOf<TimeSpan> ());
				Assert.AreEqual (new TimeSpan (6, 12, 14, 45, 344).Add (TimeSpan.FromTicks (8000)), (TimeSpan)aTimeSpan);

				Assert.True (layout.Resources.ContainsKey ("defaultTimeSpan")); 
				var defaultTimeSpan = layout.Resources ["defaultTimeSpan"];
				Assert.NotNull (defaultTimeSpan);
				Assert.That (defaultTimeSpan, Is.TypeOf<TimeSpan> ());
				Assert.AreEqual (default(TimeSpan), (TimeSpan)defaultTimeSpan);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void SupportsXUri (bool useCompiledXaml)
			{
				var layout = new X2009Primitives (useCompiledXaml);

				Assert.True (layout.Resources.ContainsKey ("anUri")); 
				var anUri = layout.Resources ["anUri"];
				Assert.NotNull (anUri);
				Assert.That (anUri, Is.TypeOf<Uri> ());
				Assert.AreEqual (new Uri ("http://xamarin.com/forms"), (Uri)anUri);

				Assert.True (layout.Resources.ContainsKey ("defaultUri")); 
				var defaultUri = layout.Resources ["defaultUri"];
				Assert.Null (defaultUri);
			}
		}
	}
}