Example #1
0
        public void TestChildGetsFromParent()
        {
            parent.RegisterComponentImplementation(typeof(SimpleTouchable));
            child.RegisterComponentImplementation(typeof(DependsOnTouchable));
            DependsOnTouchable dependsOnTouchable =
                (DependsOnTouchable)child.GetComponentInstance(typeof(DependsOnTouchable));

            Assert.IsNotNull(dependsOnTouchable);
        }
		public void DefaultPicoContainerReturnsNewInstanceForEachCallWhenUsingTransientIComponentAdapter()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			picoContainer.RegisterComponentImplementation(typeof (Service));
			picoContainer.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof (TransientComponent), typeof (TransientComponent)));
			TransientComponent c1 = (TransientComponent) picoContainer.GetComponentInstance(typeof (TransientComponent));
			TransientComponent c2 = (TransientComponent) picoContainer.GetComponentInstance(typeof (TransientComponent));
			Assert.IsFalse(c1.Equals(c2));
			Assert.AreSame(c1.service, c2.service);
		}
Example #3
0
        public void DefaultPicoContainerReturnsNewInstanceForEachCallWhenUsingTransientIComponentAdapter()
        {
            DefaultPicoContainer picoContainer = new DefaultPicoContainer();

            picoContainer.RegisterComponentImplementation(typeof(Service));
            picoContainer.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof(TransientComponent)));
            TransientComponent c1 = (TransientComponent)picoContainer.GetComponentInstance(typeof(TransientComponent));
            TransientComponent c2 = (TransientComponent)picoContainer.GetComponentInstance(typeof(TransientComponent));

            Assert.IsFalse(c1.Equals(c2));
            Assert.AreSame(c1.service, c2.service);
        }
Example #4
0
        public void ReplacedInstantiatedComponentHasCorrectClass()
        {
            IComponentAdapter componentAdapter = CreateComponentAdapter();

            picoContainer.RegisterComponent(componentAdapter);
            object o = picoContainer.ComponentInstances;

            picoContainer.UnregisterComponent(typeof(ITouchable));

            picoContainer.RegisterComponentImplementation(typeof(ITouchable), typeof(AlternativeTouchable));
            object component = picoContainer.GetComponentInstance(typeof(ITouchable));

            Assert.AreEqual(typeof(AlternativeTouchable), component.GetType());
        }
        public void InstantiationExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption()
        {
            DefaultPicoContainer picoContainer = new DefaultPicoContainer();

            picoContainer.RegisterComponentImplementation(typeof(InstantiationExceptionThrowing));
            picoContainer.GetComponentInstance(typeof(InstantiationExceptionThrowing));
        }
        protected virtual IPicoContainer WrapComponentInstances(Type decoratingComponentAdapterClass,
                                                                IPicoContainer picoContainer,
                                                                object[] wrapperDependencies)
        {
            Assert.IsTrue(typeof (DecoratingComponentAdapter).IsAssignableFrom(decoratingComponentAdapterClass));
            IMutablePicoContainer mutablePicoContainer = new DefaultPicoContainer();
            int size = (wrapperDependencies != null ? wrapperDependencies.Length : 0) + 1;
            ICollection allComponentAdapters = picoContainer.ComponentAdapters;

            foreach (object adapter in allComponentAdapters)
            {
                IParameter[] parameters = new IParameter[size];
                parameters[0] = new ConstantParameter(adapter);
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = new ConstantParameter(wrapperDependencies[i - 1]);
                }
                IMutablePicoContainer instantiatingPicoContainer =
                    new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
                instantiatingPicoContainer.RegisterComponentImplementation("decorator", decoratingComponentAdapterClass,
                                                                           parameters);
                mutablePicoContainer.RegisterComponent(
                    (IComponentAdapter) instantiatingPicoContainer.GetComponentInstance("decorator"));
            }
            return mutablePicoContainer;
        }
Example #7
0
        public void TestCollections()
        {
            IMutablePicoContainer mpc = new DefaultPicoContainer();

            IParameter[] parameters = new IParameter[]
            {
                new ComponentParameter(typeof(Cod), false),
                new ComponentParameter(typeof(Fish), false)
            };

            mpc.RegisterComponentImplementation(typeof(CollectedBowl), typeof(CollectedBowl), parameters);
            mpc.RegisterComponentImplementation(typeof(Cod));
            mpc.RegisterComponentImplementation(typeof(Shark));
            Cod           cod  = (Cod)mpc.GetComponentInstanceOfType(typeof(Cod));
            CollectedBowl bowl = (CollectedBowl)mpc.GetComponentInstance(typeof(CollectedBowl));

            Assert.AreEqual(1, bowl.cods.Length);
            Assert.AreEqual(2, bowl.fishes.Length);
            Assert.AreSame(cod, bowl.cods[0]);

            try
            {
                Assert.AreSame(bowl.fishes[0], bowl.fishes[1]);
                Assert.Fail("The fishes should not be the same");
            }
            catch (AssertionException)
            {
            }
        }
