public void WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsidered()
        {
            // Arrange

            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var view1 = new TestView();
            var view2 = "view";

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

            var navigationContext = new NavigationContext(null, new Uri(view2.GetType().FullName, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view2, returnedView);
        }
        public void WhenNoCurrentMatchingViewExists_ThenReturnsNewlyCreatedInstanceWithServiceLocatorAddedToTheRegion()
        {
            // Arrange

            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var view = new TestView();

            serviceLocatorMock
                .Setup(sl => sl.GetInstance<object>(view.GetType().Name))
                .Returns(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);

            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);

            // Assert

            Assert.AreSame(view, returnedView);
            Assert.IsTrue(region.Views.Contains(view));
        }
        public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView()
        {
            // Arrange

            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var view = new TestView();

            region.Add(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view, returnedView);
        }
Exemple #4
0
        public void WhenViewExistsAndHasDataContextThatImplementsIRegionAware_ThenDataContextIsQueriedForNavigationAndIsReturnedIfAcceptsIt()
        {
            // Arrange

            var containerMock = new Mock <IContainerExtension>();

            var region = new Region();

            var bindingContextMock = new Mock <IRegionAware>();

            bindingContextMock
            .Setup(v => v.IsNavigationTarget(It.IsAny <INavigationContext>()))
            .Returns(true)
            .Verifiable();
            var viewMock = new Mock <View>();

            viewMock.Object.BindingContext = bindingContextMock.Object;

            region.Add(viewMock.Object);

            var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.Same(viewMock.Object, returnedView);
            bindingContextMock.VerifyAll();
        }
        public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDataContextIsQueriedForNavigationAndIsReturnedIfAcceptsIt()
        {
            // Arrange

            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var dataContextMock = new Mock <INavigationAware>();

            dataContextMock
            .Setup(v => v.IsNavigationTarget(It.IsAny <NavigationContext>()))
            .Returns(true)
            .Verifiable();
            var viewMock = new Mock <FrameworkElement>();

            viewMock.Object.DataContext = dataContextMock.Object;

            region.Add(viewMock.Object);

            var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(viewMock.Object, returnedView);
            dataContextMock.VerifyAll();
        }
        public void WhenNoCurrentMatchingViewExists_ThenReturnsNewlyCreatedInstanceWithServiceLocatorAddedToTheRegion()
        {
            // Arrange

            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var view = new TestView();

            serviceLocatorMock
            .Setup(sl => sl.GetInstance <object>(view.GetType().Name))
            .Returns(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view, returnedView);
            Assert.IsTrue(region.Views.Contains(view));
        }
        public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView()
        {
            // Arrange

            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var view = new TestView();

            region.Add(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view, returnedView);
        }
Exemple #8
0
        public void WhenViewAddedByHandlerDoesNotImplementIRegionAware_ThenReturnsView()
        {
            // Arrange
            var containerMock = new Mock <IContainerExtension>();

            var region = new Region();

            var view = new Grid();

            containerMock.Setup(x => x.Resolve(typeof(object), view.GetType().Name)).Returns(view);
            containerMock.Setup(x => x.Resolve(typeof(IActiveRegionHelper)))
            .Returns(new RegionResolverOverrides());

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);

            // Act
            var firstReturnedView  = navigationTargetHandler.LoadContent(region, navigationContext);
            var secondReturnedView = navigationTargetHandler.LoadContent(region, navigationContext);

            // Assert
            Assert.Same(view, firstReturnedView);
            Assert.Same(view, secondReturnedView);
            containerMock.Verify(sl => sl.Resolve(typeof(object), view.GetType().Name), Times.Once());
        }
