Beispiel #1
0
        public void ClearUpdatesNavigationState()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Uri uri1 = new Uri("Uri1", UriKind.Relative);
            RegionNavigationJournalEntry entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            Uri uri2 = new Uri("Uri2", UriKind.Relative);
            RegionNavigationJournalEntry entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            Uri uri3 = new Uri("Uri3", UriKind.Relative);
            RegionNavigationJournalEntry entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            target.RecordNavigation(entry1, true);
            target.RecordNavigation(entry2, true);
            target.RecordNavigation(entry3, true);

            // Act
            target.Clear();

            // Verify
            Assert.False(target.CanGoBack);
            Assert.False(target.CanGoForward);
            Assert.Null(target.CurrentEntry);
        }
        public void RecordingNavigationMultipleTimesUpdatesNavigationState()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Uri uri1 = new Uri("Uri1", UriKind.Relative);
            RegionNavigationJournalEntry entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            Uri uri2 = new Uri("Uri2", UriKind.Relative);
            RegionNavigationJournalEntry entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            Uri uri3 = new Uri("Uri3", UriKind.Relative);
            RegionNavigationJournalEntry entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            // Act
            target.RecordNavigation(entry1, true);
            target.RecordNavigation(entry2, true);
            target.RecordNavigation(entry3, true);

            // Verify
            Assert.IsTrue(target.CanGoBack);
            Assert.IsFalse(target.CanGoForward);
            Assert.AreSame(entry3, target.CurrentEntry);
        }
Beispiel #3
0
        public void WhenNavigationToNewUri_ThenCanNoLongerNavigateForward()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Mock <INavigateAsync> mockNavigationTarget = new Mock <INavigateAsync>();

            target.NavigationTarget = mockNavigationTarget.Object;

            Uri uri1 = new Uri("Uri1", UriKind.Relative);
            RegionNavigationJournalEntry entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            Uri uri2 = new Uri("Uri2", UriKind.Relative);
            RegionNavigationJournalEntry entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            Uri uri3 = new Uri("Uri3", UriKind.Relative);
            RegionNavigationJournalEntry entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            Uri uri4 = new Uri("Uri4", UriKind.Relative);
            RegionNavigationJournalEntry entry4 = new RegionNavigationJournalEntry()
            {
                Uri = uri4
            };

            target.RecordNavigation(entry1, true);
            target.RecordNavigation(entry2, true);

            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));

            target.GoBack();

            Assert.True(target.CanGoForward);

            // Act
            target.RecordNavigation(entry3, true);

            // Verify
            Assert.False(target.CanGoForward);
            Assert.Equal(entry3, target.CurrentEntry);
        }
Beispiel #4
0
        public void GoForwardMultipleTimesNavigatesForward()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Mock <INavigateAsync> mockNavigationTarget = new Mock <INavigateAsync>();

            target.NavigationTarget = mockNavigationTarget.Object;

            Uri uri1 = new Uri("Uri1", UriKind.Relative);
            RegionNavigationJournalEntry entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            Uri uri2 = new Uri("Uri2", UriKind.Relative);
            RegionNavigationJournalEntry entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            Uri uri3 = new Uri("Uri3", UriKind.Relative);
            RegionNavigationJournalEntry entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            target.RecordNavigation(entry1, true);
            target.RecordNavigation(entry2, true);
            target.RecordNavigation(entry3, true);

            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));

            target.GoBack();
            target.GoBack();

            // Act
            target.GoForward();
            target.GoForward();

            // Verify
            Assert.True(target.CanGoBack);
            Assert.False(target.CanGoForward);
            Assert.Same(entry3, target.CurrentEntry);

            mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >(), null), Times.Once());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >(), null), Times.Exactly(2));
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >(), null), Times.Once());
        }