Example #8
0
        public void ThangCanBeInstantiatedWithArrayList()
        {
            IMutablePicoContainer pico = new DefaultPicoContainer();

            pico.RegisterComponentImplementation(typeof(Thingie));
            pico.RegisterComponentImplementation(typeof(ArrayList));
            Assert.IsNotNull(pico.GetComponentInstance(typeof(Thingie)));
        }
Example #9
0
        public void TestUnregisterAfterInstantiateComponents()
        {
            picoContainer.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable));
            object o = picoContainer.ComponentInstances;

            picoContainer.UnregisterComponent(typeof(ITouchable));
            Assert.IsNull(picoContainer.GetComponentInstance(typeof(ITouchable)));
        }
        public void ShouldBeAbleToInstantiateNonPublicClassesWithNonPublicConstructors()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory(true));

            pico.RegisterComponentImplementation(typeof(Private));
            pico.RegisterComponentImplementation(typeof(NotYourBusiness));
            Assert.IsNotNull(pico.GetComponentInstance(typeof(NotYourBusiness)));
        }
		public void ComponentParameterExcludesSelf()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			IComponentAdapter adapter = pico.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

			Assert.IsNotNull(pico.GetComponentInstance(typeof (ITouchable)));
			ITouchable touchable = (ITouchable) ComponentParameter.DEFAULT.ResolveInstance(pico, adapter, typeof (ITouchable));
			Assert.IsNull(touchable);
		}
        public void ShouldNotConsiderNonPublicConstructors()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();

            pico.RegisterComponentImplementation(typeof(Component201));
            pico.RegisterComponentInstance(2);
            pico.RegisterComponentInstance(true);
            pico.RegisterComponentInstance("Hello");
            Assert.IsNotNull(pico.GetComponentInstance(typeof(Component201)));
        }
        public void ComponentParameterFetches()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();
            pico.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));
            ComponentParameter parameter = new ComponentParameter(typeof (ITouchable));

            Assert.IsNotNull(pico.GetComponentInstance(typeof (ITouchable)));
            ITouchable touchable = (ITouchable) parameter.ResolveInstance(pico, null, typeof (ITouchable));
            Assert.IsNotNull(touchable);
        }
		public void ResolveFromParentByType()
		{
			IMutablePicoContainer parent = new DefaultPicoContainer();
			parent.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

			IMutablePicoContainer child = new DefaultPicoContainer(parent);
			child.RegisterComponentImplementation(typeof (DependsOnTouchable));

			Assert.IsNotNull(child.GetComponentInstance(typeof (DependsOnTouchable)));
		}
Example #15
0
        public void ComponentParameterExcludesSelf()
        {
            DefaultPicoContainer pico    = new DefaultPicoContainer();
            IComponentAdapter    adapter =
                pico.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable));

            Assert.IsNotNull(pico.GetComponentInstance(typeof(ITouchable)));
            ITouchable touchable =
                (ITouchable)ComponentParameter.DEFAULT.ResolveInstance(pico, adapter, typeof(ITouchable));

            Assert.IsNull(touchable);
        }
Example #16
0
        public void ComponentParameterFetches()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();

            pico.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable));
            ComponentParameter parameter = new ComponentParameter(typeof(ITouchable));

            Assert.IsNotNull(pico.GetComponentInstance(typeof(ITouchable)));
            ITouchable touchable = (ITouchable)parameter.ResolveInstance(pico, null, typeof(ITouchable));

            Assert.IsNotNull(touchable);
        }
Example #17
0
        public void ResolveFromParentByType()
        {
            IMutablePicoContainer parent = new DefaultPicoContainer();

            parent.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable));

            IMutablePicoContainer child = new DefaultPicoContainer(parent);

            child.RegisterComponentImplementation(typeof(DependsOnTouchable));

            Assert.IsNotNull(child.GetComponentInstance(typeof(DependsOnTouchable)));
        }
