Exemplo n.º 1
0
 /// <summary>
 ///     Close and Deactivate this View
 /// </summary>
 public virtual void Close()
 {
     IsActive = false;
     RegionNavigationService.Close(this);
     //if (!RegionInfo.IsEmpty() && RegionInfo.RegionName.IsNotNullOrEmpty())
     //    RegionManager?.Regions[RegionInfo.RegionName].Deactivate(RegionInfo.View);
 }
        public void WhenNavigatingWithNullUri_Throws()
        {
            // Prepare
            IRegion region = new Region();

            var containerMock = new Mock <IContainerExtension>();

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

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

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

            // Act
            IRegionNavigationResult navigationResult = null;

            target.RequestNavigate((Uri)null, nr => navigationResult = nr);

            // Verify
            Assert.False(navigationResult.Result.Value);
            Assert.NotNull(navigationResult.Error);
            Assert.IsType <ArgumentNullException>(navigationResult.Error);
        }
        public void WhenNavigatingWithNullUri_Throws()
        {
            // Prepare
            IRegion region = new Region();

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

            // Act
            NavigationResult navigationResult = null;

            target.RequestNavigate((Uri)null, nr => navigationResult = nr);

            // Verify
            Assert.IsFalse(navigationResult.Result.Value);
            Assert.IsNotNull(navigationResult.Error);
            Assert.IsInstanceOfType(navigationResult.Error, typeof(ArgumentNullException));
        }
        public void WhenNavigatingAndDataContextImplementsINavigationAware_ThenNavigatedIsInvokesOnNavigation()
        {
            // Prepare
            var region = new Region();

            Mock <FrameworkElement> mockFrameworkElement            = new Mock <FrameworkElement>();
            Mock <INavigationAware> mockINavigationAwareDataContext = new Mock <INavigationAware>();

            mockINavigationAwareDataContext.Setup(ina => ina.IsNavigationTarget(It.IsAny <NavigationContext>())).Returns(true);
            mockFrameworkElement.Object.DataContext = mockINavigationAwareDataContext.Object;

            var view = mockFrameworkElement.Object;

            region.Add(view);

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

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

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

            // Verify
            mockINavigationAwareDataContext.Verify(v => v.OnNavigatedTo(It.Is <NavigationContext>(nc => nc.Uri == navigationUri)));
        }
        public void WhenNavigatingFromViewThatIsNavigationAware_ThenNotifiesActiveViewNavigatingFrom()
        {
            // Arrange
            var region   = new Region();
            var viewMock = new Mock <INavigationAware>();
            var view     = viewMock.Object;

            region.Add(view);

            var view2 = new object();

            region.Add(view2);

            region.Activate(view);

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            var             navigationUri  = new Uri(view2.GetType().Name, UriKind.Relative);
            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

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

            // Verify
            viewMock.Verify(v => v.OnNavigatedFrom(It.Is <NavigationContext>(ctx => ctx.Uri == navigationUri && ctx.Parameters.Count() == 0)));
        }
        public void WhenNavigatingAndViewImplementsINavigationAware_ThenNavigatedIsInvokedOnNavigation()
        {
            // Prepare
            var region = new Region();

            var viewMock = new Mock <INavigationAware>();

            viewMock.Setup(ina => ina.IsNavigationTarget(It.IsAny <NavigationContext>())).Returns(true);
            var view = viewMock.Object;

            region.Add(view);

            var navigationUri = new Uri(view.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 RegionNavigationContentLoader(container);
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

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

            // Verify
            viewMock.Verify(v => v.OnNavigatedTo(It.Is <NavigationContext>(nc => nc.Uri == navigationUri && nc.NavigationService == target)));
        }
        public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_ThenOriginalRequestIsIgnored()
        {
            var region = new Region();

            var viewModelMock = new Mock <IConfirmRegionNavigationRequest>();

            var viewMock = new Mock <View>();
            var view     = viewMock.Object;

            view.BindingContext = viewModelMock.Object;

            var confirmationRequests = new List <Action <bool> >();

            viewModelMock
            .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny <INavigationContext>(), It.IsAny <Action <bool> >()))
            .Callback <INavigationContext, Action <bool> >((nc, c) => { confirmationRequests.Add(c); });

            region.Add(view);
            region.Activate(view);

            var navigationUri = new Uri("", 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(view);

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

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

            IRegionNavigationResult firstNavigation  = null;
            IRegionNavigationResult secondNavigation = null;

            target.RequestNavigate(navigationUri, nr => firstNavigation  = nr);
            target.RequestNavigate(navigationUri, nr => secondNavigation = nr);

            Assert.Equal(2, confirmationRequests.Count);

            confirmationRequests[0](true);
            confirmationRequests[1](true);

            Assert.False(firstNavigation.Result);
            Assert.True(secondNavigation.Result.Value);
        }
        public void WhenViewModelAcceptsNavigationOutAfterNewIncomingRequestIsReceived_ThenOriginalRequestIsIgnored()
        {
            var region = new Region();

            var viewModelMock = new Mock <IConfirmNavigationRequest>();

            var viewMock = new Mock <FrameworkElement>();
            var view     = viewMock.Object;

            view.DataContext = viewModelMock.Object;

            var confirmationRequests = new List <Action <bool> >();

            viewModelMock
            .Setup(icnr => icnr.ConfirmNavigationRequest(It.IsAny <NavigationContext>(), It.IsAny <Action <bool> >()))
            .Callback <NavigationContext, Action <bool> >((nc, c) => { confirmationRequests.Add(c); });

            region.Add(view);
            region.Activate(view);

            var navigationUri = new Uri("", 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(view);

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

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

            target.Region = region;

            bool firstNavigation  = false;
            bool secondNavigation = false;

            target.RequestNavigate(navigationUri, nr => firstNavigation  = nr.Result.Value);
            target.RequestNavigate(navigationUri, nr => secondNavigation = nr.Result.Value);

            Assert.AreEqual(2, confirmationRequests.Count);

            confirmationRequests[0](true);
            confirmationRequests[1](true);

            Assert.IsFalse(firstNavigation);
            Assert.IsTrue(secondNavigation);
        }
        /// <summary>
        /// 次へのボタンを押したときの処理
        /// </summary>
        private void NextButtonAction()
        {
            var param = new NavigationParameters();

            param.Add("TargetData", true); // パラメータをkeyとvalueの組み合わせで追加

            StopCapture();                 // カメラの映像を止める

            // 第二引数にパラメータを渡すと、viewが切り替わった先でパラメータを受け取る
            RegionNavigationService.RequestNavigate(nameof(SelectScreen), param);
        }
Exemplo n.º 10
0
        protected override void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.PropertyName != ExtractPropertyName(() => SelectedElement))
            {
                return;
            }

            var vtitle = SelectedElement.CastAs <IViewTitle>();

            RegionNavigationService.SetViewTitle(vtitle?.ViewHeader);
        }
        public void WhenRequestNavigateAwayOnDataContextAcceptsThroughCallback_ThenNavigationProceeds()
        {
            // Prepare
            var region = new Region();

            var view1DataContextMock = new Mock <IConfirmNavigationRequest>();

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

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

            view1.DataContext = view1DataContextMock.Object;

            var view2 = new object();

            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());

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

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

            // Act
            var navigationSucceeded = false;

            target.RequestNavigate(navigationUri, nr => { navigationSucceeded = nr.Result == true; });

            // Verify
            view1DataContextMock.VerifyAll();
            Assert.True(navigationSucceeded);
            Assert.Equal(new object[] { view1, view2 }, region.ActiveViews.ToArray());
        }
