diff options
author | adrianknight89 <adrianknight89@outlook.com> | 2017-02-02 09:35:23 -0600 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-02-02 15:35:23 +0000 |
commit | 070f1dcdb50b47c7abdebf91010626d55881a8fc (patch) | |
tree | 3f92422e306954c2bd4c81dd18f5e46fe559200c /Xamarin.Forms.Core.UnitTests | |
parent | 750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65 (diff) | |
download | xamarin-forms-070f1dcdb50b47c7abdebf91010626d55881a8fc.tar.gz xamarin-forms-070f1dcdb50b47c7abdebf91010626d55881a8fc.tar.bz2 xamarin-forms-070f1dcdb50b47c7abdebf91010626d55881a8fc.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.cs | 103 |
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() |