public void WhenNavigatingWithNullUri_Throws() { // Prepare IRegion region = new Region(); var containerMock = new Mock <IContainerExtension>(); containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(new RegionNavigationJournalEntry()); IContainerExtension container = containerMock.Object; var contentLoader = new Mock <RegionNavigationContentLoader>(container).Object; IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>(); var target = new RegionNavigationService(container, contentLoader, journal) { Region = region }; // Act IRegionNavigationResult navigationResult = null; target.RequestNavigate((Uri)null, nr => navigationResult = nr); // Verify Assert.False(navigationResult.Result.Value); Assert.NotNull(navigationResult.Error); Assert.IsType <ArgumentNullException>(navigationResult.Error); }
public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_ThenOriginalRequestIsIgnored() { var region = new Region(); var viewModelMock = new Mock <IConfirmRegionNavigationRequest>(); var viewMock = new Mock <View>(); var view = viewMock.Object; view.BindingContext = viewModelMock.Object; var confirmationRequests = new List <Action <bool> >(); viewModelMock .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny <INavigationContext>(), It.IsAny <Action <bool> >())) .Callback <INavigationContext, Action <bool> >((nc, c) => { confirmationRequests.Add(c); }); region.Add(view); region.Activate(view); var navigationUri = new Uri("", UriKind.Relative); var containerMock = new Mock <IContainerExtension>(); containerMock .Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))) .Returns(new RegionNavigationJournalEntry()); var contentLoaderMock = new Mock <IRegionNavigationContentLoader>(); contentLoaderMock .Setup(cl => cl.LoadContent(region, It.IsAny <INavigationContext>())) .Returns(view); var container = containerMock.Object; var contentLoader = contentLoaderMock.Object; var journal = Mock.Of <IRegionNavigationJournal>(); var target = new RegionNavigationService(container, contentLoader, journal) { Region = region }; IRegionNavigationResult firstNavigation = null; IRegionNavigationResult secondNavigation = null; target.RequestNavigate(navigationUri, nr => firstNavigation = nr); target.RequestNavigate(navigationUri, nr => secondNavigation = nr); Assert.Equal(2, confirmationRequests.Count); confirmationRequests[0](true); confirmationRequests[1](true); Assert.False(firstNavigation.Result); Assert.True(secondNavigation.Result.Value); }
public void WhenTargetViewCreationThrowsWithAsyncConfirmation_ThenExceptionIsProvidedToNavigationCallback() { var containerMock = new Mock <IContainerExtension>(); var targetException = new Exception(); var targetHandlerMock = new Mock <IRegionNavigationContentLoader>(); targetHandlerMock .Setup(th => th.LoadContent(It.IsAny <IRegion>(), It.IsAny <INavigationContext>())) .Throws(targetException); var journalMock = new Mock <IRegionNavigationJournal>(); Action <bool> navigationCallback = null; var viewMock = new Mock <View>(); viewMock .As <IConfirmRegionNavigationRequest>() .Setup(v => v.ConfirmNavigationRequest(It.IsAny <INavigationContext>(), It.IsAny <Action <bool> >())) .Callback <INavigationContext, Action <bool> >((nc, c) => { navigationCallback = c; }); var region = new Region(); region.Add(viewMock.Object); region.Activate(viewMock.Object); var target = new RegionNavigationService(containerMock.Object, targetHandlerMock.Object, journalMock.Object) { Region = region }; IRegionNavigationResult result = null; target.RequestNavigate(new Uri("", UriKind.Relative), nr => result = nr); navigationCallback(true); Assert.NotNull(result); Assert.Same(targetException, result.Error); }
private void NavigationCallback(IRegionNavigationResult obj) { Console.WriteLine(obj.Context.NavigatedName() + " Region loaded"); }
private void RegionNavigationCallback(IRegionNavigationResult result) { // Handle any errors or anything else you need to here... }
//private void ExecuteLoadModuleCommand() //{ // //_regionManager.RequestNavigate("FlexRegion", "ViewA", NavigationCallback, null); //} private void NavigationCallback(IRegionNavigationResult result) { }