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

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 (int arg)
		{
			Content = "int ctor " + arg.ToString ();
		}

		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
		{
			[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);
			}
		}
	}
}