summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/NavigationProxyTests.cs
blob: 7dae5f5d89fa252617d9ca30c78ee2979055c916 (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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Core.UnitTests
{
	[TestFixture]
	public class NavigationProxyTests : BaseTestFixture
	{
		class NavigationTest : INavigation
		{
			public Page LastPushed { get; set; }
			public Page LastPushedModal { get; set; }

			public bool Popped { get; set; }
			public bool PoppedModal { get; set; }

			public Task PushAsync (Page root)
			{
				return PushAsync (root, true);
			}

			public Task<Page> PopAsync ()
			{
				return PopAsync (true);
			}

			public Task PopToRootAsync ()
			{
				return PopToRootAsync (true);
			}

			public Task PushModalAsync (Page root)
			{
				return PushModalAsync (root, true);
			}

			public Task<Page> PopModalAsync ()
			{
				return PopModalAsync (true);
			}

			public Task PushAsync (Page root, bool animated)
			{
				LastPushed = root;
				return Task.FromResult (root);
			}

			public Task<Page> PopAsync (bool animated)
			{
				Popped = true;
				return Task.FromResult (LastPushed);
			}

			public Task PopToRootAsync (bool animated)
			{
				return Task.FromResult<Page> (null);
			}

			public Task PushModalAsync (Page root, bool animated)
			{
				LastPushedModal = root;
				return Task.FromResult<object> (null);
			}

			public Task<Page> PopModalAsync (bool animated)
			{
				PoppedModal = true;
				return Task.FromResult<Page> (null);
			}

			public void RemovePage (Page page)
			{
			}

			public void InsertPageBefore (Page page, Page before)
			{
			}

			public System.Collections.Generic.IReadOnlyList<Page> NavigationStack
			{
				get { return new List<Page> (); }
			}

			public System.Collections.Generic.IReadOnlyList<Page> ModalStack
			{
				get { return new List<Page> (); }
			}
		}

		[Test]
		public void Constructor ()
		{
			var proxy = new NavigationProxy ();

			Assert.Null (proxy.Inner);
		}

		[Test]
		public async Task PushesIntoNextInner ()
		{
			var page = new ContentPage ();
			var navProxy = new NavigationProxy ();

			await navProxy.PushAsync (page);

			var navTest = new NavigationTest ();
			navProxy.Inner = navTest;

			Assert.AreEqual (page, navTest.LastPushed);
		}

		[Test]
		public async Task PushesModalIntoNextInner ()
		{
			var page = new ContentPage ();
			var navProxy = new NavigationProxy ();

			await navProxy.PushModalAsync (page);

			var navTest = new NavigationTest ();
			navProxy.Inner = navTest;

			Assert.AreEqual (page, navTest.LastPushedModal);
		}

		[Test]
		public async Task TestPushWithInner ()
		{
			var proxy = new NavigationProxy ();
			var inner = new NavigationTest ();

			proxy.Inner = inner;

			var child = new ContentPage {Content = new View ()};
			await proxy.PushAsync (child);

			Assert.AreEqual (child, inner.LastPushed);
		}

		[Test]
		public async Task TestPushModalWithInner ()
		{
			var proxy = new NavigationProxy ();
			var inner = new NavigationTest ();

			proxy.Inner = inner;

			var child = new ContentPage {Content = new View ()};
			await proxy.PushModalAsync (child);

			Assert.AreEqual (child, inner.LastPushedModal);
		}

		[Test]
		public async Task TestPopWithInner ()
		{
			var proxy = new NavigationProxy ();
			var inner = new NavigationTest ();

			proxy.Inner = inner;

			var child = new ContentPage {Content = new View ()};
			await proxy.PushAsync (child);

			var result = await proxy.PopAsync ();
			Assert.AreEqual (child, result);
			Assert.True (inner.Popped, "Pop was never called on the inner proxy item");
		}

		[Test]
		public async Task TestPopModalWithInner ()
		{
			var proxy = new NavigationProxy ();
			var inner = new NavigationTest ();

			proxy.Inner = inner;

			var child = new ContentPage {Content = new View ()};
			await proxy.PushModalAsync (child);

			await proxy.PopModalAsync ();
			Assert.True (inner.PoppedModal, "Pop was never called on the inner proxy item");
		}
	}
}