SPRNET-1512 Fixing code path for Spring.Context.Support.AbstractApplicationContext.GetObjectNamesForType(...) to properly respect object definitions in a hierarchy of contexts/objectfactories

This commit is contained in:
Steve Bohlen
2012-07-09 16:04:06 -04:00
parent dcbdf80ad6
commit d8ff77d999
7 changed files with 362 additions and 349 deletions

View File

@@ -58,12 +58,12 @@ namespace Spring.Objects.Factory {
[Test]
public virtual void Count ()
{
AssertCount (13);
AssertCount (16);
}
protected internal void AssertCount (int count)
{
IList<string> defnames = ListableObjectFactory.GetObjectDefinitionNames ();
IList<string> defnames = ListableObjectFactory.GetObjectDefinitionNames();
Assert.IsTrue (
defnames.Count == count,
string.Format ("We should have {0} objects, not {1}.", count, defnames.Count));
@@ -72,7 +72,7 @@ namespace Spring.Objects.Factory {
[Test]
public virtual void ObjectCount ()
{
AssertTestObjectCount (9);
AssertTestObjectCount (12);
}
public virtual void AssertTestObjectCount (int count)

View File

@@ -20,7 +20,6 @@
#region Imports
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
@@ -33,193 +32,130 @@ using Spring.Objects.Factory.Xml;
namespace Spring.Objects.Factory
{
/// <summary>
/// Unit tests for the ObjectFactoryUtils class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
/// <author>Rick Evans (.NET)</author>
[TestFixture]
public sealed class ObjectFactoryUtilsTests
{
private IConfigurableListableObjectFactory _factory;
/// <summary>
/// Unit tests for the ObjectFactoryUtils class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
/// <author>Rick Evans (.NET)</author>
[TestFixture]
public sealed class ObjectFactoryUtilsTests
{
private IConfigurableListableObjectFactory _factory;
[SetUp]
public void SetUp()
{
IObjectFactory grandparent
= new XmlObjectFactory(new ReadOnlyXmlTestResource("root.xml", GetType()));
IObjectFactory parent
= new XmlObjectFactory(new ReadOnlyXmlTestResource("middle.xml", GetType()), grandparent);
IConfigurableListableObjectFactory child
= new XmlObjectFactory(new ReadOnlyXmlTestResource("leaf.xml", GetType()), parent);
_factory = child;
}
/// <summary>
/// Check that override doesn't count as two separate objects.
/// </summary>
[Test]
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));
}
[Test]
public void ObjectNamesIncludingAncestors()
{
IList<string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
Assert.AreEqual(6, names.Count);
}
[Test]
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();
IList<string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(of);
Assert.AreEqual(5, names.Count);
Assert.AreEqual(new string[] { "objA","objB","objC","obj2A","obj2C" }, names);
mocks.VerifyAll();
[SetUp]
public void SetUp()
{
IObjectFactory grandparent
= new XmlObjectFactory(new ReadOnlyXmlTestResource("root.xml", GetType()));
IObjectFactory parent
= new XmlObjectFactory(new ReadOnlyXmlTestResource("middle.xml", GetType()), grandparent);
IConfigurableListableObjectFactory child
= new XmlObjectFactory(new ReadOnlyXmlTestResource("leaf.xml", GetType()), parent);
_factory = child;
}
[Test]
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>
/// Check that override doesn't count as two separate objects.
/// </summary>
[Test]
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));
}
[Test]
[Test]
public void ObjectNamesIncludingAncestors()
{
IList<string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
Assert.AreEqual(6, names.Count);
}
[Test]
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"));
}
[Test]
public void ObjectNamesForTypeIncludingAncestorsExcludesObjectsFromParentWhenLocalObjectDefined()
{
DefaultListableObjectFactory root = new DefaultListableObjectFactory();
root.RegisterObjectDefinition( "excludeLocalObject", new RootObjectDefinition(typeof(ArrayList)) );
{
DefaultListableObjectFactory root = new DefaultListableObjectFactory();
root.RegisterObjectDefinition("excludeLocalObject", new RootObjectDefinition(typeof(ArrayList)));
DefaultListableObjectFactory child = new DefaultListableObjectFactory(root);
child.RegisterObjectDefinition("excludeLocalObject", new RootObjectDefinition(typeof(Hashtable)));
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(child, typeof (ArrayList));
// "excludeLocalObject" matches on the parent, but not the local object definition
Assert.AreEqual(0, names.Count);
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(child, typeof(ArrayList));
// "excludeLocalObject" matches on the parent, but not the local object definition
Assert.AreEqual(0, names.Count);
names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(child, typeof (ArrayList), true, true);
// "excludeLocalObject" matches on the parent, but not the local object definition
Assert.AreEqual(0, names.Count);
}
[Test]
public void ObjectNamesForTypeIncludingAncestorsPreserveOrderOfRegistration()
{
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)).Return(new string[] { "objA", "objB", "objC" });
Expect.Call(((IHierarchicalObjectFactory)of).ParentObjectFactory).Return(ofParent);
Expect.Call(ofParent.GetObjectNamesForType(EXPECTEDTYPE)).Return(new string[] { "obj2A", "objB", "obj2C" });
mocks.ReplayAll();
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(of, EXPECTEDTYPE);
Assert.AreEqual(5, names.Count);
Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
mocks.VerifyAll();
names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(child, typeof(ArrayList), true, true);
// "excludeLocalObject" matches on the parent, but not the local object definition
Assert.AreEqual(0, names.Count);
}
[Test]
public void ObjectNamesForTypeIncludingAncestorsPrototypesAndFactoryObjectsPreserveOrderOfRegistration()
public void CountObjectsIncludingAncestorsWithNonHierarchicalFactory()
{
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();
StaticListableObjectFactory lof = new StaticListableObjectFactory();
lof.AddObject("t1", new TestObject());
lof.AddObject("t2", new TestObject());
Assert.IsTrue(ObjectFactoryUtils.CountObjectsIncludingAncestors(lof) == 2);
}
[Test]
public void CountObjectsIncludingAncestorsWithNonHierarchicalFactory()
{
StaticListableObjectFactory lof = new StaticListableObjectFactory();
lof.AddObject("t1", new TestObject());
lof.AddObject("t2", new TestObject());
Assert.IsTrue(ObjectFactoryUtils.CountObjectsIncludingAncestors(lof) == 2);
}
[Test]
public void HierarchicalResolutionWithOverride()
{
object test3 = _factory.GetObject("test3");
object test = _factory.GetObject("test");
object testFactory1 = _factory.GetObject("testFactory1");
[Test]
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"]);
}
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"]);
}
[Test]
[ExpectedException(typeof (NoSuchObjectDefinitionException),
[Test]
[ExpectedException(typeof(NoSuchObjectDefinitionException),
ExpectedMessage = "No unique object of type [Spring.Objects.ITestObject] is defined : Expected single object but found 4")]
public void ObjectOfTypeIncludingAncestorsWithMoreThanOneObjectOfType()
{
ObjectFactoryUtils.ObjectOfTypeIncludingAncestors(_factory, typeof (ITestObject), true, true);
}
public void ObjectOfTypeIncludingAncestorsWithMoreThanOneObjectOfType()
{
ObjectFactoryUtils.ObjectOfTypeIncludingAncestors(_factory, typeof(ITestObject), true, true);
}
[Test]
public void ObjectOfTypeIncludingAncestorsExcludesObjectsFromParentWhenLocalObjectDefined()
@@ -234,87 +170,87 @@ namespace Spring.Objects.Factory
Assert.AreEqual(0, objectEntries.Count);
}
[Test]
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);
}
[Test]
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);
}
[Test]
public void ObjectsOfTypeIncludingAncestorsWithStaticFactory()
{
StaticListableObjectFactory lof = new StaticListableObjectFactory();
TestObject t1 = new TestObject();
TestObject t2 = new TestObject();
DummyFactory t3 = new DummyFactory();
DummyFactory t4 = new DummyFactory();
[Test]
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("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);
}
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);
}
[Test]
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.");
}
[Test]
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.");
}
[Test]
public void IsFactoryDereferenceWithNullName()
{
Assert.IsFalse(ObjectFactoryUtils.IsFactoryDereference(null),
"Null name that (obviously) didn't start with the factory object prefix is being reported " +
"(incorrectly) as a factory object dereference.");
}
[Test]
public void IsFactoryDereferenceWithNullName()
{
Assert.IsFalse(ObjectFactoryUtils.IsFactoryDereference(null),
"Null name that (obviously) didn't start with the factory object prefix is being reported " +
"(incorrectly) as a factory object dereference.");
}
[Test]
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.");
}
[Test]
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.");
}
[Test]
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.");
}
[Test]
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.");
}
[Test]
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.");
}
}
[Test]
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.");
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Spring.Objects.Factory.Support;
namespace Spring.Objects.Factory
{
[TestFixture]
public class ObjectFactoryUtils_PreserveOrderInHierarchy_Tests
{
private readonly Type _expectedtype = typeof(ITestObject);
private DefaultListableObjectFactory _factory;
[SetUp]
public void _TestSetUp()
{
DefaultListableObjectFactory parentFactory = new DefaultListableObjectFactory();
_factory = new DefaultListableObjectFactory(parentFactory);
RootObjectDefinition rodA = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rodB = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rodC = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rod2A = new RootObjectDefinition(_expectedtype);
RootObjectDefinition rod2C = new RootObjectDefinition(_expectedtype);
_factory.RegisterObjectDefinition("objA", rodA);
_factory.RegisterObjectDefinition("objB", rodB);
_factory.RegisterObjectDefinition("objC", rodC);
parentFactory.RegisterObjectDefinition("obj2A", rod2A);
parentFactory.RegisterObjectDefinition("objB", rodB);
parentFactory.RegisterObjectDefinition("obj2C", rod2C);
}
[Test]
public void ObjectNamesIncludingAncestorsPreserveOrderOfRegistration()
{
IList<string> names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(_factory);
Assert.AreEqual(5, names.Count);
Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
}
[Test]
public void ObjectNamesForTypeIncludingAncestorsPreserveOrderOfRegistration()
{
IList<string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(_factory, _expectedtype);
Assert.AreEqual(5, names.Count);
Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);
}
[Test]
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);
}
}
}