Example #18
0
        public void CollectionsAreGeneratedOnTheFly()
        {
            IMutablePicoContainer mpc = new DefaultPicoContainer();

            mpc.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof(Bowl)));
            mpc.RegisterComponentImplementation(typeof(Cod));
            Bowl bowl = (Bowl)mpc.GetComponentInstance(typeof(Bowl));

            Assert.AreEqual(1, bowl.cods.Length);
            mpc.RegisterComponentInstance("Nemo", new Cod());
            bowl = (Bowl)mpc.GetComponentInstance(typeof(Bowl));
            Assert.AreEqual(2, bowl.cods.Length);

            try
            {
                Assert.AreSame(bowl.cods[0], bowl.cods[1]);
                Assert.Fail("cods should not be the same");
            }
            catch (AssertionException)
            {
            }
        }
        public void ResolveFromGrandParentByKey()
        {
            IMutablePicoContainer grandParent = new DefaultPicoContainer();
            grandParent.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

            IMutablePicoContainer parent = new DefaultPicoContainer(grandParent);

            IMutablePicoContainer child = new DefaultPicoContainer(parent);
            child.RegisterComponentImplementation(typeof (DependsOnTouchable), typeof (DependsOnTouchable),
                                                  new IParameter[] {new ComponentParameter(typeof (ITouchable))});

            Assert.IsNotNull(child.GetComponentInstance(typeof (DependsOnTouchable)));
        }
Example #20
0
        public void OnlyStartableComponentsAreInstantiatedOnStart()
        {
            IMutablePicoContainer pico = new DefaultPicoContainer();

            pico.RegisterComponentImplementation("recording", typeof(StringBuilder));
            pico.RegisterComponentImplementation(typeof(A));
            pico.RegisterComponentImplementation(typeof(NotStartable));
            pico.Start();

            pico.Stop();
            pico.Dispose();
            Assert.AreEqual("<AA>!A", pico.GetComponentInstance("recording").ToString());
        }
Example #21
0
        public void ComponentsAreStartedBreadthFirstAndStoppedDepthFirst()
        {
            IMutablePicoContainer parent = new DefaultPicoContainer();

            parent.RegisterComponentImplementation("recording", typeof(StringBuilder));
            parent.RegisterComponentImplementation(typeof(A));
            IMutablePicoContainer child = parent.MakeChildContainer();

            child.RegisterComponentImplementation(typeof(B));
            parent.Start();
            parent.Stop();

            Assert.AreEqual("<A<BB>A>", parent.GetComponentInstance("recording").ToString());
        }
Example #22
0
        public void BowlWithoutTom()
        {
            IMutablePicoContainer mpc = new DefaultPicoContainer();

            mpc.RegisterComponentImplementation("Tom", typeof(Cod));
            mpc.RegisterComponentImplementation("Dick", typeof(Cod));
            mpc.RegisterComponentImplementation("Harry", typeof(Cod));
            mpc.RegisterComponentImplementation(typeof(Shark));

            IParameter[] parameters = new IParameter[]
            {
                new SampleCollectionComponentParameter(typeof(Cod), false),
                new CollectionComponentParameter(typeof(Fish), false)
            };

            mpc.RegisterComponentImplementation(typeof(CollectedBowl), typeof(CollectedBowl), parameters);

            CollectedBowl bowl = (CollectedBowl)mpc.GetComponentInstance(typeof(CollectedBowl));
            Cod           tom  = (Cod)mpc.GetComponentInstance("Tom");

            Assert.AreEqual(4, bowl.fishes.Length);
            Assert.AreEqual(2, bowl.cods.Length);
            Assert.IsFalse(new ArrayList(bowl.cods).Contains(tom));
        }
        public void NormalExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption()
        {
            DefaultPicoContainer picoContainer = new DefaultPicoContainer();

            picoContainer.RegisterComponentImplementation(typeof(NormalExceptionThrowing));
            try
            {
                picoContainer.GetComponentInstance(typeof(NormalExceptionThrowing));
                Assert.Fail();
            }
            catch (PicoInvocationTargetInitializationException e)
            {
                Assert.AreEqual("test", e.GetBaseException().Message);
            }
        }
        public void PicoInitializationExceptionThrownBecauseOfFilteredConstructors()
        {
            DefaultPicoContainer picoContainer = new DefaultPicoContainer();

            try
            {
                picoContainer.RegisterComponentImplementation(typeof(IllegalAccessExceptionThrowing));
                picoContainer.GetComponentInstance(typeof(IllegalAccessExceptionThrowing));
                Assert.Fail();
            }
            catch (PicoInitializationException e)
            {
                Assert.IsTrue(e.Message.IndexOf(typeof(IllegalAccessExceptionThrowing).Name) > 0);
            }
        }