Beispiel #5
0
        public void GoForwardDoesNotChangeStateWhenNavigationFails()
        {
            // Prepare
            var target = new RegionNavigationJournal();

            var mockNavigationTarget = new Mock <INavigateAsync>();

            target.NavigationTarget = mockNavigationTarget.Object;

            var uri1   = new Uri("Uri1", UriKind.Relative);
            var entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            var uri2   = new Uri("Uri2", UriKind.Relative);
            var entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            var uri3   = new Uri("Uri3", UriKind.Relative);
            var entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            target.RecordNavigation(entry1, true);
            target.RecordNavigation(entry2, true);
            target.RecordNavigation(entry3, true);

            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri1, It.IsAny <Action <IRegionNavigationResult> >(), null))
            .Callback <Uri, Action <IRegionNavigationResult>, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri2, It.IsAny <Action <IRegionNavigationResult> >(), null))
            .Callback <Uri, Action <IRegionNavigationResult>, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri3, It.IsAny <Action <IRegionNavigationResult> >(), null))
            .Callback <Uri, Action <IRegionNavigationResult>, INavigationParameters>((u, c, n) => c(new RegionNavigationResult(null, false)));

            target.GoBack();

            // Act
            target.GoForward();

            // Verify
            Assert.True(target.CanGoBack);
            Assert.True(target.CanGoForward);
            Assert.Same(entry2, target.CurrentEntry);

            mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny <Action <IRegionNavigationResult> >(), null), Times.Never());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny <Action <IRegionNavigationResult> >(), null), Times.Once());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny <Action <IRegionNavigationResult> >(), null), Times.Once());
        }
Beispiel #6
0
        public void GoBackDoesNotChangeStateWhenNavigationFails()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Mock <INavigateAsync> mockNavigationTarget = new Mock <INavigateAsync>();

            target.NavigationTarget = mockNavigationTarget.Object;

            Uri uri1 = new Uri("Uri1", UriKind.Relative);
            RegionNavigationJournalEntry entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            Uri uri2 = new Uri("Uri2", UriKind.Relative);
            RegionNavigationJournalEntry entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            Uri uri3 = new Uri("Uri3", UriKind.Relative);
            RegionNavigationJournalEntry entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            target.RecordNavigation(entry1);
            target.RecordNavigation(entry2);
            target.RecordNavigation(entry3);


            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >()))
            .Callback <Uri, Action <NavigationResult> >((u, c) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >()))
            .Callback <Uri, Action <NavigationResult> >((u, c) => c(new NavigationResult(null, false)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >()))
            .Callback <Uri, Action <NavigationResult> >((u, c) => c(new NavigationResult(null, true)));

            // Act
            target.GoBack();

            // Verify
            Assert.IsTrue(target.CanGoBack);
            Assert.IsFalse(target.CanGoForward);
            Assert.AreSame(entry3, target.CurrentEntry);

            mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >()), Times.Never());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >()), Times.Once());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >()), Times.Never());
        }
        /// <summary>
        /// Called when the implementer is being navigated away from.
        /// </summary>
        /// <param name="navigationContext">The navigation context.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public virtual void OnNavigatedFrom(NavigationContext navigationContext)
        {
            if (navigationContext == null)
            {
                throw new ArgumentNullException(nameof(navigationContext));
            }
            var journalEntry = new RegionNavigationJournalEntry {
                Uri = navigationContext.Uri
            };

            NavigationJournal = NavigationJournal ?? ServiceLocator.Current.GetInstance <IRegionNavigationJournal>();
            NavigationJournal.RecordNavigation(journalEntry);
        }
        public void WhenNavigating_NavigationIsRecordedInJournal()
        {
            // Prepare
            object view    = new object();
            Uri    viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string        regionName    = "RegionName";
            RegionManager regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            IRegionNavigationJournalEntry journalEntry = new RegionNavigationJournalEntry();

            var serviceLocatorMock = new Mock <IServiceLocator>();

            serviceLocatorMock.Setup(x => x.GetInstance <IRegionNavigationJournalEntry>())
            .Returns(journalEntry);

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);

            var journalMock = new Mock <IRegionNavigationJournal>();

            journalMock.Setup(x => x.RecordNavigation(journalEntry)).Verifiable();

            IRegionNavigationJournal journal = journalMock.Object;


            RegionNavigationService target = new RegionNavigationService(serviceLocator, contentLoader, journal);

            target.Region = region;

            // Act
            target.RequestNavigate(viewUri, nr => { });

            // Verify
            Assert.IsNotNull(journalEntry);
            Assert.AreEqual(viewUri, journalEntry.Uri);
            journalMock.VerifyAll();
        }
        public void WhenNavigating_NavigationIsRecordedInJournal()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string regionName    = "RegionName";
            var    regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            IRegionNavigationJournalEntry journalEntry = new RegionNavigationJournalEntry();

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(journalEntry);

            IContainerExtension container = containerMock.Object;
            var contentLoader             = new RegionNavigationContentLoader(container);

            var journalMock = new Mock <IRegionNavigationJournal>();

            journalMock.Setup(x => x.RecordNavigation(journalEntry, true)).Verifiable();

            IRegionNavigationJournal journal = journalMock.Object;


            var target = new RegionNavigationService(container, contentLoader, journal)
            {
                Region = region
            };

            // Act
            target.RequestNavigate(viewUri, nr => { });

            // Verify
            Assert.NotNull(journalEntry);
            Assert.Equal(viewUri, journalEntry.Uri);
            journalMock.VerifyAll();
        }
