summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
blob: d8a466e9e9cec17733edca64c3183ce69f0414e0 (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
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;

namespace Xamarin.Forms.Xaml.UnitTests
{
	public class MockxStatic
	{
		public static string MockStaticProperty { get { return "Property"; } }
		public const string MockConstant = "Constant";
		public static string MockField = "Field";
		public string InstanceProperty { get { return "InstanceProperty"; } }
		public static readonly Color BackgroundColor = Color.Fuchsia;
	}

	public enum MockEnum : long
	{
		First,
		Second,
		Third,
	}

	public partial class XStatic : ContentPage
	{
		public XStatic ()
		{
			InitializeComponent ();
		}
		public XStatic (bool useCompiledXaml)
		{
			//this stub will be replaced at compile time
		}

		[TestFixture]
		public class Tests
		{
			//{x:Static Member=prefix:typeName.staticMemberName}
			//{x:Static prefix:typeName.staticMemberName}

			//The code entity that is referenced must be one of the following:
			// - A constant
			// - A static property
			// - A field
			// - An enumeration value
			// All other cases should throw

			[SetUp]
			public void Setup()
			{
				Device.PlatformServices = new MockPlatformServices();
			}

			[TearDown]
			public void TearDown()
			{
				Device.PlatformServices = null;
			}

			[TestCase (false)]
			[TestCase (true)]
			public void StaticProperty (bool useCompiledXaml)
			{
				var layout = new XStatic (useCompiledXaml);
				Assert.AreEqual ("Property", layout.staticproperty.Text);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void MemberOptional (bool useCompiledXaml)
			{
				var layout = new XStatic (useCompiledXaml);
				Assert.AreEqual ("Property", layout.memberisoptional.Text);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void FieldColor (bool useCompiledXaml)
			{
				var layout = new XStatic (useCompiledXaml);
				Assert.AreEqual (Color.Fuchsia, layout.color.TextColor);
			}

			[TestCase(false)]
			[TestCase(true)]
			public void Constant(bool useCompiledXaml)
			{
				var layout = new XStatic(useCompiledXaml);
				Assert.AreEqual("Constant", layout.constant.Text);
			}

			[TestCase(false)]
			[TestCase(true)]
			public void Field(bool useCompiledXaml)
			{
				var layout = new XStatic(useCompiledXaml);
				Assert.AreEqual("Field", layout.field.Text);
			}

			[TestCase(false)]
			[TestCase(true)]
			public void Enum(bool useCompiledXaml)
			{
				var layout = new XStatic(useCompiledXaml);
				Assert.AreEqual(ScrollOrientation.Both, layout.enuM.Orientation);
			}
		}
	}
}