示例#1
0
        // *** 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);
        }
示例#2
0
        public void Constructor_Exception_NullLifetimeManager()
        {
            INavigationTarget navigationTarget = new MockNavigationTarget();
            IViewFactory      viewFactory      = MockViewFactory.WithPageAndViewModel;
            ILifetimeManager  lifetimeManager  = null;
            IStorageManager   storageManager   = new MockStorageManager();

            var e = Assert.Throws <ArgumentNullException>(() => new NavigationManager(navigationTarget, viewFactory, lifetimeManager, storageManager));

            Assert.Equal("Value cannot be null.\r\nParameter name: lifetimeManager", e.Message);
            Assert.Equal("lifetimeManager", e.ParamName);
        }
        public void Constructor_Exception_NullLifetimeManager()
        {
            INavigationTarget navigationTarget = new MockNavigationTarget();
            IViewFactory viewFactory = MockViewFactory.WithPageAndViewModel;
            ILifetimeManager lifetimeManager = null;
            IStorageManager storageManager = new MockStorageManager();

            var e = Assert.Throws<ArgumentNullException>(() => new NavigationManager(navigationTarget, viewFactory, lifetimeManager, storageManager));

            Assert.Equal("Value cannot be null.\r\nParameter name: lifetimeManager", e.Message);
            Assert.Equal("lifetimeManager", e.ParamName);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
            }
        }
        // *** 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;
        }
        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);
            }
        }