public void BeforeNavigation_IsNotRegisteredWithDataTransferManager()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();
            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);

            Assert.AreEqual(0, sharingManager.RegisterForSharingCount);
        }
        public void OnFirstPageNavigation_RegistersWithDataTransferManager()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();
            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);

            navigationManager.RaiseNavigatedTo(new PageNavigationEventArgs(new MockNavigationEntry(), NavigationMode.Forward));

            Assert.AreEqual(1, sharingManager.RegisterForSharingCount);
        }
        public void Constructor_ThrowsException_IfActivationManagerIsNull()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();

            var e = Assert.Throws<ArgumentNullException>(() => new SearchManager(navigationManager, null));

            Assert.Equal("Value cannot be null.\r\nParameter name: activationManager", e.Message);
            Assert.Equal("activationManager", e.ParamName);
        }
        public void NavigateTo_WithTypeAndParameter_NavigatesToPageWithFullTypeName()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();

            navigationManager.NavigateTo(typeof(NavigationManagerExFixture), "Parameter");

            CollectionAssert.AreEqual(new[] { new Tuple<string, object>("Okra.Tests.Navigation.NavigationManagerExFixture", "Parameter") },
                        (ICollection)navigationManager.NavigatedPages);
        }
        public void ShareRequested_ThrowsException_IfShareRequestIsNull()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();
            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);

            var e = Assert.Throws<ArgumentNullException>(() => sharingManager.ShareRequested(null));

            Assert.Equal("Value cannot be null.\r\nParameter name: shareRequest", e.Message);
            Assert.Equal("shareRequest", e.ParamName);
        }
        public async Task Activate_Launch_NavigatesToHomePageIfPreviousExecutionClosedByUser()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            LaunchActivationHandler activationHandler = CreateLaunchActivationHandler(navigationManager);

            // Activate the application

            await activationHandler.Activate(new MockLaunchActivatedEventArgs() { PreviousExecutionState = ApplicationExecutionState.ClosedByUser });

            // Assert that the home page was navigated to

            CollectionAssert.AreEqual(new string[] { "Home" }, navigationManager.NavigatedPages.Select(t => t.Item1).ToArray());
        }
        public async Task Activate_ReturnsFalseIfActivationKindIsNotLaunch()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            LaunchActivationHandler activationHandler = CreateLaunchActivationHandler(navigationManager);

            // Activate the application

            bool result = await activationHandler.Activate(new MockActivatedEventArgs() { Kind = ActivationKind.Search });

            // Check the result

            Assert.Equal(false, result);
        }
        public async Task Activate_RestoresNavigationIfPreviousExecutionTerminated()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            LaunchActivationHandler activationHandler = CreateLaunchActivationHandler(navigationManager);

            // Activate the application

            await activationHandler.Activate(new MockLaunchActivatedEventArgs() { PreviousExecutionState = ApplicationExecutionState.Terminated });

            // Assert that the home page was navigated to

            Assert.Equal(new string[] { "[Restored Pages]" }, navigationManager.NavigatedPages.Select(t => t.Item1).ToArray());
        }
        public async Task Activate_ReturnsTrueIfActivationKindIsLaunch()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            LaunchActivationHandler activationHandler = CreateLaunchActivationHandler(navigationManager);

            // Activate the application

            bool result = await activationHandler.Activate(new MockLaunchActivatedEventArgs() { PreviousExecutionState = ApplicationExecutionState.Terminated });

            // Check the result

            Assert.Equal(true, result);
        }
Exemple #10
0
        public async Task Activate_EmptySearch_NavigatesToHomePageIfPreviousExecutionNotRunning()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "", Language = "en-GB", PreviousExecutionState = ApplicationExecutionState.NotRunning });

            CollectionAssert.AreEqual(new[] { Tuple.Create("Home", (object)null) }, (ICollection)navigationManager.NavigatedPages);
        }
Exemple #11
0
        public async Task Activate_EmptySearch_NoNavigationIfPreviousExecutionSuspended()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "", Language = "en-GB", PreviousExecutionState = ApplicationExecutionState.Suspended });

            CollectionAssert.AreEqual(new Tuple<string, object>[] { }, (ICollection)navigationManager.NavigatedPages);
        }
