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
|
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class TableRootUnitTests : BaseTestFixture
{
[Test]
public void Ctor()
{
const string title = "FooBar";
var model = new TableRoot (title);
Assert.AreEqual (title, model.Title);
}
[Test]
public void CtorInvalid()
{
Assert.Throws<ArgumentNullException> (() => new TableRoot (null));
}
[Test]
public void TestGetSections ()
{
var model = new TableRoot ("Name") {
new TableSection ("Section 1") {
new TextCell { Text = "Item 1.1", Detail = "Hint 1"},
new TextCell { Text = "Item 1.2", Detail = "Hint 2"},
new TextCell { Text = "Item 1.3", Detail = "Hint 3"}
},
new TableSection ("Section 2") {
new TextCell { Text = "Item 2.1", Detail = "Hint 1"},
new TextCell { Text = "Item 2.2", Detail = "Hint 2"},
new TextCell { Text = "Item 2.3", Detail = "Hint 3"}
}
};
Assert.AreEqual (2, model.Count);
}
[Test]
public void TestCollectionChanged ()
{
var model = new TableRoot ();
bool changed = false;
model.CollectionChanged += (sender, e) => changed = true;
model.Add (new TableSection ("Foo"));
Assert.True (changed);
changed = false;
model [0].Add (new TextCell { Text = "Foobar" });
// Our tree is not supposed to track up like this
Assert.False (changed);
}
[Test]
public void TestTree ()
{
var model = new TableRoot ("Name") {
new TableSection ("Section 1") {
new TextCell { Text = "Item 1.1", Detail = "Hint 1"},
new TextCell { Text = "Item 1.2", Detail = "Hint 2"},
new TextCell { Text = "Item 1.3", Detail = "Hint 3"}
},
new TableSection {
new TextCell { Text = "Item 2.1", Detail = "Hint 1"},
new TextCell { Text = "Item 2.2", Detail = "Hint 2"},
new TextCell { Text = "Item 2.3", Detail = "Hint 3"}
}
};
Assert.AreEqual ("Item 1.1", (model[0][0] as TextCell).Text);
Assert.AreEqual ("Item 1.2", (model[0][1] as TextCell).Text);
Assert.AreEqual ("Item 1.3", (model[0][2] as TextCell).Text);
Assert.AreEqual ("Item 2.1", (model[1][0] as TextCell).Text);
Assert.AreEqual ("Item 2.2", (model[1][1] as TextCell).Text);
Assert.AreEqual ("Item 2.3", (model[1][2] as TextCell).Text);
}
//[Test]
//public void TestAddFromEnumerable ()
//{;
// TableSection first, second;
// var model = new TableRoot ();
// model.Add (new[] {
// first = new TableSection (),
// second = new TableSection ()
// });
// Assert.AreEqual (first, model[0]);
// Assert.AreEqual (second, model[1]);
//}
}
}
|