Exemplo n.º 12
0
        public void WhenNavigationFromViewThatIsNavigationAware_OnlyNotifiesOnNavigateFromForActiveViews()
        {
            // Arrange

            bool navigationFromInvoked = false;

            var region = new Region();

            var viewMock = new Mock <View>();

            viewMock
            .As <IRegionAware>()
            .Setup(x => x.OnNavigatedFrom(It.IsAny <INavigationContext>())).Callback(() => navigationFromInvoked = true);
            var view = viewMock.Object;

            region.Add(view);

            var targetViewMock = new Mock <StackLayout>();

            targetViewMock.As <IRegionAware>();
            region.Add(targetViewMock.Object);

            var activeViewMock = new Mock <Grid>();

            activeViewMock.As <IRegionAware>();
            region.Add(activeViewMock.Object);

            region.Activate(activeViewMock.Object);

            var containerMock = new Mock <IContainerExtension>();

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

            var navigationUri                = new Uri(targetViewMock.Object.GetType().Name, UriKind.Relative);
            IContainerExtension container    = containerMock.Object;
            var contentLoader                = new Mock <RegionNavigationContentLoader>(container).Object;
            IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>();

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

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

            // Verify
            Assert.False(navigationFromInvoked);
        }
Exemplo n.º 13
0
        public void WhenRequestNavigateAwayOnBindingContextRejectsThroughCallback_ThenNavigationDoesNotProceed()
        {
            // Prepare
            var region = new Region();

            var view1BindingContextMock = new Mock <IConfirmRegionNavigationRequest>();

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

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

            view1.BindingContext = view1BindingContextMock.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());

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

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

            // Act
            var navigationFailed = false;

            target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; });

            // Verify
            view1BindingContextMock.VerifyAll();
            Assert.True(navigationFailed);
            Assert.Equal(new object[] { view1 }, region.ActiveViews.ToArray());
        }
