public void ProviderShouldCallCloseAsyncMethodOnBackNavigation() { bool isCancelInvoked = false; bool isNavigatedInvoked = false; const NavigationMode mode = NavigationMode.Back; ViewPageMappingProvider.FindMappingForView = (type, b) => PageMapping; NavigationProvider.CurrentViewModel.ShouldBeNull(); var viewModel = GetViewModel <NavigableViewModelMock>(); NavigationService.OnNavigated(new NavigationEventArgsMock(new ViewMock { DataContext = viewModel }, NavigationMode.New)); viewModel.CloseDelegate = obj => { isCancelInvoked = true; var context = (INavigationContext)obj; context.NavigationProvider.ShouldEqual(NavigationProvider); context.NavigationMode.ShouldEqual(mode); return(ToolkitExtensions.FromResult(false)); }; viewModel.OnNavigatedFromDelegate = context => isNavigatedInvoked = true; var cancelArgs = new NavigatingCancelEventArgsMock(mode, true) { Cancel = false }; NavigationService.OnNavigating(cancelArgs); cancelArgs.Cancel.ShouldBeTrue(); isCancelInvoked.ShouldBeTrue(); isNavigatedInvoked.ShouldBeFalse(); }
public void ProviderShouldNotCallOnNavigatingFromMethodNotCancelable() { bool isCancelInvoked = false; bool isNavigatedInvoked = false; const NavigationMode mode = NavigationMode.Refresh; ViewPageMappingProvider.FindMappingForView = (type, b) => PageMapping; NavigationProvider.CurrentViewModel.ShouldBeNull(); var viewModel = GetViewModel <NavigableViewModelMock>(); NavigationService.OnNavigated(new NavigationEventArgsMock(new ViewMock { DataContext = viewModel }, NavigationMode.New)); NavigationDispatcher.OnNavigatingFromAsync = context => { isCancelInvoked = true; context.NavigationProvider.ShouldEqual(NavigationProvider); context.NavigationMode.ShouldEqual(mode); return(ToolkitExtensions.FromResult(false)); }; NavigationDispatcher.OnNavigated = context => isNavigatedInvoked = true; var cancelArgs = new NavigatingCancelEventArgsMock(mode, false) { Cancel = false }; NavigationService.OnNavigating(cancelArgs); isCancelInvoked.ShouldBeFalse(); isNavigatedInvoked.ShouldBeFalse(); }