public void Test_Set_Registry()
        {
            ContainerRegistry cr = new ContainerRegistry();

            ViewNotifier.SetRegistry(cr);
            Assert.That(ViewNotifier.Registry, Is.EqualTo(cr));
        }
Esempio n. 2
0
 public void before()
 {
     container = new SupportContainer();
     registry  = new ContainerRegistry();
     registry.SetParentFinder(new SupportParentFinder());
     viewManager = new ViewManager(registry);
     ViewNotifier.SetRegistry(registry);
 }
		public void before()
		{
			container = new SupportContainer ();
			registry = new ContainerRegistry();
			registry.SetParentFinder (new SupportParentFinder ());
			viewManager = new ViewManager(registry);
			ViewNotifier.SetRegistry (registry);
		}
		/*============================================================================*/
		/* Private Functions                                                          */
		/*============================================================================*/

		private void AfterInitializing()
		{
			_containerRegistry = _injector.GetInstance(typeof(ContainerRegistry)) as ContainerRegistry;
			if (!_injector.HasDirectMapping (typeof(IStageCrawler)))
			{
				_logger.Warn ("No CrawlerConfig configured. Make sure to configure a platform specific stage crawler config, or don't install the StageCrawler extension");
				return;
			}
			if(_injector.HasDirectMapping(typeof(IViewManager)))
			{
				ScanViewManagedContainers();
			}
			else
			{
				ScanContextView();
			}
		}
		public void Test_Register_View_Calls_View_Handler()
		{
			object expectedView = null;
			Type expectedType = null;
			object actualView = new object ();
			Type actualType = actualView.GetType ();

			ContainerRegistry cr = new ContainerRegistry ();
			ViewNotifier.SetRegistry (cr);
			object container = new object ();
			cr.SetFallbackContainer (container);
			cr.GetBinding (container).AddHandler (new CallbackViewHandler (delegate(object view, Type type)
			{
				expectedType = type;
				expectedView = view;
			}));
			ViewNotifier.RegisterView (actualView);

			Assert.That (actualView, Is.EqualTo (expectedView));
			Assert.That (actualType, Is.EqualTo (expectedType));
		}
        public void Test_Register_View_Calls_View_Handler()
        {
            object expectedView = null;
            Type   expectedType = null;
            object actualView   = new object();
            Type   actualType   = actualView.GetType();

            ContainerRegistry cr = new ContainerRegistry();

            ViewNotifier.SetRegistry(cr);
            object container = new object();

            cr.SetFallbackContainer(container);
            cr.GetBinding(container).AddHandler(new CallbackViewHandler(delegate(object view, Type type)
            {
                expectedType = type;
                expectedView = view;
            }));
            ViewNotifier.RegisterView(actualView);

            Assert.That(actualView, Is.EqualTo(expectedView));
            Assert.That(actualType, Is.EqualTo(expectedType));
        }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend (IContext context)
		{
			context.WhenInitializing(WhenInitializing);
			context.WhenDestroying(WhenDestroying);

			_injector = context.injector;

			// Just one Container Registry
			if (_containerRegistry == null)
			{
				_containerRegistry = new ContainerRegistry ();
				ViewNotifier.SetRegistry (_containerRegistry);
			}
			_injector.Map(typeof(ContainerRegistry)).ToValue(_containerRegistry);
			if(_injector.HasDirectMapping(typeof(IParentFinder)))
			{
				_injector.Unmap (typeof(IParentFinder));
			}
			_injector.Map(typeof(IParentFinder)).ToValue(_containerRegistry);

			// But you get your own View Manager
			_injector.Map(typeof(IViewManager)).ToSingleton(typeof(ViewManager));
		}
		/*============================================================================*/
		/* Public Static Functions                                                    */
		/*============================================================================*/

		public static void SetRegistry(ContainerRegistry containerRegistry)
		{
			_registry = containerRegistry;
		}
		public void Context_Inherits_Parent_Injector()
		{
			AddRootToStage();

			parentContext
				.Install (typeof(SupportParentFinderExtension))
				.Install(typeof(TestSupportViewStateWatcherExtension))
				.Install (typeof(ModularityExtension))
				.Configure(new ContextView(parentView));

			childContext
				.Install (typeof(ModularityExtension))
				.Install (typeof(SupportParentFinderExtension))
				.Install (typeof(TestSupportViewStateWatcherExtension))
				.Configure (new ContextView (childView));

			ContainerRegistry cr = new ContainerRegistry();
			cr.SetParentFinder (new SupportParentFinder ());

			parentContext.injector.Map(typeof(ContainerRegistry)).ToValue(cr);
			childContext.injector.Map(typeof(ContainerRegistry)).ToValue(cr);

			cr.AddContainer(parentView);
			cr.AddContainer(childView);

			root.AddChild(parentView);
			parentView.AddChild (childView);

			Assert.That (childContext.injector.parent, Is.EqualTo (parentContext.injector));
		}
		public void Multiple_Depths_Of_Children_Only_Inherit_The_First_Parents_Injector()
		{
			AddRootToStage();

			parentContext
				.Install (typeof(SupportParentFinderExtension))
				.Install(typeof(TestSupportViewStateWatcherExtension))
				.Install (typeof(ModularityExtension))
				.Configure(new ContextView(parentView));

			childContext
				.Install (typeof(ModularityExtension))
				.Install (typeof(SupportParentFinderExtension))
				.Install (typeof(TestSupportViewStateWatcherExtension))
				.Configure (new ContextView (childView));


			SupportView anotherChildView = new SupportView ();
			IContext anotherChildContext = new Context()
				.Install (typeof(StageSyncExtension))
				.Install (typeof(ContextViewExtension))
				.Install (typeof(ModularityExtension))
				.Install (typeof(SupportParentFinderExtension))
				.Install (typeof(TestSupportViewStateWatcherExtension))
				.Configure (new ContextView (anotherChildView));


			ContainerRegistry cr = new ContainerRegistry();
			parentContext.injector.Map(typeof(ContainerRegistry)).ToValue(cr);
			childContext.injector.Map(typeof(ContainerRegistry)).ToValue(cr);
			anotherChildContext.injector.Map(typeof(ContainerRegistry)).ToValue(cr);

			cr.AddContainer(parentView);
			cr.AddContainer(childView);
			cr.AddContainer(anotherChildView);

			root.AddChild (parentView);
			parentView.AddChild (childView);
			childView.AddChild (anotherChildView);

			Assert.That (childContext.injector.parent, Is.EqualTo (parentContext.injector));
			Assert.That (anotherChildContext.injector.parent, Is.EqualTo (childContext.injector));
			Assert.That (anotherChildContext.injector.parent, Is.Not.EqualTo (parentContext.injector));
		}
Esempio n. 11
0
        /*============================================================================*/
        /* Constructor                                                                */
        /*============================================================================*/

        public ViewManager(ContainerRegistry containerRegistry)
        {
            _registry = containerRegistry;
        }
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		public ViewManager(ContainerRegistry containerRegistry)
		{
			_registry = containerRegistry;
		}
		public void Test_Set_Registry()
		{
			ContainerRegistry cr = new ContainerRegistry ();
			ViewNotifier.SetRegistry (cr);
			Assert.That (ViewNotifier.Registry, Is.EqualTo(cr));
		}
		public void before()
		{
			registry = new ContainerRegistry();
			registry.SetParentFinder (new SupportParentFinder());
			container = new SupportContainer();
		}
 public void before()
 {
     registry = new ContainerRegistry();
     registry.SetParentFinder(new SupportParentFinder());
     container = new SupportContainer();
 }