Пример #1
0
        public async Task GoForward_Raises_NavigationStateChangedEvent()
        {
            int hitCount        = 0;
            var tcs             = new TaskCompletionSource <bool>();
            var eventAggregator = new EventAggregator();

            eventAggregator.GetEvent <NavigationStateChangedEvent>().Subscribe((args) =>
            {
                if (hitCount++ > 2 && args.StateChange == StateChangeType.Forward)
                {
                    tcs.SetResult(true);
                }
            });

            await DispatcherHelper.ExecuteOnUIThread(() =>
            {
                var frame = new FrameFacadeAdapter(new Frame(), eventAggregator);
                var sessionStateService = new MockSessionStateService();
                sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>();
                var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);

                navigationService.Navigate("Mock", 1);
                navigationService.Navigate("Mock", 2);
                navigationService.GoBack();

                navigationService.GoForward();
            });

            await Task.WhenAny(tcs.Task, Task.Delay(200));

            if (tcs.Task.IsCompleted)
            {
                Assert.IsTrue(tcs.Task.Result);
            }
            else
            {
                Assert.Fail("NavigationStateChangedEvent event wasn't raised within 200 ms.");
            }
        }
        public async Task Navigate_Forwards_Can_Go_Back_Back_Button_Visible()
        {
            await DispatcherHelper.ExecuteOnUIThread(() =>
            {
                var eventAggregator     = new EventAggregator();
                var frame               = new FrameFacadeAdapter(new Frame(), eventAggregator);
                var sessionStateService = new MockSessionStateService();
                sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>();
                var navigationService    = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);
                var deviceGestureService = new DeviceGestureService(eventAggregator);
                deviceGestureService.UseTitleBarBackButton = true;
                var navigationManager = SystemNavigationManager.GetForCurrentView();

                // Reset back button visibility before running, can't do this in TestInitialize because CoreWindow sometimes isn't ready
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

                Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);

                navigationService.Navigate("Mock", 1);

                Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);

                navigationService.Navigate("Mock", 2);

                Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility);

                Assert.IsTrue(navigationService.CanGoBack());

                navigationService.GoBack();

                Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);

                navigationService.GoForward();

                Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility);
            });
        }
Пример #3
0
        public async Task Navigate_Forwards_Can_Go_Back_Back_Button_Visible()
        {
            await DispatcherHelper.ExecuteOnUIThread(() =>
            {
                var eventAggregator = new EventAggregator();
                var frame = new FrameFacadeAdapter(new Frame(), eventAggregator);
                var sessionStateService = new MockSessionStateService();
                sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary<string, object>();
                var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);
                var deviceGestureService = new DeviceGestureService(eventAggregator);
                deviceGestureService.UseTitleBarBackButton = true;
                var navigationManager = SystemNavigationManager.GetForCurrentView();

                // Reset back button visibility before running, can't do this in TestInitialize because CoreWindow sometimes isn't ready
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

                Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);

                navigationService.Navigate("Mock", 1);

                Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);

                navigationService.Navigate("Mock", 2);

                Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility);

                Assert.IsTrue(navigationService.CanGoBack());

                navigationService.GoBack();

                Assert.AreEqual(AppViewBackButtonVisibility.Collapsed, navigationManager.AppViewBackButtonVisibility);

                navigationService.GoForward();

                Assert.AreEqual(AppViewBackButtonVisibility.Visible, navigationManager.AppViewBackButtonVisibility);
            });
        }