summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/TableViewUnitTests.cs
blob: 7e5ca496e9379cb994a5cd23c7c2084a06cc5ab8 (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
using System.Linq;

using NUnit.Framework;

namespace Xamarin.Forms.Core.UnitTests
{
	[TestFixture]
	public class TableViewUnitTests : BaseTestFixture
	{
		[Test]
		public void TestConstructor ()
		{
			var table = new TableView ();

			Assert.False (table.Root.Any ());
			Assert.AreEqual (LayoutOptions.FillAndExpand, table.HorizontalOptions);
			Assert.AreEqual (LayoutOptions.FillAndExpand, table.VerticalOptions);
		}

		[Test]
		public void TestModelChanged ()
		{
			var table = new TableView ();

			bool changed = false;

			table.ModelChanged += (sender, e) => changed = true;

			table.Root = new TableRoot ("NewRoot");

			Assert.True (changed);
		}

		[Test]
		public void BindingsContextChainsToModel ()
		{
			const string context = "Context";
			var table = new TableView { BindingContext = context, Root = new TableRoot() };

			Assert.AreEqual (context, table.Root.BindingContext);

			// reverse assignment order
			table = new TableView { Root = new TableRoot(), BindingContext = context};
			Assert.AreEqual (context, table.Root.BindingContext);
		}

		[Test]
		public void ParentsViewCells ()
		{
			ViewCell viewCell = new ViewCell { View = new Label () };
			var table = new TableView {
				Platform = new UnitPlatform (),
				Root = new TableRoot {
					new TableSection {
						viewCell
					}
				}
			};

			Assert.AreEqual (table, viewCell.Parent);
			Assert.AreEqual (viewCell, viewCell.View.Parent);
			Assert.AreEqual (table.Platform, viewCell.View.Platform);
		}

		[Test]
		public void ParentsAddedViewCells ()
		{
			var viewCell = new ViewCell { View = new Label () };
			var section = new TableSection (); 
			var table = new TableView {
				Platform = new UnitPlatform (),
				Root = new TableRoot {
					section
				}
			};

			section.Add (viewCell);

			Assert.AreEqual (table, viewCell.Parent);
			Assert.AreEqual (viewCell, viewCell.View.Parent);
			Assert.AreEqual (table.Platform, viewCell.View.Platform);
		}
	}	
}