Exemplo n.º 14
0
        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 WhenRequestNavigateAwayOnDataContextRejectsThroughCallback_ThenNavigationDoesNotProceed()
        {
            // Prepare
            var region = new Region();

            var view1DataContextMock = new Mock <IConfirmNavigationRequest>();

            view1DataContextMock
            .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 = view1DataContextMock.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());

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

            // Act
            var navigationFailed = false;

            target.RequestNavigate(navigationUri, nr => { navigationFailed = nr.Result == false; });

            // Verify
            view1DataContextMock.VerifyAll();
            Assert.IsTrue(navigationFailed);
            CollectionAssert.AreEqual(new object[] { view1 }, region.ActiveViews.ToArray());
        }
        public void WhenNavigatingWithNoRegionSet_ThenMarshallExceptionToCallback()
        {
            var             navigationUri  = new Uri("/", UriKind.Relative);
            IServiceLocator serviceLocator = new Mock <IServiceLocator>().Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            Exception error = null;

            target.RequestNavigate(navigationUri, nr => error = nr.Error);

            Assert.IsNotNull(error);
            Assert.IsInstanceOfType(error, typeof(InvalidOperationException));
        }
Exemplo n.º 17
0
        public void WhenNavigatingWithNoRegionSet_ThenMarshallExceptionToCallback()
        {
            var navigationUri                = new Uri("/", UriKind.Relative);
            IContainerExtension container    = new Mock <IContainerExtension>().Object;
            var contentLoader                = new Mock <RegionNavigationContentLoader>(container).Object;
            IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>();

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

            Exception error = null;

            target.RequestNavigate(navigationUri, nr => error = nr.Error);

            Assert.NotNull(error);
            Assert.IsType <InvalidOperationException>(error);
        }
Exemplo n.º 18
0
        public void WhenNavigationSucceeds_NavigatedIsRaised()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string regionName    = "RegionName";
            var    regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            var containerMock = new Mock <IContainerExtension>();

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

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

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

            bool isNavigatedRaised = false;

            target.Navigated += delegate(object sender, RegionNavigationEventArgs e)
            {
                if (sender == target)
                {
                    isNavigatedRaised = true;
                }
            };

            // Act
            bool isNavigationSuccessful = false;

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

            // Verify
            Assert.True(isNavigationSuccessful);
            Assert.True(isNavigatedRaised);
        }
        public void WhenNavigationSucceeds_NavigatedIsRaised()
        {
            // Prepare
            object view    = new object();
            Uri    viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string        regionName    = "RegionName";
            RegionManager regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

            bool isNavigatedRaised = false;

            target.Navigated += delegate(object sender, RegionNavigationEventArgs e)
            {
                if (sender == target)
                {
                    isNavigatedRaised = true;
                }
            };


            // Act
            bool isNavigationSuccessful = false;

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

            // Verify
            Assert.IsTrue(isNavigationSuccessful);
            Assert.IsTrue(isNavigatedRaised);
        }
        public void WhenNavigationFailsBecauseTheContentViewCannotBeRetrieved_ThenNavigationFailedIsRaised()
        {
            // Prepare
            var region = new Region {
                Name = "RegionName"
            };

            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>()))
            .Throws <InvalidOperationException>();

            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(new Uri("invalid", UriKind.Relative), nr => isNavigationSuccessful = nr.Result);

            // Verify
            Assert.IsFalse(isNavigationSuccessful.Value);
            Assert.IsNotNull(eventArgs);
            Assert.IsNotNull(eventArgs.Error);
        }
        public void WhenNavigatingWithNullUri_ThenMarshallExceptionToCallback()
        {
            IServiceLocator serviceLocator = new Mock <IServiceLocator>().Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = new Region();

            Exception error = null;

            target.RequestNavigate(null, nr => error = nr.Error);

            Assert.IsNotNull(error);
            Assert.IsInstanceOfType(error, typeof(ArgumentNullException));
        }
        public void WhenNavigationFromViewThatIsNavigationAware_OnlyNotifiesOnNavigateFromForActiveViews()
        {
            // Arrange

            bool navigationFromInvoked = false;

            var region = new Region();

            var viewMock = new Mock <INavigationAware>();

            viewMock
            .Setup(x => x.OnNavigatedFrom(It.IsAny <NavigationContext>())).Callback(() => navigationFromInvoked = true);
            var view = viewMock.Object;

            region.Add(view);

            var targetViewMock = new Mock <INavigationAware>();

            region.Add(targetViewMock.Object);

            var activeViewMock = new Mock <INavigationAware>();

            region.Add(activeViewMock.Object);

            region.Activate(activeViewMock.Object);

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            var             navigationUri  = new Uri(targetViewMock.Object.GetType().Name, UriKind.Relative);
            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

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

            // Verify
            Assert.IsFalse(navigationFromInvoked);
        }
