Esempio n. 1
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);
        }
Esempio n. 2
0
        public void NativeArrays()
        {
            IMutablePicoContainer mpc = GetDefaultPicoContainer();
            Cod  cod  = (Cod)mpc.GetComponentInstanceOfType(typeof(Cod));
            Bowl bowl = (Bowl)mpc.GetComponentInstance(typeof(Bowl));

            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("fish should not be the same");
            }
            catch (AssertionException)
            {
            }
        }
Esempio n. 3
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)
            {
            }
        }