Example #25
0
        public void ResolveFromGrandParentByKey()
        {
            IMutablePicoContainer grandParent = new DefaultPicoContainer();

            grandParent.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable));

            IMutablePicoContainer parent = new DefaultPicoContainer(grandParent);

            IMutablePicoContainer child = new DefaultPicoContainer(parent);

            child.RegisterComponentImplementation(typeof(DependsOnTouchable), typeof(DependsOnTouchable),
                                                  new IParameter[] { new ComponentParameter(typeof(ITouchable)) });

            Assert.IsNotNull(child.GetComponentInstance(typeof(DependsOnTouchable)));
        }
Example #26
0
        public void WillRemoveComponentsWithMatchingKeyFromParent()
        {
            IMutablePicoContainer parent = new DefaultPicoContainer();

            parent.RegisterComponentImplementation("Tom", typeof(Cod));
            parent.RegisterComponentImplementation("Dick", typeof(Cod));
            parent.RegisterComponentImplementation("Harry", typeof(Cod));

            IMutablePicoContainer child = new DefaultPicoContainer(parent);

            child.RegisterComponentImplementation("Dick", typeof(Shark));
            child.RegisterComponentImplementation(typeof(Bowl));
            Bowl bowl = (Bowl)child.GetComponentInstance(typeof(Bowl));

            Assert.AreEqual(3, bowl.fishes.Length);
            Assert.AreEqual(2, bowl.cods.Length);
        }
Example #27
0
        public void StartStopStartStopAndDispose()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();

            pico.RegisterComponentImplementation(typeof(One));
            pico.RegisterComponentImplementation(typeof(Two));
            pico.RegisterComponentImplementation(typeof(Three));
            pico.RegisterComponentImplementation(typeof(Four));
            One    one = (One)pico.GetComponentInstance(typeof(One));
            object o   = pico.ComponentInstances;

            // instantiation - would be difficult to do these in the wrong order!!
            Assert.AreEqual(4, one.getInstantiating().Count);
            Assert.AreEqual("One", one.getInstantiating()[0]);
            Assert.AreEqual("Two", one.getInstantiating()[1]);
            Assert.AreEqual("Three", one.getInstantiating()[2]);
            Assert.AreEqual("Four", one.getInstantiating()[3]);
            StartStopDisposeLifecycleComps(pico, pico, pico, one);
        }
Example #28
0
        public void StartStopOfDaemonizedThread()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();

            pico.RegisterComponentImplementation(typeof(FooRunnable));

            object i = pico.ComponentInstances;

            pico.Start();
            Thread.Sleep(100);
            pico.Stop();

            FooRunnable foo = (FooRunnable)pico.GetComponentInstance(typeof(FooRunnable));

            Assert.AreEqual(1, foo.runCount());
            pico.Start();
            Thread.Sleep(100);
            pico.Stop();
            Assert.AreEqual(2, foo.runCount());
        }
