public void RemoveChild (SupportView child)
		{
			if (child.Parent == this)
			{
				child.RemoveThisView();
			}
		}
		public void AddViewListener_With_Basic_View_Component_Throws_Error()
		{
			SupportView basicView = new SupportView ();
			instance.viewComponent = basicView;
			instance.Try_addViewListener (EVENT_TYPE, CALLBACK);
			logger.Verify(_logger=>_logger.Warn(It.IsAny<String>(), It.Is<object>(mediator=>mediator==instance), It.Is<object>(vc=>vc == basicView)), Times.Once);
		}
 public void RemoveChild(SupportView child)
 {
     if (child.Parent == this)
     {
         child.RemoveThisView();
     }
 }
		public void mediatedItem_is_injected_as_exact_type_into_mediator()
		{
			SupportView expected = new SupportView();
			IMediatorMapping mapping = new MediatorMapping(CreateTypeFilter(new Type[1]{ typeof(SupportView) }), typeof(ViewInjectedMediator));
			ViewInjectedMediator mediator = factory.CreateMediators(expected, typeof(SupportView), new List<IMediatorMapping> {mapping})[0] as ViewInjectedMediator;

			Assert.That(mediator.mediatedItem, Is.EqualTo(expected));
		}
		public void Setup()
		{
			injector = new RobotlegsInjector();
			manager = new MediatorManager();
			container = new SupportView ();
			container.AddThisView();
			factory = new Mock<IMediatorFactory> ();
		}
		public void Setup()
		{
			injector = new RobotlegsInjector();
			instance = new ViewProcessorMap(new ViewProcessorFactory(injector));

			mediatorWatcher = new MediatorWatcher();
			injector.Map(typeof(MediatorWatcher)).ToValue(mediatorWatcher);
			matchingView = new SupportView();
		}
		public void handler_is_called()
		{
			SupportView expected = new SupportView();
			object actual = null;
			viewManager.AddContainer(container);
			viewManager.AddViewHandler(new CallbackViewHandler(delegate(object view, Type type) {
				actual = view;
			}));
			container.AddChild(expected);
			Assert.That(actual, Is.EqualTo(expected));
		}
		public void second_view_container_is_ignored()
		{
			IContextView actual = null;
			SupportView secondView = new SupportView();
			context.Install<ContextViewExtension>().Configure(new ContextView(view), new ContextView(secondView));
			context.WhenInitializing((Action)delegate() {
				actual = context.injector.GetInstance<IContextView>();
			});
			context.Initialize();
			Assert.That(actual.view, Is.EqualTo(view));
		}
		public void Create_Mediator_Instantiates_Mediator_For_View_When_Mapped()
		{
			instance.Map(typeof(SupportView)).ToProcess(new MediatorCreator(typeof(SupportMediator)));

			SupportView objA = new SupportView();
			instance.HandleView(objA, objA.GetType());
			objA.AddThisView();

			string[] expectedNotifications = new string[1] { "SupportMediator" };
			Assert.That (expectedNotifications, Is.EquivalentTo (mediatorWatcher.Notifications));
		}
		public void Setup()
		{
			injector = new RobotlegsInjector();
			injector.Map(typeof(RobotlegsInjector)).ToValue(injector);
			viewProcessorMap = new ViewProcessorMap(new ViewProcessorFactory(injector));
			trackingProcessor = new TrackingProcessor();
			trackingProcessor2 = new TrackingProcessor();
			matchingView = new SupportView();
			nonMatchingView = new ObjectB();
			guardObject = new GuardObject();
			matchingView2 = new SupportViewWithWidthAndHeight();
		}
		public void Setup()
		{
			root = new SupportView();
			parentView = new SupportView();
			childView = new SupportView();

			parentContext = new Context()
				.Install(typeof(StageSyncExtension))
				.Install(typeof(ContextViewExtension));
			childContext = new Context()
				.Install(typeof(StageSyncExtension))
				.Install(typeof(ContextViewExtension));
		}
		public void Mediator_Is_Removed_From_Factory_When_View_Leaves_Stage()
		{
			int callCount = 0;
			object actualView = null;
			manager.ViewRemoved += (Action<object>)delegate (object eventView) {
				callCount++;
				actualView = eventView;
			};
			SupportView view = new SupportView();
			IMediatorMapping mapping = new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportView)}), typeof(CallbackMediator));
			object mediator = injector.InstantiateUnmapped(typeof(CallbackMediator));
			container.AddChild(view);
			manager.AddMediator(mediator, view, mapping);
			container.RemoveChild(view);

			Assert.That(callCount, Is.EqualTo(1));
			Assert.That(actualView, Is.EqualTo(view));
		}
		public void Runs_Destroy_On_Created_Mediator_When_Unprocess_Runs()
		{
			instance.Map(typeof(SupportView)).ToProcess(new MediatorCreator(typeof(SupportMediator)));

			SupportView view = new SupportView();
			instance.Process(view);
			instance.Unprocess(view);

			List<string> expectedNotifications = new List<string>{"SupportMediator", "SupportMediator destroy"};
			Assert.That(expectedNotifications, Is.EquivalentTo(mediatorWatcher.Notifications));
		}
		public void Setup()
		{
			context = new Context();
			contextView = new SupportView();
		}
		public void Mediator_Is_NOT_Removed_When_View_Leaves_Stage_When_AutoRemove_Is_False()
		{
			int callCount = 0;
			manager.ViewRemoved += (Action<object>)delegate (object eventView) {
				callCount++;
			};

			SupportView view = new SupportView();
			MediatorMapping mapping = new MediatorMapping(CreateTypeFilter(new Type[1] {typeof(SupportView)}), typeof(CallbackMediator));
			mapping.AutoRemove(false);
			object mediator = injector.InstantiateUnmapped(typeof(CallbackMediator));
			container.AddChild(view);
			manager.AddMediator(mediator, view, mapping);
			container.RemoveChild(view);

			Assert.That (callCount, Is.EqualTo (0));
		}
		public void removeAllMediators_removes_all_mediators_from_manager()
		{
			SupportView mediatedItem1 = new SupportView();
			SupportView mediatedItem2 = new SupportView();
			IMediatorMapping mapping1 =
				new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportView)}), typeof(CallbackMediator));
			IMediatorMapping mapping2 =
				new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportContainer)}), typeof(ViewInjectedAsRequestedMediator));

			injector.Map<IMediatorManager> ().ToValue (manager.Object);
			factory = new MediatorFactory (injector);
			factory.CreateMediators (mediatedItem1, typeof(SupportView), new List<IMediatorMapping>{ mapping1, mapping2 });
			factory.CreateMediators (mediatedItem2, typeof(SupportView), new List<IMediatorMapping>{ mapping1, mapping2 });
			factory.RemoveAllMediators();

			manager.Verify(_manager=>_manager.RemoveMediator(
				It.IsAny<CallbackMediator>(),
				It.Is<object>(arg2=>arg2==mediatedItem1),
				It.Is<IMediatorMapping>(arg3=>arg3==mapping1)), Times.Once);

			manager.Verify(_manager=>_manager.RemoveMediator(
				It.IsAny<ViewInjectedAsRequestedMediator>(),
				It.Is<object>(arg2=>arg2==mediatedItem1),
				It.Is<IMediatorMapping>(arg3=>arg3==mapping2)), Times.Once);

			manager.Verify(_manager=>_manager.RemoveMediator(
				It.IsAny<CallbackMediator>(),
				It.Is<object>(arg2=>arg2==mediatedItem2),
				It.Is<IMediatorMapping>(arg3=>arg3==mapping1)), Times.Once);

			manager.Verify(_manager=>_manager.RemoveMediator(
				It.IsAny<ViewInjectedAsRequestedMediator>(),
				It.Is<object>(arg2=>arg2==mediatedItem2),
				It.Is<IMediatorMapping>(arg3=>arg3==mapping2)), Times.Once);
		}
		public void removeMediator_removes_mediator_from_manager()
		{
			SupportView mediatedItem = new SupportView();
			IMediatorMapping mapping =
				new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportView)}), typeof(CallbackMediator));

			injector.Map<IMediatorManager> ().ToValue (manager.Object);
			factory = new MediatorFactory(injector);
			factory.CreateMediators(mediatedItem, typeof(SupportView), new List<IMediatorMapping> {mapping});
			factory.RemoveMediators(mediatedItem);
			factory.RemoveMediators(mediatedItem);

			manager.Verify (_manager => _manager.RemoveMediator (It.IsAny<CallbackMediator> (), It.Is<object> (arg2 => arg2 == mediatedItem), It.Is<IMediatorMapping> (arg3 => arg3 == mapping)), Times.Once);
		}
		public void removeMediator() 
		{
			SupportView mediatedItem = new SupportView();
			IMediatorMapping mapping =
				new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportView)}), typeof(CallbackMediator));

			factory.CreateMediators(mediatedItem, typeof(SupportView), new List<IMediatorMapping> {mapping});
			factory.RemoveMediators(mediatedItem);

			Assert.That (factory.GetMediator (mediatedItem, mapping), Is.Null);
		}
		public void runs_destroy_on_created_mediator_when_unmediate_runs()
		{
			mediatorMap.Map(typeof(SupportView)).ToMediator(typeof(ExampleMediatorWatcher));

			SupportView view = new SupportView();
			mediatorMap.Mediate(view);
			mediatorMap.Unmediate(view);

			List<string> expectedNotifications = new List<string>{"ExampleMediatorWatcher", "ExampleMediatorWatcher destroy"};
			Assert.That (expectedNotifications, Is.EqualTo (mediatorWatcher.Notifications).AsCollection);
		}
		public void hook_receives_mediator_and_mediatedItem()
		{
			SupportView mediatedItem = new SupportView();
			object injectedMediator = null;
			object injectedView = null;
			injector.Map(typeof(Action<MediatorHook>), "callback").ToValue((Action<MediatorHook>)delegate(MediatorHook hook) {
				injectedMediator = hook.mediator;
				injectedView = hook.mediatedItem;
			});

			MediatorMapping mapping = new MediatorMapping(CreateTypeFilter(
				new Type[1]{ typeof(SupportView) }), 
				typeof(ViewInjectedMediator));

			mapping.WithHooks(typeof(MediatorHook));

			factory.CreateMediators(mediatedItem, typeof(SupportView), new List<IMediatorMapping> {mapping});

			Assert.That(injectedMediator, Is.InstanceOf<ViewInjectedMediator>());
			Assert.That(injectedView, Is.EqualTo(mediatedItem));
		}
		public void handler_is_not_called_after_container_removal()
		{
			int callCount = 0;
			viewManager.AddContainer(container);
			viewManager.AddViewHandler(new CallbackViewHandler(delegate(object view, Type type) {
				callCount++;
			}));
			viewManager.RemoveContainer(container);
			SupportView supportView = new SupportView();
			container.AddChild(supportView);
			Assert.That(callCount, Is.EqualTo(0));
		}
		public void handlers_are_called()
		{
			List<object> expected = new List<object> {"handler1", "handler2", "handler3"};
			List<object> actual = new List<object>();
			viewManager.AddContainer(container);
			viewManager.AddViewHandler(new CallbackViewHandler(delegate(object view, Type type) {
				actual.Add("handler1");
			}));
			viewManager.AddViewHandler(new CallbackViewHandler(delegate(object view, Type type) {
				actual.Add("handler2");
			}));
			viewManager.AddViewHandler(new CallbackViewHandler(delegate(object view, Type type) {
				actual.Add("handler3");
			}));
			SupportView supportView = new SupportView();
			container.AddChild(supportView);
			Assert.That(actual, Is.EqualTo(expected).AsCollection);
		}
		public void Setup()
		{
			context = new Context().Install(typeof(TestSupportViewStateWatcherExtension));
			contextViewObject = new SupportView ();
		}
		public void adding_fallback_should_be_found_as_parent()
		{
			object fallback = new object ();
			registry.SetFallbackContainer (fallback);
			object newView = new SupportView ();
			ContainerBinding parentBinding = registry.FindParentBinding (newView);
			Assert.That (parentBinding.Container, Is.EqualTo (fallback));
		}
		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));
		}
		public void multiple_mappings_per_matcher_destroy_mediators()
		{
			mediatorMap.Map(typeof(SupportView)).ToMediator(typeof(ExampleMediatorWatcher));
			mediatorMap.Map(typeof(SupportView)).ToMediator(typeof(ExampleMediatorWatcher2));

			SupportView view = new SupportView();

			mediatorMap.Mediate(view);
			mediatorMap.Unmediate(view);

			List<string> expectedNotifications = new List<string> {"ExampleMediatorWatcher", "ExampleMediatorWatcher2", "ExampleMediatorWatcher destroy", "ExampleMediatorWatcher2 destroy"};
			
			Assert.That (expectedNotifications, Is.EqualTo (mediatorWatcher.Notifications).AsCollection);
		}
		public void expected_number_of_mediators_are_returned_for_mappings_and_mediatedItem()
		{
			SupportView mediatedItem = new SupportView();
			MediatorMapping mapping1 =
				new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportView)}), typeof(ViewInjectedMediator));
			MediatorMapping mapping2 =
				new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportContainer)}), typeof(ViewInjectedAsRequestedMediator));
			List<object> mediators = factory.CreateMediators(mediatedItem, typeof(SupportView), new List<IMediatorMapping> {mapping1, mapping2});
			Assert.That(mediators.Count, Is.EqualTo(2));
		}
		public void only_one_mediator_created_if_identical_mapping_duplicated()
		{
			mediatorMap.Map(typeof(SupportView)).ToMediator(typeof(ExampleMediatorWatcher)).WithGuards(typeof(HappyGuard)).WithHooks(typeof(AddChildHook));
			mediatorMap.Map(typeof(SupportView)).ToMediator(typeof(ExampleMediatorWatcher)).WithGuards(typeof(HappyGuard)).WithHooks(typeof(AddChildHook));

			SupportView view = new SupportView ();
			mediatorMap.Mediate(view);
			List<string> expectedNotifications = new List<string> {"ExampleMediatorWatcher"};
			Assert.That (expectedNotifications, Is.EqualTo (mediatorWatcher.Notifications).AsCollection);
			Assert.That (view.NumChildren, Is.EqualTo (1));
		}
		public void no_mediator_is_created_if_guard_prevents_it()
		{
			mediatorMap.Map(typeof(SupportView)).ToMediator(typeof(ExampleMediatorWatcher)).WithGuards(typeof(OnlyIfViewHasChildrenGuard));
			SupportView view = new SupportView();
			mediatorMap.Mediate(view);

			List<string> expectedNotifications = new List<string>();
			Assert.That (expectedNotifications, Is.EqualTo (mediatorWatcher.Notifications).AsCollection);
		}
		public void RunAllUnprocessors_Runs_All_Unprocessors_For_All_Views()
		{
			TrackingProcessor trackingProcessor2 = new TrackingProcessor();

			SupportView view = new SupportView();
			ObjectWhichExtendsSupportView viewA = new ObjectWhichExtendsSupportView();

			ViewProcessorMapping mapping = new ViewProcessorMapping(new TypeMatcher().AllOf(view.GetType()).CreateTypeFilter(), trackingProcessor);
			ViewProcessorMapping mappingA = new ViewProcessorMapping(new TypeMatcher().AllOf(viewA.GetType()).CreateTypeFilter(), trackingProcessor2);

			viewProcessorFactory.RunProcessors(view, view.GetType(), new ViewProcessorMapping[1] {mapping});
			viewProcessorFactory.RunProcessors(viewA, viewA.GetType(), new ViewProcessorMapping[2] {mapping, mappingA});

			viewProcessorFactory.RunAllUnprocessors();

			Assert.That (trackingProcessor.UnprocessedViews, Is.EquivalentTo (new object[2]{ view, viewA }), "trackingProcessor unprocessed all views");
			Assert.That (trackingProcessor2.UnprocessedViews, Is.EquivalentTo (new object[1]{ viewA }), "trackingProcessor2 unprocessed all views");
		}
		public void Mediator_For_UIComponent_Is_Initialized()
		{
			SupportView view = new SupportView ();
			IMediatorMapping mapping = new MediatorMapping(CreateTypeFilter(new Type[1]{typeof(SupportView)}), typeof(LifecycleReportingMediator));
			LifecycleReportingMediator mediator = injector.InstantiateUnmapped(typeof(LifecycleReportingMediator)) as LifecycleReportingMediator;

			factory.Setup (f => f.GetMediator (It.IsAny<object> (), It.IsAny<IMediatorMapping>())).Returns(mediator);
			Assert.That (mediator.initialized, Is.False);
			manager.AddMediator(mediator, view, mapping);
			container.AddChild (view);

			Assert.That (mediator.initialized, Is.True);
		}