Exemple #9
0
        public void WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsidered()
        {
            // Arrange

            var containerMock = new Mock <IContainerExtension>();

            //containerMock.As<IContainerInfo>()
            //    .Setup(x => x.GetRegistrationType("Xamarin.Forms.Grid"))
            //    .Returns(typeof(Grid));

            containerMock.Setup(x => x.Resolve(typeof(IActiveRegionHelper)))
            .Returns(new RegionResolverOverrides());

            var region = new Region();

            var view1 = new TestView();
            var view2 = new Grid();

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

            var navigationContext = new NavigationContext(null, new Uri(view2.GetType().FullName, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.Same(view2, returnedView);
        }
        public void WhenViewAddedByHandlerDoesNotImplementINavigationAware_ThenReturnsView()
        {
            // Arrange

            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var view = new TestView();

            serviceLocatorMock
            .Setup(sl => sl.GetInstance <object>(view.GetType().Name))
            .Returns(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var firstReturnedView  = navigationTargetHandler.LoadContent(region, navigationContext);
            var secondReturnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view, firstReturnedView);
            Assert.AreSame(view, secondReturnedView);
            serviceLocatorMock.Verify(sl => sl.GetInstance <object>(view.GetType().Name), Times.Once());
        }
Exemple #11
0
        public void WhenNoCurrentMatchingViewExists_ThenReturnsNewlyCreatedInstanceWithServiceLocatorAddedToTheRegion()
        {
            // Arrange

            var containerMock = new Mock <IContainerExtension>();

            var region = new Region();

            var view = new TestView();

            containerMock.Setup(sl => sl.Resolve(typeof(object), view.GetType().Name)).Returns(view);
            containerMock.Setup(x => x.Resolve(typeof(IActiveRegionHelper)))
            .Returns(new RegionResolverOverrides());

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.Same(view, returnedView);
            Assert.True(region.Views.Contains(view));
        }
Exemple #12
0
        public void WhenViewExistsAndDoesNotImplementIRegionAware_ThenReturnsView()
        {
            // Arrange

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IActiveRegionHelper)))
            .Returns(new RegionResolverOverrides());

            var region = new Region();

            var view = new TestView();

            region.Add(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.Same(view, returnedView);
        }
        public void WhenRegionHasMultipleViews_ThenViewsWithMatchingTypeNameAreConsidered()
        {
            // Arrange

            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var view1 = new TestView();
            var view2 = "view";

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

            var navigationContext = new NavigationContext(null, new Uri(view2.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view2, returnedView);
        }
        public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDataContextIsQueriedForNavigationAndNewInstanceIsCreatedIfItRejectsIt()
        {
            // Arrange
            var containerMock = new Mock <IContainerExtension>();

            var region = new Region();

            var dataContextMock = new Mock <INavigationAware>();

            dataContextMock
            .Setup(v => v.IsNavigationTarget(It.IsAny <NavigationContext>()))
            .Returns(false)
            .Verifiable();
            var viewMock = new Mock <FrameworkElement>();

            viewMock.Object.DataContext = dataContextMock.Object;

            region.Add(viewMock.Object);

            var newView = new TestView();

            containerMock.Setup(sl => sl.Resolve(typeof(object), viewMock.Object.GetType().Name)).Returns(newView);

            var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);

            // Act
            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);

            // Assert
            Assert.Same(newView, returnedView);
            Assert.True(region.Views.Contains(newView));
            dataContextMock.VerifyAll();
        }
        public void WhenRequestingContentForNullContext_ThenThrows()
        {
            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            ExceptionAssert.Throws <ArgumentNullException>(
                () =>
            {
                navigationTargetHandler.LoadContent(region, null);
            });
        }
        public void WhenRequestingContentForNullRegion_ThenThrows()
        {
            var serviceLocatorMock = new Mock <IServiceLocator>();

            var navigationContext = new NavigationContext(null, new Uri("/", UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            ExceptionAssert.Throws <ArgumentNullException>(
                () =>
            {
                navigationTargetHandler.LoadContent(null, navigationContext);
            });
        }
        public void WhenViewCannotBeCreated_ThenThrowsAnException()
        {
            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(sl => sl.Resolve(typeof(object), typeof(TestView).Name)).Throws <ActivationException>();

            var region = new Region();

            var navigationContext = new NavigationContext(null, new Uri(typeof(TestView).Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);

            // Act

            ExceptionAssert.Throws <InvalidOperationException>(
                () =>
            {
                navigationTargetHandler.LoadContent(region, navigationContext);
            });
        }
Exemple #18
0
        public void WhenViewCannotBeCreated_ThenThrowsAnException()
        {
            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(object), typeof(TestView).Name))
            .Throws(new ContainerResolutionException(typeof(object), typeof(TestView).Name, null));
            containerMock.Setup(x => x.Resolve(typeof(IActiveRegionHelper)))
            .Returns(new RegionResolverOverrides());

            var region = new Region();

            var navigationContext = new NavigationContext(null, new Uri(typeof(TestView).Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object);

            // Act
            var ex = Record.Exception(() => navigationTargetHandler.LoadContent(region, navigationContext));

            Assert.IsType <ContainerResolutionException>(ex);
        }
        public void WhenViewExistsAndImplementsINavigationAware_ThenViewIsQueriedForNavigationAndNewInstanceIsCreatedIfItRejectsIt()
        {
            // Arrange

            var serviceLocatorMock = new Mock <IServiceLocator>();

            var region = new Region();

            var viewMock = new Mock <INavigationAware>();

            viewMock
            .Setup(v => v.IsNavigationTarget(It.IsAny <NavigationContext>()))
            .Returns(false)
            .Verifiable();

            region.Add(viewMock.Object);

            var newView = new TestView();

            serviceLocatorMock
            .Setup(sl => sl.GetInstance <object>(viewMock.Object.GetType().Name))
            .Returns(newView);

            var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(newView, returnedView);
            Assert.IsTrue(region.Views.Contains(newView));
            viewMock.VerifyAll();
        }
        public void WhenViewCannotBeCreated_ThenThrowsAnException()
        {
            var serviceLocatorMock = new Mock <IServiceLocator>();

            serviceLocatorMock
            .Setup(sl => sl.GetInstance <object>(typeof(TestView).Name))
            .Throws <ActivationException>();

            var region = new Region();

            var navigationContext = new NavigationContext(null, new Uri(typeof(TestView).Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            ExceptionAssert.Throws <InvalidOperationException>(
                () =>
            {
                navigationTargetHandler.LoadContent(region, navigationContext);
            });
        }
        public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDataContextIsQueriedForNavigationAndIsReturnedIfAcceptsIt()
        {
            // Arrange

            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var dataContextMock = new Mock<INavigationAware>();
            dataContextMock
                .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
                .Returns(true)
                .Verifiable();
            var viewMock = new Mock<FrameworkElement>();
            viewMock.Object.DataContext = dataContextMock.Object;

            region.Add(viewMock.Object);

            var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(viewMock.Object, returnedView);
            dataContextMock.VerifyAll();
        }
        public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDataContextIsQueriedForNavigationAndNewInstanceIsCreatedIfItRejectsIt()
        {
            // Arrange

            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var dataContextMock = new Mock<INavigationAware>();
            dataContextMock
                .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>()))
                .Returns(false)
                .Verifiable();
            var viewMock = new Mock<FrameworkElement>();
            viewMock.Object.DataContext = dataContextMock.Object;

            region.Add(viewMock.Object);

            var newView = new TestView();

            serviceLocatorMock
                .Setup(sl => sl.GetInstance<object>(viewMock.Object.GetType().Name))
                .Returns(newView);

            var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(newView, returnedView);
            Assert.IsTrue(region.Views.Contains(newView));
            dataContextMock.VerifyAll();
        }
        public void WhenViewCannotBeCreated_ThenThrowsAnException()
        {
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock
                .Setup(sl => sl.GetInstance<object>(typeof(TestView).Name))
                .Throws<ActivationException>();

            var region = new Region();

            var navigationContext = new NavigationContext(null, new Uri(typeof(TestView).Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            ExceptionAssert.Throws<InvalidOperationException>(
                () =>
                {
                    navigationTargetHandler.LoadContent(region, navigationContext);

                });
        }
        public void WhenRequestingContentForNullContext_ThenThrows()
        {
            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            ExceptionAssert.Throws<ArgumentNullException>(
                () =>
                {
                    navigationTargetHandler.LoadContent(region, null);

                });
        }
        public void WhenViewAddedByHandlerDoesNotImplementINavigationAware_ThenReturnsView()
        {
            // Arrange

            var serviceLocatorMock = new Mock<IServiceLocator>();

            var region = new Region();

            var view = new TestView();

            serviceLocatorMock
                .Setup(sl => sl.GetInstance<object>(view.GetType().Name))
                .Returns(view);

            var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            // Act

            var firstReturnedView = navigationTargetHandler.LoadContent(region, navigationContext);
            var secondReturnedView = navigationTargetHandler.LoadContent(region, navigationContext);


            // Assert

            Assert.AreSame(view, firstReturnedView);
            Assert.AreSame(view, secondReturnedView);
            serviceLocatorMock.Verify(sl => sl.GetInstance<object>(view.GetType().Name), Times.Once());
        }
        public void WhenRequestingContentForNullRegion_ThenThrows()
        {
            var serviceLocatorMock = new Mock<IServiceLocator>();

            var navigationContext = new NavigationContext(null, new Uri("/", UriKind.Relative));

            var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);


            ExceptionAssert.Throws<ArgumentNullException>(
                () =>
                {
                    navigationTargetHandler.LoadContent(null, navigationContext);

                });
        }