Beispiel #10
0
        public void RecordingNavigationUpdatesNavigationState()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Uri uri = new Uri("Uri", UriKind.Relative);
            RegionNavigationJournalEntry entry = new RegionNavigationJournalEntry()
            {
                Uri = uri
            };

            // Act
            target.RecordNavigation(entry, true);

            // Verify
            Assert.False(target.CanGoBack);
            Assert.False(target.CanGoForward);
            Assert.Same(entry, target.CurrentEntry);
        }
Beispiel #11
0
        public void WhenSavePreviousFalseDoNotRecordEntry()
        {
            // Prepare
            RegionNavigationJournal target = new RegionNavigationJournal();

            Mock <INavigateAsync> mockNavigationTarget = new Mock <INavigateAsync>();

            target.NavigationTarget = mockNavigationTarget.Object;

            Uri uri1 = new Uri("Uri1", UriKind.Relative);
            RegionNavigationJournalEntry entry1 = new RegionNavigationJournalEntry()
            {
                Uri = uri1
            };

            Uri uri2 = new Uri("Uri2", UriKind.Relative);
            RegionNavigationJournalEntry entry2 = new RegionNavigationJournalEntry()
            {
                Uri = uri2
            };

            Uri uri3 = new Uri("Uri3", UriKind.Relative);
            RegionNavigationJournalEntry entry3 = new RegionNavigationJournalEntry()
            {
                Uri = uri3
            };

            Uri uri4 = new Uri("Uri4", UriKind.Relative);
            RegionNavigationJournalEntry entry4 = new RegionNavigationJournalEntry()
            {
                Uri = uri4
            };

            target.RecordNavigation(entry1, true);
            target.RecordNavigation(entry2, true);
            target.RecordNavigation(entry3, false);
            target.RecordNavigation(entry4, true);

            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));
            mockNavigationTarget
            .Setup(x => x.RequestNavigate(uri4, It.IsAny <Action <NavigationResult> >(), null))
            .Callback <Uri, Action <NavigationResult>, NavigationParameters>((u, c, n) => c(new NavigationResult(null, true)));

            Assert.Equal(entry4, target.CurrentEntry);

            target.GoBack();

            Assert.True(target.CanGoBack);
            Assert.True(target.CanGoForward);
            Assert.Same(entry2, target.CurrentEntry);

            mockNavigationTarget.Verify(x => x.RequestNavigate(uri1, It.IsAny <Action <NavigationResult> >(), null), Times.Never());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri2, It.IsAny <Action <NavigationResult> >(), null), Times.Once());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri3, It.IsAny <Action <NavigationResult> >(), null), Times.Never());
            mockNavigationTarget.Verify(x => x.RequestNavigate(uri4, It.IsAny <Action <NavigationResult> >(), null), Times.Never());
        }