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()); }
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); }
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()); }
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()); }
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()); }