コード例 #1
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)
            {
            }
        }
コード例 #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)
            {
            }
        }
コード例 #3
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));
        }
コード例 #4
0
		public Bowl(Cod[] cods, Fish[] fishes)
		{
			this.cods = cods;
			this.fishes = fishes;
		}