summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/ViewCellTests.cs
blob: 2a8647d48a1d7a008aca8a77e897c81c5b8f6da8 (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
using System;
using NUnit.Framework;


namespace Xamarin.Forms.Core.UnitTests
{
	[TestFixture]
	public class ViewCellTests : BaseTestFixture
	{
		[Test]
		public void SetParentBeforeView ()
		{
			var parent = new View { Platform = new UnitPlatform () };
			var child = new View ();
			var viewCell = new ViewCell ();

			Assert.Null (viewCell.View);
			Assert.DoesNotThrow (() => viewCell.Parent = parent);

			viewCell.View = child;
			Assert.AreSame (parent, viewCell.Parent);
			Assert.AreSame (viewCell, child.Parent);
			Assert.AreSame (parent.Platform, child.Platform);
		}

		[Test]
		//issue 550
		public void SetBindingContextBeforeParent ()
		{
			var parent = new View { 
				Platform = new UnitPlatform (),
				BindingContext = new object (),
			};

			var itemcontext = new object ();
			var cell = new ViewCell { View = new Label ()};
			cell.BindingContext = itemcontext;
			cell.Parent = parent;

			Assert.AreSame (itemcontext, cell.View.BindingContext);
		}

		[Test]
		public void SetBindingContextBeforeView ()
		{
			var context = new object ();
			var view = new View ();
			var cell = new ViewCell ();
			cell.BindingContext = context;
			cell.View = view;
			Assert.AreSame (context, view.BindingContext);
		}

		[Test]
		public void SetViewBeforeBindingContext ()
		{
			var context = new object ();
			var view = new View ();
			var cell = new ViewCell ();
			cell.View = view;
			cell.BindingContext = context;
			Assert.AreSame (context, view.BindingContext);
		}
	}
}