private void Close()
        {
            var p = new DialogParameters {
                { "Input", Input.Value }
            };

            if (RegionNavigationService == null)
            {
                RequestClose(new DialogResult(true, p));
            }
            else
            {
                RegionNavigationService?.RequestNavigate(nameof(ContentView), p);
            }
        }
        public void WhenNavigationFailsBecauseActiveViewRejectsIt_ThenNavigationFailedIsRaised()
        {
            // Prepare
            var region = new Region {
                Name = "RegionName"
            };

            var view1Mock = new Mock <View>();

            view1Mock
            .As <IConfirmRegionNavigationRequest>()
            .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny <INavigationContext>(), It.IsAny <Action <bool> >()))
            .Callback <INavigationContext, Action <bool> >((nc, c) => c(false))
            .Verifiable();

            var view1 = view1Mock.Object;

            var view2 = new StackLayout();

            region.Add(view1);
            region.Add(view2);

            region.Activate(view1);

            var navigationUri = new Uri(view2.GetType().Name, 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(view2);

            var container     = containerMock.Object;
            var contentLoader = contentLoaderMock.Object;
            var journal       = Mock.Of <IRegionNavigationJournal>();

            var target = new RegionNavigationService(container, contentLoader, journal)
            {
                Region = region
            };

            RegionNavigationFailedEventArgs eventArgs = null;

            target.NavigationFailed += delegate(object sender, RegionNavigationFailedEventArgs e)
            {
                if (sender == target)
                {
                    eventArgs = e;
                }
            };

            // Act
            bool?isNavigationSuccessful = null;

            target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Result);

            // Verify
            view1Mock.VerifyAll();
            Assert.False(isNavigationSuccessful.Value);
            Assert.NotNull(eventArgs);
            Assert.Null(eventArgs.Error);
        }
Example #3
0
        public void WhenNavigationFailsBecauseDataContextForActiveViewRejectsIt_ThenNavigationFailedIsRaised()
        {
            // Prepare
            var region = new Region {
                Name = "RegionName"
            };

            var viewModel1Mock = new Mock <IConfirmNavigationRequest>();

            viewModel1Mock
            .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny <NavigationContext>(), It.IsAny <Action <bool> >()))
            .Callback <NavigationContext, Action <bool> >((nc, c) => c(false))
            .Verifiable();


            var view1Mock = new Mock <FrameworkElement>();
            var view1     = view1Mock.Object;

            view1.DataContext = viewModel1Mock.Object;

            var view2 = new object();

            region.Add(view1);
            region.Add(view2);

            region.Activate(view1);

            var navigationUri = new Uri(view2.GetType().Name, UriKind.Relative);

            var serviceLocatorMock = new Mock <IServiceLocator>();

            serviceLocatorMock
            .Setup(x => x.GetInstance <IRegionNavigationJournalEntry>())
            .Returns(new RegionNavigationJournalEntry());

            var contentLoaderMock = new Mock <IRegionNavigationContentLoader>();

            contentLoaderMock
            .Setup(cl => cl.LoadContent(region, It.IsAny <NavigationContext>()))
            .Returns(view2);

            var serviceLocator = serviceLocatorMock.Object;
            var contentLoader  = contentLoaderMock.Object;
            var journal        = new Mock <IRegionNavigationJournal>().Object;

            var target = new RegionNavigationService(serviceLocator, contentLoader, journal);

            target.Region = region;

            RegionNavigationFailedEventArgs eventArgs = null;

            target.NavigationFailed += delegate(object sender, RegionNavigationFailedEventArgs e)
            {
                if (sender == target)
                {
                    eventArgs = e;
                }
            };

            // Act
            bool?isNavigationSuccessful = null;

            target.RequestNavigate(navigationUri, nr => isNavigationSuccessful = nr.Result);

            // Verify
            viewModel1Mock.VerifyAll();
            Assert.IsFalse(isNavigationSuccessful.Value);
            Assert.IsNotNull(eventArgs);
            Assert.IsNull(eventArgs.Error);
        }
        public void WhenNavigating_ThenNavigationRequestQueriesForVetoOnAllActiveViewsIfAllSucceed()
        {
            // Prepare
            var region = new Region();

            var view1Mock = new Mock <IConfirmNavigationRequest>();

            view1Mock
            .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny <NavigationContext>(), It.IsAny <Action <bool> >()))
            .Callback <NavigationContext, Action <bool> >((nc, c) => c(true))
            .Verifiable();

            var view1 = view1Mock.Object;

            region.Add(view1);
            region.Activate(view1);

            var view2Mock = new Mock <IConfirmNavigationRequest>();

            var view2 = view2Mock.Object;

            region.Add(view2);

            var view3Mock = new Mock <INavigationAware>();

            var view3 = view3Mock.Object;

            region.Add(view3);
            region.Activate(view3);

            var view4Mock = new Mock <IConfirmNavigationRequest>();

            view4Mock
            .Setup(ina => ina.ConfirmNavigationRequest(It.IsAny <NavigationContext>(), It.IsAny <Action <bool> >()))
            .Callback <NavigationContext, Action <bool> >((nc, c) => c(true))
            .Verifiable();

            var view4 = view4Mock.Object;

            region.Add(view4);
            region.Activate(view4);

            var navigationUri = new Uri(view1.GetType().Name, UriKind.Relative);

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(new RegionNavigationJournalEntry());

            IContainerExtension           container     = containerMock.Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(container).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

            RegionNavigationService target = new RegionNavigationService(container, contentLoader, journal)
            {
                Region = region
            };

            // Act
            target.RequestNavigate(navigationUri, nr => { });

            // Verify
            view1Mock.VerifyAll();
            view2Mock.Verify(ina => ina.ConfirmNavigationRequest(It.IsAny <NavigationContext>(), It.IsAny <Action <bool> >()), Times.Never());
            view3Mock.VerifyAll();
            view4Mock.VerifyAll();
        }
Example #5
0
 public OtherContentViewModel()
 {
     BackCommand    = new DelegateCommand(() => RegionNavigationService.Journal.GoBack(), () => RegionNavigationService?.Journal?.CanGoBack ?? false);
     ForwardCommand = new DelegateCommand(() => RegionNavigationService.Journal.GoForward(), () => RegionNavigationService?.Journal?.CanGoForward ?? false);
     ContentCommand = new DelegateCommand(() => RegionNavigationService.RequestNavigate(nameof(ContentView)));
 }