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


namespace Xamarin.Forms.Core.UnitTests
{
	[TestFixture]
	public class TableModelTests : BaseTestFixture
	{
		class TestModel : TableModel
		{
			public override int GetRowCount (int section)
			{
				return 10;
			}

			public override int GetSectionCount ()
			{
				return 1;
			}

			public override object GetItem (int section, int row)
			{
				return "Foo";
			}

			public string ProtectedSectionTitle ()
			{
				return GetSectionTitle (0);
			}
		}

		[Test]
		public void DefaultSectionTitle ()
		{
			Assert.IsNull (new TestModel ().ProtectedSectionTitle ());
		}

		[Test]
		public void DefualtSectionIndexTitles ()
		{
			Assert.IsNull (new TestModel ().GetSectionIndexTitles ());
		}

		[Test]
		public void DefaultHeaderCell ()
		{
			Assert.IsNull (new TestModel ().GetHeaderCell (0));
		}

		[Test]
		public void DefaultCellFromObject ()
		{
			var model = new TestModel ();
			var cell = model.GetCell (0, 5);

			Assert.That (cell, Is.TypeOf<TextCell> ());

			var textCell = (TextCell) cell;
			Assert.AreEqual ("Foo", textCell.Text);
		}

		[Test]
		public void RowLongPressed ()
		{
			var model = new TestModel ();

			var longPressedItem = "";
			model.ItemLongPressed += (sender, arg) => {
				longPressedItem = (string)arg.Data;
			};

			model.RowLongPressed (0, 5);
		}

		[Test]
		public void RowSelectedForObject ()
		{
			var model = new TestModel ();
			string result = null;
			model.ItemSelected += (sender, arg) => result = (string)arg.Data;

			model.RowSelected ("Foobar");
			Assert.AreEqual ("Foobar", result);
		}
	}
}