コード例 #1
0
        public void GetObjectDefinitionResolvesAliases()
        {
            const string TheParentsAlias = "theParentsAlias";
            const int ExpectedAge = 31;
            const string ExpectedName = "Rick Evans";

            RootObjectDefinition parentDef = new RootObjectDefinition(typeof(TestObject));
            parentDef.IsAbstract = true;
            parentDef.PropertyValues.Add("name", ExpectedName);
            parentDef.PropertyValues.Add("age", ExpectedAge);

            ChildObjectDefinition childDef = new ChildObjectDefinition(TheParentsAlias);

            DefaultListableObjectFactory fac = new DefaultListableObjectFactory();

            fac.RegisterObjectDefinition("parent", parentDef);
            fac.RegisterAlias("parent", TheParentsAlias);

            IObjectDefinition od = fac.GetObjectDefinition(TheParentsAlias);
            Assert.IsNotNull(od);
        }
コード例 #2
0
        public void ChildReferencesParentByAnAliasOfTheParent()
        {
            const string TheParentsAlias = "theParentsAlias";
            const int ExpectedAge = 31;
            const string ExpectedName = "Rick Evans";

            RootObjectDefinition parentDef = new RootObjectDefinition(typeof(TestObject));
            parentDef.IsAbstract = true;
            parentDef.PropertyValues.Add("name", ExpectedName);
            parentDef.PropertyValues.Add("age", ExpectedAge);

            ChildObjectDefinition childDef = new ChildObjectDefinition(TheParentsAlias);

            DefaultListableObjectFactory fac = new DefaultListableObjectFactory();

            fac.RegisterObjectDefinition("parent", parentDef);
            fac.RegisterAlias("parent", TheParentsAlias);
            fac.RegisterObjectDefinition("child", childDef);

            TestObject child = (TestObject)fac.GetObject("child");
            Assert.AreEqual(ExpectedName, child.Name);
            Assert.AreEqual(ExpectedAge, child.Age);
        }