public async Task NavigateToCurrentViewModel_Calls_VieModel_OnNavigatedTo() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedToCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (a, b) => Assert.IsTrue(true); viewModel.OnNavigatedToCommand = (parameter, navigationMode, frameState) => { Assert.AreEqual(NavigationMode.New, navigationMode); Assert.AreEqual(1, frameState["someValue"]); viewModelNavigatedToCalled = true; }; // Set up the viewModel to the Page we navigated frame.Navigated += (sender, e) => { var view = frame.Content as FrameworkElement; view.DataContext = viewModel; }; var frameSessionState = new MockFrameSessionState(); frameSessionState.GetSessionStateForFrameDelegate = (currentFrame) => { var toReturn = new Dictionary<string, object>(); toReturn.Add("someValue", 1); return toReturn; }; var restorableStateService = new MockSuspensionManagerState(); var navigationService = new FrameNavigationService(frame, frameSessionState, (pageToken) => typeof(MockPage), restorableStateService); navigationService.Navigate("Mock", 1); Assert.IsTrue(viewModelNavigatedToCalled); }); }
public async Task Resuming_Calls_ViewModel_OnNavigatedTo() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); var frameSessionState = new MockFrameSessionState(); frameSessionState.GetSessionStateForFrameDelegate = (currentFrame) => { var toReturn = new Dictionary<string, object>(); toReturn.Add("someValue", 1); return toReturn; }; var restorableStateService = new MockSuspensionManagerState(); var navigationService = new FrameNavigationService(frame, frameSessionState, (pageToken) => typeof(MockPage), restorableStateService); navigationService.Navigate("Mock", 1); var viewModel = new MockPageViewModel(); viewModel.OnNavigatedToCommand = (navigationParameter, navigationMode, frameState) => { Assert.AreEqual(NavigationMode.Refresh, navigationMode); Assert.AreEqual(1, frameState["someValue"]); }; var page = (MockPage)frame.Content; page.DataContext = viewModel; navigationService.RestoreSavedNavigation(); }); }
public async Task NavigateFromCurrentViewModel_Calls_VieModel_OnNavigatedFrom() { await ExecuteOnUIThread(() => { var frame = new FrameFacadeAdapter(new Frame()); bool viewModelNavigatedFromCalled = false; var viewModel = new MockPageViewModel(); viewModel.OnNavigatedFromCommand = (frameState, suspending) => { Assert.IsFalse(suspending); Assert.AreEqual(1, frameState["someValue"]); viewModelNavigatedFromCalled = true; }; var frameSessionState = new MockFrameSessionState(); frameSessionState.GetSessionStateForFrameDelegate = (currentFrame) => { var toReturn = new Dictionary<string, object>(); toReturn.Add("someValue", 1); return toReturn; }; var navigationService = new FrameNavigationService(frame, frameSessionState, (pageToken) => typeof(MockPage), null); // Set up the frame's content with a Page var view = new MockPage(); view.DataContext = viewModel; frame.Content = view; // Navigate to fire the NavigatedToCurrentViewModel navigationService.Navigate("Mock", 1); Assert.IsTrue(viewModelNavigatedFromCalled); }); }