RequestNavigate() public method

Initiates navigation to the specified target.
public RequestNavigate ( Uri target, Action navigationCallback ) : void
target System.Uri The target.
navigationCallback Action A callback to execute when the navigation request is completed.
return void
        public void MissingCandidateViewCreatesViewInRegion()
        {
            this.ConfigureMockServiceLocator();

            // We cannot access the UnityRegionNavigationContentLoader directly so we need to call its
            // GetCandidatesFromRegion method through a navigation request.
            IRegion testRegion = new Region();

            Assert.AreEqual(0, testRegion.Views.Count());
            Assert.AreEqual(0, testRegion.ActiveViews.Count());

            testRegion.RequestNavigate("MockView1");

            Assert.AreEqual(1, testRegion.Views.Count());
            Assert.AreEqual(1, testRegion.ActiveViews.Count());
        }
        public void ShouldFindCandidateViewWithFriendlyNameInRegion()
        {
            this.ConfigureMockServiceLocator();

            // We cannot access the MefRegionNavigationContentLoader directly so we need to call its
            // GetCandidatesFromRegion method through a navigation request.
            IRegion testRegion = new Region();

            MockView2 view = new MockView2();
            testRegion.Add(view);
            testRegion.Deactivate(view);

            testRegion.RequestNavigate("SomeView");

            Assert.IsTrue(testRegion.Views.Contains(view));
            Assert.IsTrue(testRegion.Views.Count() == 1);
            Assert.IsTrue(testRegion.ActiveViews.Count() == 1);
            Assert.IsTrue(testRegion.ActiveViews.Contains(view));
        }
        public void ShouldFindCandidateViewInRegion()
        {
            IUnityContainer container = new UnityContainer();
            container.RegisterType<object, MockView>("MockView");

            this.ConfigureMockServiceLocator(container);

            // We cannot access the UnityRegionNavigationContentLoader directly so we need to call its
            // GetCandidatesFromRegion method through a navigation request.
            IRegion testRegion = new Region();

            MockView view = new MockView();
            testRegion.Add(view);
            testRegion.Deactivate(view);

            testRegion.RequestNavigate("MockView");

            Assert.IsTrue(testRegion.Views.Contains(view));
            Assert.IsTrue(testRegion.Views.Count() == 1);
            Assert.IsTrue(testRegion.ActiveViews.Count() == 1);
            Assert.IsTrue(testRegion.ActiveViews.Contains(view));
        }
コード例 #4
0
        public void NavigateDelegatesToIRegionNavigationService()
        {
            try
            {
                // Prepare
                IRegion region = new Region();

                object view = new object();
                region.Add(view);

                Uri uri = new Uri(view.GetType().Name, UriKind.Relative);
                Action<NavigationResult> navigationCallback = nr => { };

                Mock<IRegionNavigationService> mockRegionNavigationService = new Mock<IRegionNavigationService>();
                mockRegionNavigationService.Setup(x => x.RequestNavigate(uri, navigationCallback)).Verifiable();

                Mock<IServiceLocator> mockServiceLocator = new Mock<IServiceLocator>();
                mockServiceLocator.Setup(x => x.GetInstance<IRegionNavigationService>()).Returns(mockRegionNavigationService.Object);
                ServiceLocator.SetLocatorProvider(() => mockServiceLocator.Object);

                // Act
                region.RequestNavigate(uri, navigationCallback);

                // Verify
                mockRegionNavigationService.VerifyAll();
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(() => null);
            }
        }