Beispiel #1
0
        public void ObjectNamesForTypeIncludingAncestorsPrototypesAndFactoryObjectsPreserveOrderOfRegistration()
        {
            IList <string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, _expectedtype, false, false);

            Assert.AreEqual(5, names.Count);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
        }
 public void IsFactoryDereferenceWithJustTheFactoryObjectPrefixCharacter()
 {
     Assert.IsFalse(ObjectFactoryUtils.IsFactoryDereference(
                        ObjectFactoryUtils.FactoryObjectPrefix),
                    "Name that consisted solely of the factory object prefix is being reported " +
                    "(incorrectly) as a factory object dereference.");
 }
Beispiel #3
0
        public void ObjectNamesIncludingAncestorsPreserveOrderOfRegistration()
        {
            IList <string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);

            Assert.AreEqual(5, names.Count);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
        }
 public void IsFactoryDereferenceSunnyDay()
 {
     Assert.IsTrue(ObjectFactoryUtils.IsFactoryDereference(
                       ObjectFactoryUtils.FactoryObjectPrefix + "roob"),
                   "Name that did start with the factory object prefix is not being reported " +
                   "(incorrectly) as a factory object dereference.");
 }
        public void HierarchicalResolutionWithOverride()
        {
            object test3        = _factory.GetObject("test3");
            object test         = _factory.GetObject("test");
            object testFactory1 = _factory.GetObject("testFactory1");

            IDictionary <string, object> objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(_factory, typeof(ITestObject), true, false);

            Assert.AreEqual(3, objects.Count);
            Assert.AreEqual(test3, objects["test3"]);
            Assert.AreEqual(test, objects["test"]);
            Assert.AreEqual(testFactory1, objects["testFactory1"]);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(_factory, typeof(ITestObject), false, false);
            Assert.AreEqual(2, objects.Count);
            Assert.AreEqual(test, objects["test"]);
            Assert.AreEqual(testFactory1, objects["testFactory1"]);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(_factory, typeof(ITestObject), false, true);
            Assert.AreEqual(2, objects.Count);
            Assert.AreEqual(test, objects["test"]);
            Assert.AreEqual(testFactory1, objects["testFactory1"]);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(_factory, typeof(ITestObject), true, true);
            Assert.AreEqual(4, objects.Count);
            Assert.AreEqual(test3, objects["test3"]);
            Assert.AreEqual(test, objects["test"]);
            Assert.AreEqual(testFactory1, objects["testFactory1"]);
            Assert.IsTrue(objects["testFactory2"] is ITestObject);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(_factory, typeof(DummyFactory), true, true);
            Assert.AreEqual(2, objects.Count);
            Assert.AreEqual(_factory.GetObject("&testFactory1"), objects["&testFactory1"]);
            Assert.AreEqual(_factory.GetObject("&testFactory2"), objects["&testFactory2"]);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(_factory, typeof(IFactoryObject), true, true);
            Assert.AreEqual(2, objects.Count);
            Assert.AreEqual(_factory.GetObject("&testFactory1"), objects["&testFactory1"]);
            Assert.AreEqual(_factory.GetObject("&testFactory2"), objects["&testFactory2"]);
        }
        public void ObjectsOfTypeIncludingAncestorsWithStaticFactory()
        {
            StaticListableObjectFactory lof = new StaticListableObjectFactory();
            TestObject   t1 = new TestObject();
            TestObject   t2 = new TestObject();
            DummyFactory t3 = new DummyFactory();
            DummyFactory t4 = new DummyFactory();

            t4.IsSingleton = false;
            lof.AddObject("t1", t1);
            lof.AddObject("t2", t2);
            lof.AddObject("t3", t3);
            t3.AfterPropertiesSet(); // StaticListableObjectFactory does support lifecycle calls.
            lof.AddObject("t4", t4);
            t4.AfterPropertiesSet(); // StaticListableObjectFactory does support lifecycle calls.
            IDictionary <string, object> objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(lof, typeof(ITestObject), true, false);

            Assert.AreEqual(2, objects.Count);
            Assert.AreEqual(t1, objects["t1"]);
            Assert.AreEqual(t2, objects["t2"]);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(lof, typeof(ITestObject), false, true);
            Assert.AreEqual(3, objects.Count);
            Assert.AreEqual(t1, objects["t1"]);
            Assert.AreEqual(t2, objects["t2"]);
            Assert.AreEqual(t3.GetObject(), objects["t3"]);
            objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(lof, typeof(ITestObject), true, true);
            Assert.AreEqual(4, objects.Count);
            Assert.AreEqual(t1, objects["t1"]);
            Assert.AreEqual(t2, objects["t2"]);
            Assert.AreEqual(t3.GetObject(), objects["t3"]);
            Assert.IsTrue(objects["t4"] is TestObject);
        }
 public void CountObjectsIncludingAncestors()
 {
     // leaf count...
     Assert.AreEqual(1, _factory.ObjectDefinitionCount);
     // count minus duplicate...
     Assert.AreEqual(6, ObjectFactoryUtils.CountObjectsIncludingAncestors(_factory),
                     "Should count 6 objects, not " + ObjectFactoryUtils.CountObjectsIncludingAncestors(_factory));
 }
        public void CountObjectsIncludingAncestorsWithNonHierarchicalFactory()
        {
            StaticListableObjectFactory lof = new StaticListableObjectFactory();

            lof.AddObject("t1", new TestObject());
            lof.AddObject("t2", new TestObject());
            Assert.IsTrue(ObjectFactoryUtils.CountObjectsIncludingAncestors(lof) == 2);
        }
        public void NoObjectsOfTypeIncludingAncestors()
        {
            StaticListableObjectFactory lof = new StaticListableObjectFactory();

            lof.AddObject("foo", new object());
            IDictionary <string, object> objects = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(lof, typeof(ITestObject), true, false);

            Assert.IsTrue(objects.Count == 0);
        }
        public void ObjectNamesForTypeIncludingAncestors()
        {
            IList <string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, typeof(ITestObject));

            // includes 2 TestObjects from IFactoryObjects (DummyFactory definitions)
            Assert.AreEqual(4, names.Count);
            Assert.IsTrue(names.Contains("test"));
            Assert.IsTrue(names.Contains("test3"));
            Assert.IsTrue(names.Contains("testFactory1"));
            Assert.IsTrue(names.Contains("testFactory2"));
        }
        /// <summary>
        /// Return the object name, stripping out the factory dereference prefix if necessary.
        /// </summary>
        /// <param name="name">The name of the object.</param>
        /// <returns>The object name sans any factory dereference prefix.</returns>
        public static string TransformedObjectName(string name)
        {
            AssertUtils.ArgumentNotNull(name, "name", "Object name must not be null.");
            if (!ObjectFactoryUtils.IsFactoryDereference(name))
            {
                return(name);
            }

            string objectName = name.Substring(ObjectFactoryUtils.FactoryObjectPrefix.Length);

            return(objectName);
        }
        public void ObjectOfTypeIncludingAncestorsExcludesObjectsFromParentWhenLocalObjectDefined()
        {
            DefaultListableObjectFactory root = new DefaultListableObjectFactory();

            root.RegisterObjectDefinition("excludeLocalObject", new RootObjectDefinition(typeof(ArrayList)));
            DefaultListableObjectFactory child = new DefaultListableObjectFactory(root);

            child.RegisterObjectDefinition("excludeLocalObject", new RootObjectDefinition(typeof(Hashtable)));

            IDictionary <string, object> objectEntries = ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(child, typeof(ArrayList), true, true);

            // "excludeLocalObject" matches on the parent, but not the local object definition
            Assert.AreEqual(0, objectEntries.Count);
        }
        public void ObjectNamesIncludingAncestors()
        {
            IList <string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);

            Assert.AreEqual(6, names.Count);
        }
 public void IsFactoryDereferenceWithEmptyName()
 {
     Assert.IsFalse(ObjectFactoryUtils.IsFactoryDereference(string.Empty),
                    "String.Empty name that (obviously) didn't start with the factory object prefix is being reported " +
                    "(incorrectly) as a factory object dereference.");
 }
 public void IsFactoryDereferenceWithNonFactoryObjectName()
 {
     Assert.IsFalse(ObjectFactoryUtils.IsFactoryDereference("roob"),
                    "Name that didn't start with the factory object prefix is being reported " +
                    "(incorrectly) as a factory object dereference.");
 }
 public void ObjectOfTypeIncludingAncestorsWithMoreThanOneObjectOfType()
 {
     Assert.Throws <NoSuchObjectDefinitionException>(
         () => ObjectFactoryUtils.ObjectOfTypeIncludingAncestors(_factory, typeof(ITestObject), true, true),
         "No unique object of type [Oragon.Spring.Objects.ITestObject] is defined : Expected single object but found 4");
 }