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 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 virtual void FactoryIsInitialized() { TestObject tb = (TestObject)ObjectFactory.GetObject("singletonFactory"); DummyFactory factory = (DummyFactory)ObjectFactory.GetObject("&singletonFactory"); Assert.IsTrue(factory.WasInitialized, "Factory was not initialized even though it implemented IInitializingObject"); }
public virtual void FactorySingleton() { Assert.IsTrue(ObjectFactory.IsSingleton("&singletonFactory")); Assert.IsTrue(ObjectFactory.IsSingleton("singletonFactory")); TestObject tb = (TestObject)ObjectFactory.GetObject("singletonFactory"); Assert.IsTrue(tb.Name.Equals(DummyFactory.SINGLETON_NAME), "Singleton from factory has correct name, not " + tb.Name); DummyFactory factory = (DummyFactory)ObjectFactory.GetObject("&singletonFactory"); TestObject tb2 = (TestObject)ObjectFactory.GetObject("singletonFactory"); Assert.IsTrue(tb == tb2, "Singleton references =="); Assert.IsTrue(factory.ObjectFactory != null, "FactoryObject is ObjectFactoryAware"); }
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 virtual void GetFactoryItself() { DummyFactory factory = (DummyFactory)ObjectFactory.GetObject("&singletonFactory"); Assert.IsTrue(factory != null); }