/
MenuUnitTests.cs
161 lines (128 loc) · 2.94 KB
/
MenuUnitTests.cs
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class MenuUnitTests : BaseTestFixture
{
[SetUp]
public override void Setup()
{
base.Setup();
Device.PlatformServices = new MockPlatformServices();
Application.Current = new MockApplication();
}
[TearDown]
public override void TearDown()
{
Application.Current = null;
}
[Test]
public void SetMenuOnMenuItem()
{
var item = new MenuItem();
var menu = new Menu { Text = "Hello" };
MenuItem.SetMenu(item, menu);
Assert.AreEqual(menu, MenuItem.GetMenu(item));
}
[Test]
public void AddSubMenuOnMenu()
{
var item = new MenuItem();
var menu = new Menu { Text = "Hello" };
var submenu = new Menu { Text = "SubMenu Hello" };
menu.Add(submenu);
MenuItem.SetMenu(item, menu);
Assert.AreEqual(MenuItem.GetMenu(item), menu);
Assert.AreEqual(MenuItem.GetMenu(item)[0], submenu);
Assert.AreEqual(MenuItem.GetMenu(item)[0].Text, submenu.Text);
}
[Test]
public void SetMenuOnApplicationMainMenu()
{
var item = new MenuItem();
var menu = new Menu { Text = "Hello" };
Element.SetMenu(Application.Current, menu);
Assert.GreaterOrEqual(1, Element.GetMenu(Application.Current).Count);
}
[Test]
public void MenuText()
{
string text = "hello";
var menu = new Menu { Text = text };
Assert.AreEqual(text, menu.Text);
}
[Test]
public void MenuInvalidateFiresPropertyChanged()
{
string text = "hello";
int count = 0;
var menu = new Menu { Text = text };
menu.PropertyChanged += (s, e) =>
{
count = count+1;
};
menu.Invalidate();
Assert.AreEqual(1, count);
}
[Test]
public void MenuInvalidateWorksOnAdd()
{
string text = "hello";
int count = 0;
var menu = new Menu { Text = text };
menu.PropertyChanged += (s, e) =>
{
count = count + 1;
};
menu.Add(new Menu());
Assert.AreEqual(1, count);
}
[Test]
public void MenuInvalidateWorksOnClear()
{
string text = "hello";
int count = 0;
var menu = new Menu { Text = text };
menu.PropertyChanged += (s, e) =>
{
count = count + 1;
};
menu.Add(new Menu());
menu.Clear();
Assert.AreEqual(2, count);
}
[Test]
public void MenuInvalidateWorksOnInsertAndRemove()
{
string text = "hello";
int count = 0;
var menu = new Menu { Text = text };
menu.PropertyChanged += (s, e) =>
{
count = count + 1;
};
menu.Insert(0, new Menu());
Assert.AreEqual(1, count);
menu.RemoveAt(0);
Assert.AreEqual(2, count);
}
[Test]
public void MenuFiresPropertyChangedOnAddItems()
{
string text = "hello";
int count = 0;
var menu = new Menu { Text = text };
menu.PropertyChanged += (s, e) =>
{
count = count + 1;
};
menu.Items.Add(new MenuItem());
Assert.AreEqual(1, count);
}
}
}