Example #29
0
        public void TestDictionaries()
        {
            IMutablePicoContainer mpc = new DefaultPicoContainer();

            IParameter[] parameters = new IParameter[] { new ComponentParameter(typeof(Fish), false) };

            mpc.RegisterComponentImplementation(typeof(DictionaryBowl), typeof(DictionaryBowl), parameters);
            mpc.RegisterComponentImplementation(typeof(Cod));
            mpc.RegisterComponentImplementation(typeof(Shark));
            DictionaryBowl bowl = (DictionaryBowl)mpc.GetComponentInstance(typeof(DictionaryBowl));

            Assert.AreEqual(2, bowl.Fishes.Length);

            try
            {
                Assert.AreSame(bowl.Fishes[0], bowl.Fishes[1]);
                Assert.Fail("Should not be the same fish");
            }
            catch (AssertionException)
            {
            }
        }
		public void TestCollections()
		{
			IMutablePicoContainer mpc = new DefaultPicoContainer();
			IParameter[] parameters = new IParameter[]{new ComponentParameter(typeof(Cod), false), 
														  new ComponentParameter(typeof(Fish), false)};

			mpc.RegisterComponentImplementation(typeof(CollectedBowl), typeof(CollectedBowl), parameters);
			mpc.RegisterComponentImplementation(typeof(Cod));
			mpc.RegisterComponentImplementation(typeof(Shark));
			Cod cod = (Cod) mpc.GetComponentInstanceOfType(typeof(Cod));
			CollectedBowl bowl = (CollectedBowl) mpc.GetComponentInstance(typeof(CollectedBowl));
			Assert.AreEqual(1, bowl.cods.Length);
			Assert.AreEqual(2, bowl.fishes.Length);
			Assert.AreSame(cod, bowl.cods[0]);

			try
			{
				Assert.AreSame(bowl.fishes[0], bowl.fishes[1]);
				Assert.Fail("The fishes should not be the same");
			}
			catch(AssertionException) {}
		}
		public void TestDictionaries()
		{
			IMutablePicoContainer mpc = new DefaultPicoContainer();
			IParameter[] parameters = new IParameter[] {new ComponentParameter(typeof (Fish), false)};

			mpc.RegisterComponentImplementation(typeof (DictionaryBowl), typeof (DictionaryBowl), parameters);
			mpc.RegisterComponentImplementation(typeof (Cod));
			mpc.RegisterComponentImplementation(typeof (Shark));
			DictionaryBowl bowl = (DictionaryBowl) mpc.GetComponentInstance(typeof (DictionaryBowl));
			Assert.AreEqual(2, bowl.Fishes.Length);

			try
			{
				Assert.AreSame(bowl.Fishes[0], bowl.Fishes[1]);
				Assert.Fail("Should not be the same fish");
			} 
			catch(AssertionException) {}
		}
		public void WillRemoveComponentsWithMatchingKeyFromParent() 
		{
			IMutablePicoContainer parent = new DefaultPicoContainer();
			parent.RegisterComponentImplementation("Tom", typeof(Cod));
			parent.RegisterComponentImplementation("Dick", typeof(Cod));
			parent.RegisterComponentImplementation("Harry", typeof(Cod));
			
			IMutablePicoContainer child = new DefaultPicoContainer(parent);
			child.RegisterComponentImplementation("Dick", typeof(Shark));
			child.RegisterComponentImplementation(typeof(Bowl));
			Bowl bowl = (Bowl) child.GetComponentInstance(typeof(Bowl));
			Assert.AreEqual(3, bowl.fishes.Length);
			Assert.AreEqual(2, bowl.cods.Length);
		}
		public void BowlWithoutTom()
		{
			IMutablePicoContainer mpc = new DefaultPicoContainer();
			mpc.RegisterComponentImplementation("Tom", typeof (Cod));
			mpc.RegisterComponentImplementation("Dick", typeof (Cod));
			mpc.RegisterComponentImplementation("Harry", typeof (Cod));
			mpc.RegisterComponentImplementation(typeof (Shark));

			IParameter[] parameters = new IParameter[]
				{
					new SampleCollectionComponentParameter(typeof (Cod), false),
					new CollectionComponentParameter(typeof (Fish), false)
				};

			mpc.RegisterComponentImplementation(typeof (CollectedBowl), typeof (CollectedBowl), parameters);

			CollectedBowl bowl = (CollectedBowl) mpc.GetComponentInstance(typeof (CollectedBowl));
			Cod tom = (Cod) mpc.GetComponentInstance("Tom");
			Assert.AreEqual(4, bowl.fishes.Length);
			Assert.AreEqual(2, bowl.cods.Length);
			Assert.IsFalse(new ArrayList(bowl.cods).Contains(tom));
		}
		public void CollectionsAreGeneratedOnTheFly()
		{
			IMutablePicoContainer mpc = new DefaultPicoContainer();
			mpc.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof (Bowl), typeof (Bowl)));
			mpc.RegisterComponentImplementation(typeof (Cod));
			Bowl bowl = (Bowl) mpc.GetComponentInstance(typeof (Bowl));
			Assert.AreEqual(1, bowl.cods.Length);
			mpc.RegisterComponentInstance("Nemo", new Cod());
			bowl = (Bowl) mpc.GetComponentInstance(typeof (Bowl));
			Assert.AreEqual(2, bowl.cods.Length);

			try
			{
				Assert.AreSame(bowl.cods[0], bowl.cods[1]);
				Assert.Fail("cods should not be the same");
			}
			catch (AssertionException)
			{
			}
		}
		public void InstantiationExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			picoContainer.RegisterComponentImplementation(typeof (InstantiationExceptionThrowing));
			picoContainer.GetComponentInstance(typeof (InstantiationExceptionThrowing));
		}
        public void StartStopOfDaemonizedThread()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();
            pico.RegisterComponentImplementation(typeof (FooRunnable));

            object i = pico.ComponentInstances;
            pico.Start();
            Thread.Sleep(100);
            pico.Stop();

            FooRunnable foo = (FooRunnable) pico.GetComponentInstance(typeof (FooRunnable));
            Assert.AreEqual(1, foo.runCount());
            pico.Start();
            Thread.Sleep(100);
            pico.Stop();
            Assert.AreEqual(2, foo.runCount());
        }
 public void StartStopStartStopAndDispose()
 {
     DefaultPicoContainer pico = new DefaultPicoContainer();
     pico.RegisterComponentImplementation(typeof (One));
     pico.RegisterComponentImplementation(typeof (Two));
     pico.RegisterComponentImplementation(typeof (Three));
     pico.RegisterComponentImplementation(typeof (Four));
     One one = (One) pico.GetComponentInstance(typeof (One));
     object o = pico.ComponentInstances;
     // instantiation - would be difficult to do these in the wrong order!!
     Assert.AreEqual(4, one.getInstantiating().Count);
     Assert.AreEqual("One", one.getInstantiating()[0]);
     Assert.AreEqual("Two", one.getInstantiating()[1]);
     Assert.AreEqual("Three", one.getInstantiating()[2]);
     Assert.AreEqual("Four", one.getInstantiating()[3]);
     StartStopDisposeLifecycleComps(pico, pico, pico, one);
 }
        public void OnlyStartableComponentsAreInstantiatedOnStart()
        {
            IMutablePicoContainer pico = new DefaultPicoContainer();
            pico.RegisterComponentImplementation("recording", typeof (StringBuilder));
            pico.RegisterComponentImplementation(typeof (A));
            pico.RegisterComponentImplementation(typeof (NotStartable));
            pico.Start();

            pico.Stop();
            pico.Dispose();
            Assert.AreEqual("<AA>!A", pico.GetComponentInstance("recording").ToString());
        }
        public void ComponentsAreStartedBreadthFirstAndStoppedDepthFirst()
        {
            IMutablePicoContainer parent = new DefaultPicoContainer();
            parent.RegisterComponentImplementation("recording", typeof (StringBuilder));
            parent.RegisterComponentImplementation(typeof (A));
            IMutablePicoContainer child = parent.MakeChildContainer();
            child.RegisterComponentImplementation(typeof (B));
            parent.Start();
            parent.Stop();

            Assert.AreEqual("<A<BB>A>", parent.GetComponentInstance("recording").ToString());
        }
		public void ShouldNotConsiderNonPublicConstructors()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			pico.RegisterComponentImplementation(typeof (Component201));
			pico.RegisterComponentInstance(2);
			pico.RegisterComponentInstance(true);
			pico.RegisterComponentInstance("Hello");
			Assert.IsNotNull(pico.GetComponentInstance(typeof (Component201)));
		}
 public void ThangCanBeInstantiatedWithArrayList()
 {
     IMutablePicoContainer pico = new DefaultPicoContainer();
     pico.RegisterComponentImplementation(typeof (Thingie));
     pico.RegisterComponentImplementation(typeof (ArrayList));
     Assert.IsNotNull(pico.GetComponentInstance(typeof (Thingie)));
 }
		public void NormalExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			picoContainer.RegisterComponentImplementation(typeof (NormalExceptionThrowing));
			try
			{
				picoContainer.GetComponentInstance(typeof (NormalExceptionThrowing));
				Assert.Fail();
			}
			catch (PicoInvocationTargetInitializationException e)
			{
				Assert.AreEqual("test", e.GetBaseException().Message);
			}
		}
		public void ShouldBeAbleToInstantiateNonPublicClassesWithNonPublicConstructors()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory(true));
			pico.RegisterComponentImplementation(typeof (Private));
			pico.RegisterComponentImplementation(typeof (NotYourBusiness));
			Assert.IsNotNull(pico.GetComponentInstance(typeof (NotYourBusiness)));
		}
		public void PicoInitializationExceptionThrownBecauseOfFilteredConstructors()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			try
			{
				picoContainer.RegisterComponentImplementation(typeof (IllegalAccessExceptionThrowing));
				picoContainer.GetComponentInstance(typeof (IllegalAccessExceptionThrowing));
				Assert.Fail();
			}
			catch (PicoInitializationException e)
			{
				Assert.IsTrue(e.Message.IndexOf(typeof (IllegalAccessExceptionThrowing).Name) > 0);
			}
		}