Exemplo n.º 23
0
        public void WhenNavigatingWithNullUri_ThenMarshallExceptionToCallback()
        {
            IContainerExtension container    = new Mock <IContainerExtension>().Object;
            var contentLoader                = new Mock <RegionNavigationContentLoader>(container).Object;
            IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>();

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

            Exception error = null;

            target.RequestNavigate(null, nr => error = nr.Error);

            Assert.NotNull(error);
            Assert.IsType <ArgumentNullException>(error);
        }
Exemplo n.º 24
0
        public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string otherType = "OtherType";

            var containerMock = new Mock <IContainerExtension>();

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

            var targetHandlerMock = new Mock <IRegionNavigationContentLoader>();

            targetHandlerMock.Setup(th => th.LoadContent(It.IsAny <IRegion>(), It.IsAny <INavigationContext>())).Throws <ArgumentException>();

            IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>();

            var target = new RegionNavigationService(container, targetHandlerMock.Object, journal)
            {
                Region = region
            };

            // Act
            Exception error = null;

            target.RequestNavigate(
                new Uri(otherType.GetType().Name, UriKind.Relative),
                nr =>
            {
                error = nr.Error;
            });

            // Verify
            bool isViewActive = region.ActiveViews.Contains(view);

            Assert.False(isViewActive);
            Assert.IsType <ArgumentException>(error);
        }
