// *** Private Methods *** private TestableNavigationManager CreateNavigationManager(INavigationTarget navigationTarget = null, IViewFactory viewFactory = null, INavigationStack navigationStack = null, ILifetimeManager lifetimeManager = null, IStorageManager storageManager = null, bool navigationTargetIsNull = false) { if (navigationTarget == null && !navigationTargetIsNull) { navigationTarget = new MockNavigationTarget(); } if (viewFactory == null) { viewFactory = MockViewFactory.WithPageAndViewModel; } if (navigationStack == null) { navigationStack = new MockNavigationStack(); } if (lifetimeManager == null) { lifetimeManager = new MockLifetimeManager(); } if (storageManager == null) { storageManager = new MockStorageManager(); } TestableNavigationManager navigationManager = new TestableNavigationManager(navigationTarget, viewFactory, navigationStack, lifetimeManager, storageManager); return(navigationManager); }
// *** Constructors *** public MockNavigationBase(INavigationStack navigationStack = null) { if (navigationStack == null) navigationStack = new MockNavigationStack(); this.NavigationStack = navigationStack; }
public void Constructor_WithViewFactoryAndNavigationStack_ThrowsException_WhenViewFactoryIsNull() { INavigationStack navigationStack = new MockNavigationStack(); var e = Assert.Throws<ArgumentNullException>(() => new TestableSettingsPaneManager(null, navigationStack)); Assert.Equal("Value cannot be null.\r\nParameter name: viewFactory", e.Message); Assert.Equal("viewFactory", e.ParamName); }
public void GoBackTo_Exception_IfPageNameIsEmpty() { MockNavigationStack navigationStack = new MockNavigationStack(); var e = Assert.Throws<ArgumentException>(() => navigationStack.GoBackTo("")); Assert.Equal("The argument cannot be null or an empty string.\r\nParameter name: pageName", e.Message); Assert.Equal("pageName", e.ParamName); }
public void NavigateTo_WithPageName_NavigatesToPage() { MockNavigationStack navigationStack = new MockNavigationStack(); navigationStack.NavigateTo("Page 1"); Assert.Equal(new string[] { "Page 1" }, navigationStack.Select(e => e.PageName).ToList()); Assert.Equal(new object[] { null }, navigationStack.Select(e => e.GetArguments<string>()).ToList()); }
public void GoBackTo_NavigatesBackToPage() { MockNavigationStack navigationStack = new MockNavigationStack(); navigationStack.NavigateTo("Page 1"); navigationStack.NavigateTo("Page 2"); navigationStack.NavigateTo("Page 3"); navigationStack.NavigateTo("Page 4"); navigationStack.GoBackTo("Page 2"); Assert.Equal(new string[] { "Page 1", "Page 2" }, navigationStack.Select(e => e.PageName).ToList()); }
public async Task RestoreNavigationStack_NavigatesToHomePageIfNoPreviousNavigationStack() { MockNavigationStack navigationStack = new MockNavigationStack(); INavigationManager navigationManager = CreateNavigationManager(navigationStack: navigationStack); navigationManager.NavigationStorageType = NavigationStorageType.Local; bool success = await navigationManager.RestoreNavigationStack(); Assert.Equal(false, success); string[] pageNames = navigationStack.Select(page => page.PageName).ToArray(); Assert.Equal(new string[] { "Home" }, pageNames); }
public async Task RestoreNavigationStack_NavigatesToHomePageIfStateFileIsCorrupt() { MockNavigationStack navigationStack = new MockNavigationStack(); MockStorageManager storageManager = new MockStorageManager(); INavigationManager navigationManager = CreateNavigationManager(navigationStack: navigationStack, storageManager: storageManager); navigationManager.NavigationStorageType = NavigationStorageType.Local; InvalidNavigationState state = new InvalidNavigationState(); await storageManager.StoreAsync <InvalidNavigationState>(ApplicationData.Current.LocalFolder, "Okra_Navigation_NavigationManager.xml", state); bool success = await navigationManager.RestoreNavigationStack(); Assert.Equal(false, success); string[] pageNames = navigationStack.Select(page => page.PageName).ToArray(); Assert.Equal(new string[] { "Home" }, pageNames); }
public async Task RestoreNavigationStack_RestoresPreviousNavigationStackViaRoamingStorage() { IStorageManager storageManager = new MockStorageManager(); // --- First Instance --- { MockNavigationStack navigationStack = new MockNavigationStack(); MockLifetimeManager lifetimeManager = new MockLifetimeManager(); INavigationManager navigationManager = CreateNavigationManager(navigationStack: navigationStack, lifetimeManager: lifetimeManager, storageManager: storageManager); navigationManager.NavigationStorageType = NavigationStorageType.Roaming; // Navigate to some pages navigationStack.Add(new PageInfo("Page 1", null)); navigationStack.Add(new PageInfo("Page 2", null)); // Suspend the application lifetimeManager.Suspend(); } // --- Second Instance --- { MockNavigationStack navigationStack = new MockNavigationStack(); INavigationManager navigationManager = CreateNavigationManager(navigationStack: navigationStack, storageManager: storageManager); navigationManager.NavigationStorageType = NavigationStorageType.Roaming; // Restore the navigation stack bool success = await navigationManager.RestoreNavigationStack(); // Assert that the current page is restored from storage Assert.Equal(true, success); string[] pageNames = navigationStack.Select(page => page.PageName).ToArray(); Assert.Equal(new string[] { "Page 1", "Page 2" }, pageNames); } }
public void SettingsPaneBackClick_GoesBackInNavigationStack() { MockNavigationStack navigationStack = new MockNavigationStack(); TestableSettingsPaneManager settingsPaneManager = CreateSettingsPaneManager(navigationStack: navigationStack); navigationStack.NavigateTo(new PageInfo("Page 1", null)); navigationStack.NavigateTo(new PageInfo("Page 2", null)); BackClickEventArgs e = new BackClickEventArgs() { Handled = false }; settingsPaneManager.CallOnSettingsPaneBackClick(e); string[] pageNames = navigationStack.Select(page => page.PageName).ToArray(); Assert.Equal(new string[] { "Page 1" }, pageNames); }
public void SettingsPaneBackClick_HandlesEvent() { MockNavigationStack navigationStack = new MockNavigationStack(); TestableSettingsPaneManager settingsPaneManager = CreateSettingsPaneManager(navigationStack: navigationStack); navigationStack.NavigateTo(new PageInfo("Page 1", null)); navigationStack.NavigateTo(new PageInfo("Page 2", null)); BackClickEventArgs e = new BackClickEventArgs() { Handled = false }; settingsPaneManager.CallOnSettingsPaneBackClick(e); Assert.Equal(true, e.Handled); }
public void FlyoutClosed_ClearsNavigationStack() { MockNavigationStack navigationStack = new MockNavigationStack(); TestableSettingsPaneManager settingsPaneManager = CreateSettingsPaneManager(navigationStack: navigationStack); navigationStack.NavigateTo(new PageInfo("Page 1", null)); navigationStack.NavigateTo(new PageInfo("Page 2", null)); settingsPaneManager.CallOnSettingsFlyoutClosed(); string[] pageNames = navigationStack.Select(page => page.PageName).ToArray(); Assert.Equal(new string[] { }, pageNames); }
public void NavigateTo_WithPageName_Exception_IfPageNameIsNull() { MockNavigationStack navigationStack = new MockNavigationStack(); var e = Assert.Throws<ArgumentException>(() => navigationStack.NavigateTo((string)null)); Assert.Equal("The argument cannot be null or an empty string.\r\nParameter name: pageName", e.Message); Assert.Equal("pageName", e.ParamName); }
public async Task RestoreNavigationStack_NavigatesToHomePageIfStateFileIsCorrupt() { MockNavigationStack navigationStack = new MockNavigationStack(); MockStorageManager storageManager = new MockStorageManager(); INavigationManager navigationManager = CreateNavigationManager(navigationStack: navigationStack, storageManager: storageManager); navigationManager.NavigationStorageType = NavigationStorageType.Local; InvalidNavigationState state = new InvalidNavigationState(); await storageManager.StoreAsync<InvalidNavigationState>(ApplicationData.Current.LocalFolder, "Okra_Navigation_NavigationManager.xml", state); bool success = await navigationManager.RestoreNavigationStack(); Assert.Equal(false, success); string[] pageNames = navigationStack.Select(page => page.PageName).ToArray(); Assert.Equal(new string[] { "Home" }, pageNames); }
public void NavigateTo_WithTypeAndParameter_Exception_IfPageNameIsNull() { MockNavigationStack navigationStack = new MockNavigationStack(); var e = Assert.Throws<ArgumentNullException>(() => navigationStack.NavigateTo((Type)null, "Parameter")); Assert.Equal("Value cannot be null.\r\nParameter name: pageName", e.Message); Assert.Equal("pageName", e.ParamName); }
// *** Private Methods *** private TestableNavigationManager CreateNavigationManager(INavigationTarget navigationTarget = null, IViewFactory viewFactory = null, INavigationStack navigationStack = null, ILifetimeManager lifetimeManager = null, IStorageManager storageManager = null, bool navigationTargetIsNull = false) { if (navigationTarget == null && !navigationTargetIsNull) navigationTarget = new MockNavigationTarget(); if (viewFactory == null) viewFactory = MockViewFactory.WithPageAndViewModel; if (navigationStack == null) navigationStack = new MockNavigationStack(); if (lifetimeManager == null) lifetimeManager = new MockLifetimeManager(); if (storageManager == null) storageManager = new MockStorageManager(); TestableNavigationManager navigationManager = new TestableNavigationManager(navigationTarget, viewFactory, navigationStack, lifetimeManager, storageManager); return navigationManager; }
// *** Private Methods *** private TestableSettingsPaneManager CreateSettingsPaneManager(IViewFactory viewFactory = null, INavigationStack navigationStack = null) { if (viewFactory == null) viewFactory = MockViewFactory.WithPageAndViewModel; if (navigationStack == null) navigationStack = new MockNavigationStack(); TestableSettingsPaneManager settingsPaneManager = new TestableSettingsPaneManager(viewFactory, navigationStack); return settingsPaneManager; }
public void NavigateTo_WithTypeAndParameter_NavigatesToPageWithFullTypeName() { MockNavigationStack navigationStack = new MockNavigationStack(); navigationStack.NavigateTo(typeof(MockNavigationBase.MockPage), "Parameter 1"); Assert.Equal(new string[] { MockNavigationBase.MOCKPAGE_NAME }, navigationStack.Select(e => e.PageName).ToList()); Assert.Equal(new object[] { "Parameter 1" }, navigationStack.Select(e => e.GetArguments<string>()).ToList()); }