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.");
 }
        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 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 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 ObjectNamesIncludingAncestorsPreserveOrderOfRegistration()
        {
            IList <string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);

            Assert.AreEqual(5, names.Count);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
        }
        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 CountObjectsIncludingAncestorsWithNonHierarchicalFactory()
        {
            StaticListableObjectFactory lof = new StaticListableObjectFactory();

            lof.AddObject("t1", new TestObject());
            lof.AddObject("t2", new TestObject());
            Assert.IsTrue(ObjectFactoryUtils.CountObjectsIncludingAncestors(lof) == 2);
        }
 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 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);
        }
Exemplo n.º 10
0
        public void ObjectNamesForTypeIncludingAncestors()
        {
            var 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"));
        }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public void ObjectNamesIncludingAncestorsPreserveOrderOfRegistration()
        {
            MockRepository mocks = new MockRepository();
            IConfigurableListableObjectFactory of       = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));
            IConfigurableListableObjectFactory ofParent = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));

            Expect.Call(of.GetObjectNamesForType(typeof(object))).Return(new string[] { "objA", "objB", "objC" });
            Expect.Call(((IHierarchicalObjectFactory)of).ParentObjectFactory).Return(ofParent);
            Expect.Call(ofParent.GetObjectNamesForType(typeof(object))).Return(new string[] { "obj2A", "objB", "obj2C" });

            mocks.ReplayAll();

            string[] names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(of);
            Assert.AreEqual(5, names.Length);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);

            mocks.VerifyAll();
        }
Exemplo n.º 14
0
        public void ObjectNamesForTypeIncludingAncestorsPrototypesAndFactoryObjectsPreserveOrderOfRegistration()
        {
            MockRepository mocks = new MockRepository();
            IConfigurableListableObjectFactory of       = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));
            IConfigurableListableObjectFactory ofParent = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));
            Type EXPECTEDTYPE = typeof(ITestObject);

            Expect.Call(of.GetObjectNamesForType(EXPECTEDTYPE, false, false)).Return(new string[] { "objA", "objB", "objC" });
            Expect.Call(((IHierarchicalObjectFactory)of).ParentObjectFactory).Return(ofParent);
            Expect.Call(ofParent.GetObjectNamesForType(EXPECTEDTYPE, false, false)).Return(new string[] { "obj2A", "objB", "obj2C" });

            mocks.ReplayAll();

            IList <string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(of, EXPECTEDTYPE, false, false);

            Assert.AreEqual(5, names.Count);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);


            mocks.VerifyAll();
        }
Exemplo n.º 15
0
        public void ObjectNamesIncludingAncestors()
        {
            var names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);

            Assert.AreEqual(6, names.Count);
        }
Exemplo n.º 16
0
 public void ObjectOfTypeIncludingAncestorsWithMoreThanOneObjectOfType()
 {
     ObjectFactoryUtils.ObjectOfTypeIncludingAncestors(_factory, typeof(ITestObject), true, true);
 }
Exemplo n.º 17
0
 public void ObjectOfTypeIncludingAncestorsWithMoreThanOneObjectOfType()
 {
     Assert.Throws <NoSuchObjectDefinitionException>(
         () => ObjectFactoryUtils.ObjectOfTypeIncludingAncestors(_factory, typeof(ITestObject), true, true),
         "No unique object of type [Spring.Objects.ITestObject] is defined : Expected single object but found 4");
 }
Exemplo n.º 18
0
 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.");
 }
Exemplo n.º 19
0
 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.");
 }