Exemple #12
0
        public async Task Activate_NavigatesToSearchPageAfterHomePageIfPreviousExecutionClosedByUser()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB", PreviousExecutionState = ApplicationExecutionState.ClosedByUser });

            CollectionAssert.AreEqual(new[] { Tuple.Create("Home", (object)null), Tuple.Create("Search", (object)null) }, (ICollection)navigationManager.NavigatedPages);
        }
        public void NavigateTo_WithTypeAndParameter_Exception_IfPageNameIsNull()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();

            Assert.ThrowsException<ArgumentNullException>(() => navigationManager.NavigateTo((Type)null, "Parameter"));
        }
        public void OnSecondPageNavigation_OnlyRegistersWithDataTransferManagerOnce()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();
            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);

            navigationManager.RaiseNavigatedTo(new PageNavigationEventArgs(new PageInfo("Page 1", null), PageNavigationMode.Forward));
            navigationManager.RaiseNavigatedTo(new PageNavigationEventArgs(new PageInfo("Page 2", null), PageNavigationMode.Forward));

            Assert.Equal(1, sharingManager.RegisterForSharingCount);
        }
        public void WithSharableElement_ForwardsDataRequest()
        {
            INavigationManager navigationManager = new MockNavigationManager(pageName =>
                                {
                                    return new MockNavigationEntry()
                                            {
                                                PageName = pageName,
                                                PageElements = new object[] { new MockPageElement(), new MockShareablePageElement(), new MockPageElement() }
                                            };
                                });

            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);

            navigationManager.NavigateTo("Test Page");
            MockDataRequest dataRequest = new MockDataRequest();
            sharingManager.DataRequested(dataRequest);

            MockShareablePageElement sharableElement = navigationManager.CurrentPage.GetElements().First(e => e is MockShareablePageElement) as MockShareablePageElement;
            CollectionAssert.AreEqual(new object[] { dataRequest }, sharableElement.DataRequests);
        }
        public void WithSharableElement_DoesNotSetDisplayText()
        {
            INavigationManager navigationManager = new MockNavigationManager(pageName =>
            {
                return new MockNavigationEntry()
                {
                    PageName = pageName,
                    PageElements = new object[] { new MockShareablePageElement() }
                };
            });

            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);
            sharingManager.DefaultFailureText = "Default Text";

            navigationManager.NavigateTo("Test Page");
            MockDataRequest dataRequest = new MockDataRequest();
            sharingManager.DataRequested(dataRequest);

            CollectionAssert.AreEqual(new string[] { }, dataRequest.FailureText);
        }
        public async Task Activate_EmptySearch_NavigatesToHomePageIfPreviousExecutionClosedByUser()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "", Language = "en-GB", PreviousExecutionState = ApplicationExecutionState.ClosedByUser });

            Assert.Equal<Tuple<string, object>>(new[] { Tuple.Create("Home", (object)null) }, navigationManager.NavigatedPages);
        }
        public void WithSharableElement_DoesNotSetDisplayText()
        {
            INavigationManager navigationManager = new MockNavigationManager(_ => new object[] { new MockShareablePageElement() });

            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);
            sharingManager.DefaultFailureText = "Default Text";

            navigationManager.NavigationStack.NavigateTo(new PageInfo("Test Page", null));
            MockShareRequest shareRequest = new MockShareRequest();
            sharingManager.ShareRequested(shareRequest);

            Assert.Equal(new string[] { }, shareRequest.FailureText);
        }
Exemple #19
0
        public async Task Activate_DoesNotNavigateIfActivationKindIsNotSearch()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            // Activate the application

            await searchManager.Activate(new MockActivatedEventArgs() { Kind = ActivationKind.Launch });

            // Assert that no pages were navigated

            CollectionAssert.AreEqual(new string[] { }, navigationManager.NavigatedPages.Select(t => t.Item1).ToArray());
        }
Exemple #20
0
        public async Task Activate_SuccessfulEvenWhenNoSearchPageImplementors()
        {
            MockNavigationEntry searchPageEntry = new MockNavigationEntry() { Page = new MockPageElement(), ViewModel = new MockPageElement() };
            MockNavigationManager navigationManager = new MockNavigationManager(_ => searchPageEntry);
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB" });
        }
        // *** Private Methods ***

        private LaunchActivationHandler CreateLaunchActivationHandler(INavigationManager navigationManager = null, IActivationManager activationManager = null)
        {
            if (navigationManager == null)
                navigationManager = new MockNavigationManager();

            if (activationManager == null)
                activationManager = new MockActivationManager();

            return new LaunchActivationHandler(activationManager, navigationManager);
        }
        public async Task Activate_DoesNotNavigateIfActivationKindIsNotLaunch()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            LaunchActivationHandler activationHandler = CreateLaunchActivationHandler(navigationManager);

            // Activate the application

            await activationHandler.Activate(new MockActivatedEventArgs() { Kind = ActivationKind.Search });

            // Assert that the home page was navigated to

            Assert.Equal(new string[] { }, navigationManager.NavigatedPages.Select(t => t.Item1).ToArray());
        }