Exemplo n.º 25
0
        public void WhenNavigating_NavigationIsRecordedInJournal()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string regionName    = "RegionName";
            var    regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            IRegionNavigationJournalEntry journalEntry = new RegionNavigationJournalEntry();

            var containerMock = new Mock <IContainerExtension>();

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

            IContainerExtension container = containerMock.Object;
            var contentLoader             = new RegionNavigationContentLoader(container);

            var journalMock = new Mock <IRegionNavigationJournal>();

            journalMock.Setup(x => x.RecordNavigation(journalEntry, true)).Verifiable();

            IRegionNavigationJournal journal = journalMock.Object;


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

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

            // Verify
            Assert.NotNull(journalEntry);
            Assert.Equal(viewUri, journalEntry.Uri);
            journalMock.VerifyAll();
        }
        public void WhenNavigating_NavigationIsRecordedInJournal()
        {
            // Prepare
            object view    = new object();
            Uri    viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string        regionName    = "RegionName";
            RegionManager regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            IRegionNavigationJournalEntry journalEntry = new RegionNavigationJournalEntry();

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            IServiceLocator serviceLocator = serviceLocatorMock.Object;
            RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);

            var journalMock = new Mock <IRegionNavigationJournal>();

            journalMock.Setup(x => x.RecordNavigation(journalEntry)).Verifiable();

            IRegionNavigationJournal journal = journalMock.Object;


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

            target.Region = region;

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

            // Verify
            Assert.IsNotNull(journalEntry);
            Assert.AreEqual(viewUri, journalEntry.Uri);
            journalMock.VerifyAll();
        }
        public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError()
        {
            // Prepare
            object view    = new object();
            Uri    viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string otherType = "OtherType";

            var serviceLocatorMock = new Mock <IServiceLocator>();

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

            Mock <IRegionNavigationContentLoader> targetHandlerMock = new Mock <IRegionNavigationContentLoader>();

            targetHandlerMock.Setup(th => th.LoadContent(It.IsAny <IRegion>(), It.IsAny <NavigationContext>())).Throws <ArgumentException>();

            IRegionNavigationJournal journal = new Mock <IRegionNavigationJournal>().Object;

            RegionNavigationService target = new RegionNavigationService(serviceLocator, targetHandlerMock.Object, journal);

            target.Region = region;

            // Act
            Exception error = null;

            target.RequestNavigate(
                new Uri(otherType.GetType().Name, UriKind.Relative),
                nr =>
            {
                error = nr.Error;
            });

            // Verify
            bool isViewActive = region.ActiveViews.Contains(view);

            Assert.IsFalse(isViewActive);
            Assert.IsInstanceOfType(error, typeof(ArgumentException));
        }
        public void WhenNavigatingWithNullCallback_ThenThrows()
        {
            var region = new Region();

            var             navigationUri  = new Uri("/", UriKind.Relative);
            IServiceLocator serviceLocator = new Mock <IServiceLocator>().Object;
            RegionNavigationContentLoader contentLoader = new Mock <RegionNavigationContentLoader>(serviceLocator).Object;
            IRegionNavigationJournal      journal       = new Mock <IRegionNavigationJournal>().Object;

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

            target.Region = region;

            ExceptionAssert.Throws <ArgumentNullException>(
                () =>
            {
                target.RequestNavigate(navigationUri, null);
            });
        }
Exemplo n.º 29
0
        public void WhenNavigatingAndBothViewAndBindingContextImplementIRegionAware_ThenNavigatedIsInvokesOnNavigation()
        {
            // Prepare
            var region = new Region();

            var mockView             = new Mock <View>();
            var mockIRegionAwareView = mockView.As <IRegionAware>();

            mockIRegionAwareView
            .Setup(ina => ina.IsNavigationTarget(It.IsAny <INavigationContext>()))
            .Returns(true);

            var mockIRegionAwareBindingContext = new Mock <IRegionAware>();

            mockIRegionAwareBindingContext.Setup(ina => ina.IsNavigationTarget(It.IsAny <INavigationContext>())).Returns(true);
            mockView.Object.BindingContext = mockIRegionAwareBindingContext.Object;

            var view = mockView.Object;

            region.Add(view);

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

            var containerMock = new Mock <IContainerExtension>();

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

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

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

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

            // Verify
            mockIRegionAwareView.Verify(v => v.OnNavigatedTo(It.Is <INavigationContext>(nc => nc.Uri == navigationUri)));
            mockIRegionAwareBindingContext.Verify(v => v.OnNavigatedTo(It.Is <INavigationContext>(nc => nc.Uri == navigationUri)));
        }
Exemplo n.º 30
0
        //private void LoadView(object viewType)
        //{
        //    //If the view already existed then select the view.
        //    var info = ActivatedObjects.TryGet(viewType);
        //    if (info.Value != null)
        //    {
        //        SelectedElement = info.Value;
        //        return;
        //    }

        //    if (info.Key.IsNullOrEmpty()) return;

        //    var view = Container.GetInstance<object>(info.Key) as FrameworkElement;
        //    if (view == null) return;

        //    //Add and selected the view.
        //    ActivatedObjects.Add(view);
        //}

        private void CloseView(object viewObj)
        {
            var view = viewObj as FrameworkElement;

            if (view == null)
            {
                return;
            }
            RegionNavigationService.Close(view);

            //Get current index of view and selected status
            //var isSelected = ReferenceEquals(SelectedElement, view);

            //ActivatedObjects.Remove(view);

            //Select the neighbor view based on index and status if available.
            //if (ActivatedObjects.Count <= 0 || !isSelected) return;

            //SelectedElement = ActivatedObjects.LastOrDefault();
        }