View File

@@ -26,119 +26,119 @@ using Spring.Objects.Factory.Support;
namespace Spring.Objects.Factory
{
internal class UnsupportedObjectDefinitionImplementation : IObjectDefinition
{
public MutablePropertyValues PropertyValues
{
get { throw new NotImplementedException(); }
}
internal class UnsupportedObjectDefinitionImplementation : IObjectDefinition
{
public MutablePropertyValues PropertyValues
{
get { throw new NotImplementedException(); }
}
public ConstructorArgumentValues ConstructorArgumentValues
{
get { throw new NotImplementedException(); }
}
public ConstructorArgumentValues ConstructorArgumentValues
{
get { throw new NotImplementedException(); }
}
public MethodOverrides MethodOverrides
{
get { throw new NotImplementedException(); }
}
public MethodOverrides MethodOverrides
{
get { throw new NotImplementedException(); }
}
public EventValues EventHandlerValues
{
get { throw new NotImplementedException(); }
}
public EventValues EventHandlerValues
{
get { throw new NotImplementedException(); }
}
public string ResourceDescription
{
get { return "UnsupportedObjectDefinitionImplementation_Resource"; }
}
public string ResourceDescription
{
get { return "UnsupportedObjectDefinitionImplementation_Resource"; }
}
public bool IsTemplate
{
get { throw new NotImplementedException(); }
}
public bool IsAbstract
{
get { throw new NotImplementedException(); }
}
public bool IsAbstract
{
get { return false; }
}
public bool IsSingleton
{
get { throw new NotImplementedException(); }
}
public bool IsSingleton
{
get { throw new NotImplementedException(); }
}
public bool IsLazyInit
{
get { throw new NotImplementedException(); }
}
public bool IsLazyInit
{
get { return false; }
}
public string ParentName
{
get { return null; }
set { throw new NotImplementedException(); }
}
public string ParentName
{
get { return null; }
set { throw new NotImplementedException(); }
}
public string Scope
{
get { throw new System.NotImplementedException(); }
set { throw new System.NotImplementedException(); }
}
public string Scope
{
get { return "UnsupportedObjectDefinitionImplementation_Resource"; }
set { throw new System.NotImplementedException(); }
}
public ObjectRole Role
{
get { throw new NotImplementedException(); }
}
public ObjectRole Role
{
get { throw new NotImplementedException(); }
}
public Type ObjectType
{
get { throw new NotImplementedException(); }
}
public Type ObjectType
{
get { throw new NotImplementedException(); }
}
public string ObjectTypeName
{
public string ObjectTypeName
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
}
public AutoWiringMode AutowireMode
{
get { throw new NotImplementedException(); }
}
public AutoWiringMode AutowireMode
{
get { throw new NotImplementedException(); }
}
public DependencyCheckingMode DependencyCheck
{
get { throw new NotImplementedException(); }
}
public DependencyCheckingMode DependencyCheck
{
get { throw new NotImplementedException(); }
}
public IList<string> DependsOn
{
get { throw new NotImplementedException(); }
}
public IList<string> DependsOn
{
get { throw new NotImplementedException(); }
}
public string InitMethodName
{
get { throw new NotImplementedException(); }
}
public string InitMethodName
{
get { throw new NotImplementedException(); }
}
public string DestroyMethodName
{
get { throw new NotImplementedException(); }
}
public string DestroyMethodName
{
get { throw new NotImplementedException(); }
}
public string FactoryMethodName
{
get { throw new NotImplementedException(); }
}
public string FactoryMethodName
{
get { throw new NotImplementedException(); }
}
public string FactoryObjectName
{
get { throw new NotImplementedException(); }
}
public string FactoryObjectName
{
get { throw new NotImplementedException(); }
}
public bool IsAutowireCandidate
{
get { throw new NotImplementedException(); }
}
}
public bool IsAutowireCandidate
{
get { throw new NotImplementedException(); }
}
}
}

View File

@@ -97,8 +97,8 @@ namespace Spring.Objects.Factory.Xml
parent.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(TestObject), false));
// add unsupported IObjectDefinition implementation...
UnsupportedObjectDefinitionImplementation unsupportedDefinition = new UnsupportedObjectDefinitionImplementation();
parent.RegisterObjectDefinition("unsupportedDefinition", unsupportedDefinition);
//UnsupportedObjectDefinitionImplementation unsupportedDefinition = new UnsupportedObjectDefinitionImplementation();
//parent.RegisterObjectDefinition("unsupportedDefinition", unsupportedDefinition);
XmlObjectFactory factory;
factory = new XmlObjectFactory(new ReadOnlyXmlTestResource("test.xml", GetType()), parent);