Exemple #23
0
        public async Task Activate_DoesNotNavigateIfAlreadyShowingSearchPage()
        {
            MockNavigationManager navigationManager = new MockNavigationManager();
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            navigationManager.NavigateTo("Search");
            navigationManager.NavigatedPages.Clear();

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB", PreviousExecutionState = ApplicationExecutionState.Running });

            CollectionAssert.AreEqual(new Tuple<string, object>[] { }, (ICollection)navigationManager.NavigatedPages);
        }
        public async Task Activate_DoesNotCallPerformQueryIfSameQueryAsVisible()
        {
            MockNavigationManager navigationManager = new MockNavigationManager(_ => new object[] { new MockSearchPageElement(), new MockSearchPageElement() });
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB" });

            PageInfo searchPage = navigationManager.NavigationStack.CurrentPage;
            IList<object> searchElements = navigationManager.GetPageElements(searchPage).ToList();

            Assert.Equal<Tuple<string, string>>(new[] { Tuple.Create("MyQuery", "en-GB") }, ((MockSearchPageElement)searchElements[1]).Queries);
            Assert.Equal<Tuple<string, string>>(new[] { Tuple.Create("MyQuery", "en-GB") }, ((MockSearchPageElement)searchElements[0]).Queries);
        }
Exemple #25
0
        public async Task Activate_CallsPerformQueryOnlyOnSearchPageImplementors()
        {
            MockNavigationEntry searchPageEntry = new MockNavigationEntry() { Page = new MockPageElement() };
            MockNavigationManager navigationManager = new MockNavigationManager(_ => searchPageEntry);
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB" });

            CollectionAssert.AreEqual(new[] { Tuple.Create("MyQuery", "en-GB") }, (ICollection)((MockSearchPageElement)searchPageEntry.ViewModel).Queries);
        }
        // *** Private Methods ***

        private TestableSharingManager CreateSharingManager(INavigationManager navigationManager = null)
        {
            if (navigationManager == null)
                navigationManager = new MockNavigationManager();

            TestableSharingManager sharingManager = new TestableSharingManager(navigationManager);

            return sharingManager;
        }
Exemple #27
0
        public async Task Activate_DoesNotCallPerformQueryIfSameQueryAsVisible()
        {
            MockNavigationEntry searchPageEntry = new MockNavigationEntry();
            MockNavigationManager navigationManager = new MockNavigationManager(_ => searchPageEntry);
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB" });

            CollectionAssert.AreEqual(new[] { Tuple.Create("MyQuery", "en-GB") }, (ICollection)((MockSearchPageElement)searchPageEntry.Page).Queries);
            CollectionAssert.AreEqual(new[] { Tuple.Create("MyQuery", "en-GB") }, (ICollection)((MockSearchPageElement)searchPageEntry.ViewModel).Queries);
        }
        public async Task Activate_NavigatesToSearchPageWithRestoredNavigationIfPreviousExecutionTerminated()
        {
            MockNavigationManager navigationManager = new MockNavigationManager() { CanRestoreNavigationStack = true };
            SearchManager searchManager = CreateSearchMananger(navigationManager: navigationManager);

            await searchManager.Activate(new MockSearchActivatedEventArgs() { QueryText = "MyQuery", Language = "en-GB", PreviousExecutionState = ApplicationExecutionState.Terminated });

            Assert.Equal<Tuple<string, object>>(new[] { Tuple.Create("[Restored Pages]", (object)null), Tuple.Create("Search", (object)null) }, navigationManager.NavigatedPages);
        }
Exemple #29
0
        // *** Private Methods ***

        private TestableSearchManager CreateSearchMananger(MockNavigationManager navigationManager = null, MockActivationManager activationManager = null, bool setSearchPageName = true)
        {
            if (navigationManager == null)
                navigationManager = new MockNavigationManager();

            if (activationManager == null)
                activationManager = new MockActivationManager();

            TestableSearchManager searchManager = new TestableSearchManager(navigationManager, activationManager);

            if (setSearchPageName)
                searchManager.SearchPageName = "Search";

            return searchManager;
        }
        public void WithSharableElement_ForwardsShareRequest()
        {
            INavigationManager navigationManager = new MockNavigationManager(_ => new object[] { new MockPageElement(), new MockShareablePageElement(), new MockPageElement() });

            TestableSharingManager sharingManager = CreateSharingManager(navigationManager);

            navigationManager.NavigationStack.NavigateTo(new PageInfo("Test Page", null));

            MockShareRequest shareRequest = new MockShareRequest();
            sharingManager.ShareRequested(shareRequest);

            MockShareablePageElement sharableElement = navigationManager.GetPageElements(navigationManager.NavigationStack.CurrentPage).First(e => e is MockShareablePageElement) as MockShareablePageElement;
            Assert.Equal(new object[] { shareRequest }, sharableElement.ShareRequests);
        }