public void Constructor_Exception_NullStorageManager()
        {
            INavigationTarget navigationTarget = new MockNavigationTarget();
            IViewFactory viewFactory = MockViewFactory.WithPageAndViewModel;
            ILifetimeManager lifetimeManager = new MockLifetimeManager();
            IStorageManager storageManager = null;

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

            Assert.Equal("Value cannot be null.\r\nParameter name: storageManager", e.Message);
            Assert.Equal("storageManager", e.ParamName);
        }
        public void Constructor_RegistersWithLifetimeManager()
        {
            MockLifetimeManager lifetimeManager = new MockLifetimeManager();
            INavigationManager navigationManager = CreateNavigationManager(lifetimeManager: lifetimeManager);

            Assert.Contains((ILifetimeAware)navigationManager, lifetimeManager.RegisteredServices);
        }
        // *** 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_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);
            }
        }