summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2017-02-02 09:35:23 -0600
committerKangho Hur <kangho.hur@samsung.com>2017-03-24 13:18:57 +0900
commit3b608a3a5e9b5739014a60995c31dbf610b61de4 (patch)
tree7fa83323820fe480e7eadeffabc92d5a2e0b087b /Xamarin.Forms.Core.UnitTests
parent22ebe38f70c038ef89ce8f1453ece5d222e685a8 (diff)
downloadxamarin-forms-3b608a3a5e9b5739014a60995c31dbf610b61de4.tar.gz
xamarin-forms-3b608a3a5e9b5739014a60995c31dbf610b61de4.tar.bz2
xamarin-forms-3b608a3a5e9b5739014a60995c31dbf610b61de4.zip
[Core] Added RootPage to NavigationPage (#464)
* d * removed whitespace * Using ArgumentNullException * changes
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests')
-rw-r--r--Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs103
1 files changed, 97 insertions, 6 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs b/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs
index d82a97a4..fb68d14e 100644
--- a/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs
+++ b/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs
@@ -14,6 +14,7 @@ namespace Xamarin.Forms.Core.UnitTests
{
NavigationPage nav = new NavigationPage ();
+ Assert.IsNull(nav.RootPage);
Assert.IsNull (nav.CurrentPage);
Label child = new Label {Text = "Label"};
@@ -21,7 +22,9 @@ namespace Xamarin.Forms.Core.UnitTests
await nav.Navigation.PushAsync (childRoot);
- Assert.AreSame (childRoot, nav.CurrentPage);
+ Assert.AreSame(childRoot, nav.RootPage);
+ Assert.AreSame(childRoot, nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
}
[Test]
@@ -40,16 +43,26 @@ namespace Xamarin.Forms.Core.UnitTests
bool fired = false;
nav.Popped += (sender, e) => fired = true;
+
+ Assert.AreSame(childRoot, nav.RootPage);
+ Assert.AreNotSame(childRoot2, nav.RootPage);
+ Assert.AreNotSame(nav.RootPage, nav.CurrentPage);
+
var popped = await nav.Navigation.PopAsync ();
Assert.True (fired);
- Assert.AreSame (childRoot, nav.CurrentPage);
+ Assert.AreSame(childRoot, nav.RootPage);
+ Assert.AreSame(childRoot, nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
Assert.AreEqual (childRoot2, popped);
await nav.PopAsync ();
var last = await nav.Navigation.PopAsync ();
Assert.IsNull (last);
+ Assert.IsNotNull(nav.RootPage);
+ Assert.IsNotNull(nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
}
[Test]
@@ -57,6 +70,7 @@ namespace Xamarin.Forms.Core.UnitTests
{
NavigationPage nav = new NavigationPage ();
+ Assert.IsNull(nav.RootPage);
Assert.IsNull (nav.CurrentPage);
Label child = new Label {Text = "Label"};
@@ -64,7 +78,9 @@ namespace Xamarin.Forms.Core.UnitTests
await nav.PushAsync (childRoot);
- Assert.AreSame (childRoot, nav.CurrentPage);
+ Assert.AreSame (childRoot, nav.RootPage);
+ Assert.AreSame(childRoot, nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
}
[Test]
@@ -96,10 +112,15 @@ namespace Xamarin.Forms.Core.UnitTests
bool fired = false;
nav.Pushed += (sender, e) => fired = true;
+ Assert.AreSame(childRoot, nav.RootPage);
+ Assert.AreSame(childRoot, nav.CurrentPage);
+
await nav.PushAsync (childRoot);
Assert.False (fired);
- Assert.AreEqual (childRoot, nav.CurrentPage);
+ Assert.AreSame(childRoot, nav.RootPage);
+ Assert.AreSame(childRoot, nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
}
[Test]
@@ -184,7 +205,9 @@ namespace Xamarin.Forms.Core.UnitTests
nav.PopToRootAsync ();
Assert.True (signaled);
- Assert.AreEqual (root, nav.CurrentPage);
+ Assert.AreSame (root, nav.RootPage);
+ Assert.AreSame(root, nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
}
[Test]
@@ -209,7 +232,9 @@ namespace Xamarin.Forms.Core.UnitTests
Assert.AreEqual (2, poppedChildren.Count);
Assert.Contains (child1, poppedChildren);
Assert.Contains (child2, poppedChildren);
- Assert.AreEqual (root, nav.CurrentPage);
+ Assert.AreSame(root, nav.RootPage);
+ Assert.AreSame(root, nav.CurrentPage);
+ Assert.AreSame(nav.RootPage, nav.CurrentPage);
}
[Test]
@@ -458,6 +483,72 @@ namespace Xamarin.Forms.Core.UnitTests
Assert.False (result);
}
+ [Test]
+ public void TestInsertPage()
+ {
+ var root = new ContentPage { Title = "Root" };
+ var newPage = new ContentPage();
+ var navPage = new NavigationPage(root);
+
+ navPage.Navigation.InsertPageBefore(newPage, navPage.RootPage);
+
+ Assert.AreSame(newPage, navPage.RootPage);
+ Assert.AreNotSame(newPage, navPage.CurrentPage);
+ Assert.AreNotSame(navPage.RootPage, navPage.CurrentPage);
+ Assert.AreSame(root, navPage.CurrentPage);
+
+ Assert.Throws<ArgumentException>(() =>
+ {
+ navPage.Navigation.InsertPageBefore(new ContentPage(), new ContentPage());
+ });
+
+ Assert.Throws<ArgumentException>(() =>
+ {
+ navPage.Navigation.InsertPageBefore(navPage.RootPage, navPage.CurrentPage);
+ });
+
+ Assert.Throws<ArgumentNullException>(() =>
+ {
+ navPage.Navigation.InsertPageBefore(null, navPage.CurrentPage);
+ });
+
+ Assert.Throws<ArgumentNullException>(() =>
+ {
+ navPage.Navigation.InsertPageBefore(new ContentPage(), null);
+ });
+ }
+
+ [Test]
+ public async void TestRemovePage()
+ {
+ var root = new ContentPage { Title = "Root" };
+ var newPage = new ContentPage();
+ var navPage = new NavigationPage(root);
+ await navPage.PushAsync(newPage);
+
+ navPage.Navigation.RemovePage(root);
+
+ Assert.AreSame(newPage, navPage.RootPage);
+ Assert.AreSame(newPage, navPage.CurrentPage);
+ Assert.AreSame(navPage.RootPage, navPage.CurrentPage);
+ Assert.AreNotSame(root, navPage.CurrentPage);
+
+ Assert.Throws<ArgumentException>(() =>
+ {
+ navPage.Navigation.RemovePage(root);
+ });
+
+ Assert.Throws<InvalidOperationException>(() =>
+ {
+ navPage.Navigation.RemovePage(newPage);
+ });
+
+ Assert.Throws<ArgumentNullException>(() =>
+ {
+ navPage.Navigation.RemovePage(null);
+ });
+ }
+
[Test (Description = "CurrentPage should not be set to null when you attempt to pop the last page")]
[Property ("Bugzilla", 28335)]
public async Task CurrentPageNotNullPoppingRoot()