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

namespace Xamarin.Forms.Xaml.UnitTests
{
	public class MockView : View
	{
		public MockFactory Content { get; set; }
	}

	public class MockFactory
	{
		public string Content { get; set; }
		public MockFactory ()
		{
			Content = "default ctor";
		}

		public MockFactory(string arg0, string arg1)
		{
			Content = "alternate ctor " + arg0 + arg1;
		}

		public MockFactory(string arg0)
		{
			Content = "alternate ctor " + arg0;
		}

		public MockFactory (int arg)
		{
			Content = "int ctor " + arg.ToString ();
		}

		public MockFactory(object [] args)
		{
			Content = string.Join(" ", args);
		}

		public static  MockFactory ParameterlessFactory ()
		{
			return new MockFactory {
				Content = "parameterless factory",
			};
		}

		public static MockFactory Factory (string arg0, int arg1)
		{
			return new MockFactory {
				Content = "factory " + arg0 + arg1,
			};
		}

		public static MockFactory Factory (int arg0, string arg1)
		{
			return new MockFactory {
				Content = "factory " + arg0 + arg1,
			};
		}
	}

	public partial class FactoryMethods : ContentPage
	{
		public FactoryMethods ()
		{
			InitializeComponent ();
		}

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

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

			[TestCase (false)]
			[TestCase (true)]
			public void TestDefaultCtor (bool useCompiledXaml)
			{
				var layout = new FactoryMethods (useCompiledXaml);
				Assert.AreEqual ("default ctor", layout.v0.Content.Content);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void TestStringCtor (bool useCompiledXaml)
			{
				var layout = new FactoryMethods (useCompiledXaml);
				Assert.AreEqual ("alternate ctor foobar", layout.v1.Content.Content);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void TestIntCtor (bool useCompiledXaml)
			{
				var layout = new FactoryMethods (useCompiledXaml);
				Assert.AreEqual ("int ctor 42", layout.v2.Content.Content);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void TestArgumentlessFactoryMethod (bool useCompiledXaml)
			{
				var layout = new FactoryMethods (useCompiledXaml);
				Assert.AreEqual ("parameterless factory", layout.v3.Content.Content);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void TestFactoryMethod (bool useCompiledXaml)
			{
				var layout = new FactoryMethods (useCompiledXaml);
				Assert.AreEqual ("factory foo42", layout.v4.Content.Content);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void TestFactoryMethodParametersOrder (bool useCompiledXaml)
			{
				var layout = new FactoryMethods (useCompiledXaml);
				Assert.AreEqual ("factory 42foo", layout.v5.Content.Content);
			}

			[TestCase(false)]
			[TestCase(true)]
			public void TestCtorWithxStatic(bool useCompiledXaml)
			{
				var layout = new FactoryMethods(useCompiledXaml);
				Assert.AreEqual("alternate ctor Property", layout.v6.Content.Content);
			}

			[TestCase(false)]
			[TestCase(true)]
			public void TestCtorWithxStaticAttribute(bool useCompiledXaml)
			{
				var layout = new FactoryMethods(useCompiledXaml);
				Assert.AreEqual("alternate ctor Property", layout.v7.Content.Content);
			}

			[TestCase(false)]
			[TestCase(true)]
			public void TestCtorWithArrayParameter(bool useCompiledXaml)
			{
				var layout = new FactoryMethods(useCompiledXaml);
				Assert.AreEqual("Foo Bar", layout.v8.Content.Content);
			}
		}
	}
}