diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs
index 7d577194..3f704708 100644
--- a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs
+++ b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs
@@ -352,7 +352,7 @@ namespace Spring.Objects.Factory.Support
{
PropertyValue copiedProperty = copiedProperties[i];
//(string name, RootObjectDefinition definition, string argumentName, object argumentValue)
- object value = valueResolver.ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value );
+ object value = valueResolver.ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value);
// object value = ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value);
PropertyValue propertyValue = new PropertyValue(copiedProperty.Name, value, copiedProperty.Expression);
// update mutable copy...
@@ -389,21 +389,23 @@ namespace Spring.Objects.Factory.Support
///
/// The wrapping the target object.
///
- protected string[] UnsatisfiedObjectProperties(RootObjectDefinition definition, IObjectWrapper wrapper)
+ protected string[] UnsatisfiedNonSimpleProperties(RootObjectDefinition definition, IObjectWrapper wrapper)
{
- ArrayList result = new ArrayList();
- ISet ignoredTypes = IgnoredDependencyTypes;
+ ListSet results = new ListSet();
+ IPropertyValues pvs = definition.PropertyValues;
PropertyInfo[] properties = wrapper.GetPropertyInfos();
foreach (PropertyInfo property in properties)
{
string name = property.Name;
- if (property.CanWrite && !ignoredTypes.Contains(property.PropertyType) && !result.Contains(name)
+ if (property.CanWrite
+ && !IsExcludedFromDependencyCheck(property)
+ && !pvs.Contains(name)
&& !ObjectUtils.IsSimpleProperty(property.PropertyType))
{
- result.Add(name);
+ results.Add(name);
}
}
- return (string[])result.ToArray(typeof(string));
+ return (string[])CollectionUtils.ToArray(results, typeof(string));
}
///
@@ -601,7 +603,7 @@ namespace Spring.Objects.Factory.Support
///
protected void AutowireByName(string name, RootObjectDefinition definition, IObjectWrapper wrapper, MutablePropertyValues properties)
{
- string[] propertyNames = UnsatisfiedObjectProperties(definition, wrapper);
+ string[] propertyNames = UnsatisfiedNonSimpleProperties(definition, wrapper);
foreach (string propertyName in propertyNames)
{
// look for a matching type
@@ -664,7 +666,7 @@ namespace Spring.Objects.Factory.Support
///
protected void AutowireByType(string name, RootObjectDefinition definition, IObjectWrapper wrapper, MutablePropertyValues properties)
{
- string[] propertyNames = UnsatisfiedObjectProperties(definition, wrapper);
+ string[] propertyNames = UnsatisfiedNonSimpleProperties(definition, wrapper);
foreach (string propertyName in propertyNames)
{
// look for a matching type
@@ -987,7 +989,7 @@ namespace Spring.Objects.Factory.Support
/// IObjectWrapper for the new instance
protected virtual IObjectWrapper InstantiateObject(string objectName, RootObjectDefinition definition)
{
- return new ObjectWrapper(InstantiationStrategy.Instantiate(definition, objectName, this));
+ return new ObjectWrapper(InstantiationStrategy.Instantiate(definition, objectName, this));
}
///
@@ -1008,7 +1010,7 @@ namespace Spring.Objects.Factory.Support
if (ObjectUtils.IsAssignable(typeof(SmartInstantiationAwareObjectPostProcessor), objectPostProcessor))
{
SmartInstantiationAwareObjectPostProcessor iop =
- (SmartInstantiationAwareObjectPostProcessor) objectPostProcessor;
+ (SmartInstantiationAwareObjectPostProcessor)objectPostProcessor;
ConstructorInfo[] ctors = iop.DetermineCandidateConstructors(objectType, objectName);
if (ctors != null)
{
@@ -1082,7 +1084,7 @@ namespace Spring.Objects.Factory.Support
///
protected IObjectWrapper AutowireConstructor(string name, RootObjectDefinition definition, ConstructorInfo[] ctors, object[] explicitArgs)
{
- ConstructorResolver constructorResolver =
+ ConstructorResolver constructorResolver =
new ConstructorResolver(this, this, InstantiationStrategy);
return constructorResolver.AutowireConstructor(name, definition, ctors, explicitArgs);
@@ -1193,11 +1195,20 @@ namespace Spring.Objects.Factory.Support
}
- private bool IsExcludedFromDependencyCheck(PropertyInfo pi)
+ ///
+ /// Determine whether the given bean property is excluded from dependency checks.
+ /// This implementation excludes properties whose type matches an ignored dependency type
+ /// or which are defined by an ignored dependency interface.
+ ///
+ ///
+ ///
+ /// the of the object property
+ /// whether the object property is excluded
+ private bool IsExcludedFromDependencyCheck(PropertyInfo property)
{
- bool b1 = !pi.CanWrite; //AutowireUtils.IsExcludedFromDependencyCheck(pi);
- bool b2 = IgnoredDependencyTypes.Contains(pi.PropertyType);
- bool b3 = AutowireUtils.IsSetterDefinedInInterface(pi, ignoredDependencyInterfaces);
+ bool b1 = !property.CanWrite; //AutowireUtils.IsExcludedFromDependencyCheck(pi);
+ bool b2 = IgnoredDependencyTypes.Contains(property.PropertyType);
+ bool b3 = AutowireUtils.IsSetterDefinedInInterface(property, ignoredDependencyInterfaces);
return b1 || b2 || b3;
/*
return AutowireUtils.IsExcludedFromDependencyCheck(pi) ||
diff --git a/src/Spring/Spring.Core/Util/CollectionUtils.cs b/src/Spring/Spring.Core/Util/CollectionUtils.cs
index 757e842f..394e9b5e 100644
--- a/src/Spring/Spring.Core/Util/CollectionUtils.cs
+++ b/src/Spring/Spring.Core/Util/CollectionUtils.cs
@@ -201,6 +201,20 @@ namespace Spring.Util
return new ArrayList(inputCollection);
}
+ ///
+ /// Copies the elements of the to a
+ /// new array of the specified element type.
+ ///
+ /// The instance to be converted.
+ /// The element of the destination array to create and copy elements to
+ /// An array of the specified element type containing copies of the elements of the .
+ public static Array ToArray(ICollection inputCollection, Type elementType)
+ {
+ Array array = Array.CreateInstance(elementType, inputCollection.Count);
+ inputCollection.CopyTo(array, 0);
+ return array;
+ }
+
///
/// Finds a value of the given type in the given collection.
///
diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryTests.cs
index 00a04983..6e1d16c7 100644
--- a/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryTests.cs
+++ b/test/Spring/Spring.Core.Tests/Objects/Factory/DefaultListableObjectFactoryTests.cs
@@ -35,63 +35,138 @@ using Spring.Objects.Factory.Xml;
namespace Spring.Objects.Factory
{
- ///
- /// Unit tests for the DefaultListableObjectFactory class.
- ///
- /// Rod Johnson
- /// Simon White (.NET)
- [TestFixture]
- public sealed class DefaultListableObjectFactoryTests
- {
- ///
- /// The setup logic executed before the execution of this test fixture.
- ///
- [TestFixtureSetUp]
- public void FixtureSetUp()
- {
- // enable (null appender) logging, just to ensure that the logging code is correct :D
- //XmlConfigurator.Configure();
- }
+ ///
+ /// Unit tests for the DefaultListableObjectFactory class.
+ ///
+ /// Rod Johnson
+ /// Simon White (.NET)
+ [TestFixture]
+ public sealed class DefaultListableObjectFactoryTests
+ {
+ ///
+ /// The setup logic executed before the execution of this test fixture.
+ ///
+ [TestFixtureSetUp]
+ public void FixtureSetUp()
+ {
+ // enable (null appender) logging, just to ensure that the logging code is correct :D
+ //XmlConfigurator.Configure();
+ }
- [Test(Description="http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
- public void ObjectCreatedViaStaticFactoryMethodUsesReturnTypeOfFactoryMethodAsTheObjectType()
- {
- RootObjectDefinition def
- = new RootObjectDefinition(typeof(TestObjectCreator));
- def.FactoryMethodName = "CreateTestObject";
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.RegisterObjectDefinition("factoryObject", def);
- IDictionary objs = lof.GetObjectsOfType(typeof(TestObject));
- Assert.AreEqual(1, objs.Count);
- }
+ interface ICollaborator {}
+ interface IStrategy {}
- [Test(Description="http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
- public void ObjectCreatedViaInstanceFactoryMethodUsesReturnTypeOfFactoryMethodAsTheObjectType()
- {
- RootObjectDefinition def
- = new RootObjectDefinition(typeof(TestObjectCreator));
- def.FactoryMethodName = "InstanceCreateTestObject";
- def.FactoryObjectName = "target";
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.RegisterObjectDefinition("factoryObject", def);
- lof.RegisterObjectDefinition("target", new RootObjectDefinition(typeof(TestObjectCreator)));
- IDictionary objs = lof.GetObjectsOfType(typeof(TestObject));
- Assert.AreEqual(1, objs.Count);
- }
+ class Collaborator : ICollaborator {}
+ class Strategy1 : IStrategy {}
+ class Strategy2 : IStrategy {}
+
+ class Class1
+ {
+ public readonly IStrategy TheStrategy;
+
+ public Class1( ICollaborator collaborator, IStrategy strategy)
+ {
+ TheStrategy = strategy;
+ }
+ }
+
+ class Class2
+ {
+ private IStrategy _strategy;
+ private ICollaborator _collaborator;
+
+ public Class2()
+ {}
+
+ public IStrategy Strategy
+ {
+ get { return _strategy; }
+ set { _strategy = value; }
+ }
+
+ public ICollaborator Collaborator
+ {
+ get { return _collaborator; }
+ set { _collaborator = value; }
+ }
+ }
+
+
+ [Test(Description = "http://jira.springframework.org/browse/SPRNET-985")]
+ public void AutowireConstructorHonoresOverridesBeforeThrowingUnsatisfiedDependencyException()
+ {
+ RootObjectDefinition def = new RootObjectDefinition(typeof(Class1));
+ def.AutowireMode = AutoWiringMode.AutoDetect;
+ def.ConstructorArgumentValues.AddNamedArgumentValue("strategy", new RuntimeObjectReference("Strategy1") );
+
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.RegisterObjectDefinition("Class", def);
+ lof.RegisterObjectDefinition("ICollaborator", new RootObjectDefinition(typeof(Collaborator)));
+ lof.RegisterObjectDefinition("Strategy1", new RootObjectDefinition(typeof(Strategy1)));
+ lof.RegisterObjectDefinition("Strategy2", new RootObjectDefinition(typeof(Strategy1)));
+
+ Class1 c1 = (Class1) lof.GetObject("Class");
+ Assert.IsNotNull(c1);
+ Assert.AreEqual( typeof(Strategy1), c1.TheStrategy.GetType() );
+ }
+
+ [Test(Description = "http://jira.springframework.org/browse/SPRNET-985")]
+ public void AutowireByTypeHonoresOverridesBeforeThrowingUnsatisfiedDependencyException()
+ {
+ RootObjectDefinition def = new RootObjectDefinition(typeof(Class2));
+ def.AutowireMode = AutoWiringMode.AutoDetect;
+ def.PropertyValues.Add("strategy", new RuntimeObjectReference("Strategy1") );
+
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.RegisterObjectDefinition("Class", def);
+ lof.RegisterObjectDefinition("ICollaborator", new RootObjectDefinition(typeof(Collaborator)));
+ lof.RegisterObjectDefinition("Strategy1", new RootObjectDefinition(typeof(Strategy1)));
+ lof.RegisterObjectDefinition("Strategy2", new RootObjectDefinition(typeof(Strategy1)));
+
+ Class2 c2 = (Class2) lof.GetObject("Class");
+ Assert.IsNotNull(c2);
+ Assert.AreEqual( typeof(Strategy1), c2.Strategy.GetType() );
+ }
+
+ [Test(Description = "http://jira.springframework.org/browse/SPRNET-112")]
+ public void ObjectCreatedViaStaticFactoryMethodUsesReturnTypeOfFactoryMethodAsTheObjectType()
+ {
+ RootObjectDefinition def
+ = new RootObjectDefinition(typeof(TestObjectCreator));
+ def.FactoryMethodName = "CreateTestObject";
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.RegisterObjectDefinition("factoryObject", def);
+ IDictionary objs = lof.GetObjectsOfType(typeof(TestObject));
+ Assert.AreEqual(1, objs.Count);
+ }
+
+ [Test(Description = "http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
+ public void ObjectCreatedViaInstanceFactoryMethodUsesReturnTypeOfFactoryMethodAsTheObjectType()
+ {
+ RootObjectDefinition def
+ = new RootObjectDefinition(typeof(TestObjectCreator));
+ def.FactoryMethodName = "InstanceCreateTestObject";
+ def.FactoryObjectName = "target";
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.RegisterObjectDefinition("factoryObject", def);
+ lof.RegisterObjectDefinition("target", new RootObjectDefinition(typeof(TestObjectCreator)));
+ IDictionary objs = lof.GetObjectsOfType(typeof(TestObject));
+ Assert.AreEqual(1, objs.Count);
+ }
#if NET_2_0
- [Test(Description="http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
+ [Test(Description = "http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
public void ObjectCreatedViaStaticGenericFactoryMethodUsesReturnTypeOfGenericFactoryMethodAsTheObjectType()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
RootObjectDefinition def
- = new RootObjectDefinition(typeof(TestGenericObject));
+ = new RootObjectDefinition(typeof(TestGenericObject));
def.FactoryMethodName = "CreateList";
lof.RegisterObjectDefinition("foo", def);
IDictionary objs = lof.GetObjectsOfType(typeof(System.Collections.Generic.List));
Assert.AreEqual(1, objs.Count);
}
- [Test(Description="http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
+ [Test(Description = "http://opensource2.atlassian.com/projects/spring/browse/SPRNET-112")]
public void ObjectCreatedViaInstanceGenericFactoryMethodUsesReturnTypeOfGenericFactoryMethodAsTheObjectType()
{
RootObjectDefinition def
@@ -100,744 +175,744 @@ namespace Spring.Objects.Factory
def.FactoryObjectName = "target";
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
lof.RegisterObjectDefinition("factoryObject", def);
- lof.RegisterObjectDefinition("target", new RootObjectDefinition(typeof(TestGenericObject)));
- IDictionary objs = lof.GetObjectsOfType(typeof(TestGenericObject));
+ lof.RegisterObjectDefinition("target", new RootObjectDefinition(typeof(TestGenericObject)));
+ IDictionary objs = lof.GetObjectsOfType(typeof(TestGenericObject));
Assert.AreEqual(1, objs.Count);
}
#endif
- ///
- /// Object instantiation through factory method should not require type attribute.
- ///
- [Test(Description="http://opensource.atlassian.com/projects/spring/browse/SPRNET-130")]
- public void SPRNET_130()
- {
- const string factoryObjectName = "factoryObject";
- const string exampleObjectName = "exampleObject";
+ ///
+ /// Object instantiation through factory method should not require type attribute.
+ ///
+ [Test(Description = "http://opensource.atlassian.com/projects/spring/browse/SPRNET-130")]
+ public void SPRNET_130()
+ {
+ const string factoryObjectName = "factoryObject";
+ const string exampleObjectName = "exampleObject";
- RootObjectDefinition factoryObjectDefinition
- = new RootObjectDefinition(typeof(TestObjectFactory));
- RootObjectDefinition exampleObjectDefinition = new RootObjectDefinition();
- exampleObjectDefinition.FactoryObjectName = factoryObjectName;
- exampleObjectDefinition.FactoryMethodName = "GetObject";
+ RootObjectDefinition factoryObjectDefinition
+ = new RootObjectDefinition(typeof(TestObjectFactory));
+ RootObjectDefinition exampleObjectDefinition = new RootObjectDefinition();
+ exampleObjectDefinition.FactoryObjectName = factoryObjectName;
+ exampleObjectDefinition.FactoryMethodName = "GetObject";
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.RegisterObjectDefinition(factoryObjectName, factoryObjectDefinition);
- lof.RegisterObjectDefinition(exampleObjectName, exampleObjectDefinition);
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.RegisterObjectDefinition(factoryObjectName, factoryObjectDefinition);
+ lof.RegisterObjectDefinition(exampleObjectName, exampleObjectDefinition);
- object exampleObject = lof.GetObject(exampleObjectName);
- Assert.IsNotNull(exampleObject);
- object factoryObject = lof.GetObject(factoryObjectName);
- Assert.IsNotNull(factoryObject);
- }
+ object exampleObject = lof.GetObject(exampleObjectName);
+ Assert.IsNotNull(exampleObject);
+ object factoryObject = lof.GetObject(factoryObjectName);
+ Assert.IsNotNull(factoryObject);
+ }
- [Test(Description="http://opensource.atlassian.com/projects/spring/browse/SPR-1011")]
- public void SPR_1011()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition def
- = new RootObjectDefinition(
- typeof (StaticFactoryMethodObject));
- def.FactoryMethodName = "CreateObject";
- lof.RegisterObjectDefinition("foo", def);
- IDictionary objs = lof.GetObjectsOfType(typeof (DBNull));
- Assert.AreEqual(1, objs.Count,
- "Must be looking at the RETURN TYPE of the factory method, " +
- "and hence get one DBNull object back.");
- }
+ [Test(Description = "http://opensource.atlassian.com/projects/spring/browse/SPR-1011")]
+ public void SPR_1011()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition def
+ = new RootObjectDefinition(
+ typeof(StaticFactoryMethodObject));
+ def.FactoryMethodName = "CreateObject";
+ lof.RegisterObjectDefinition("foo", def);
+ IDictionary objs = lof.GetObjectsOfType(typeof(DBNull));
+ Assert.AreEqual(1, objs.Count,
+ "Must be looking at the RETURN TYPE of the factory method, " +
+ "and hence get one DBNull object back.");
+ }
- private sealed class StaticFactoryMethodObject
- {
- private StaticFactoryMethodObject()
- {
- }
+ private sealed class StaticFactoryMethodObject
+ {
+ private StaticFactoryMethodObject()
+ {
+ }
- public static DBNull CreateObject()
- {
- return DBNull.Value;
- }
- }
+ public static DBNull CreateObject()
+ {
+ return DBNull.Value;
+ }
+ }
- [Test(Description="http://opensource.atlassian.com/projects/spring/browse/SPR-1077")]
- public void SPR_1077()
- {
- DisposableTestObject sing = null;
- using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
- {
- RootObjectDefinition singleton
- = new RootObjectDefinition(typeof (DisposableTestObject));
- MutablePropertyValues sprops = new MutablePropertyValues();
- sprops.Add("name", "Rick");
- singleton.PropertyValues = sprops;
- lof.RegisterObjectDefinition("singleton", singleton);
+ [Test(Description = "http://opensource.atlassian.com/projects/spring/browse/SPR-1077")]
+ public void SPR_1077()
+ {
+ DisposableTestObject sing = null;
+ using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
+ {
+ RootObjectDefinition singleton
+ = new RootObjectDefinition(typeof(DisposableTestObject));
+ MutablePropertyValues sprops = new MutablePropertyValues();
+ sprops.Add("name", "Rick");
+ singleton.PropertyValues = sprops;
+ lof.RegisterObjectDefinition("singleton", singleton);
- RootObjectDefinition prototype
- = new RootObjectDefinition(typeof (TestObject));
- MutablePropertyValues pprops = new MutablePropertyValues();
- pprops.Add("name", "Jenny");
- // prototype has dependency on a singleton...
- pprops.Add("spouse", new RuntimeObjectReference("singleton"));
- prototype.PropertyValues = pprops;
- prototype.IsSingleton = false;
- lof.RegisterObjectDefinition("prototype", prototype);
+ RootObjectDefinition prototype
+ = new RootObjectDefinition(typeof(TestObject));
+ MutablePropertyValues pprops = new MutablePropertyValues();
+ pprops.Add("name", "Jenny");
+ // prototype has dependency on a singleton...
+ pprops.Add("spouse", new RuntimeObjectReference("singleton"));
+ prototype.PropertyValues = pprops;
+ prototype.IsSingleton = false;
+ lof.RegisterObjectDefinition("prototype", prototype);
- sing = (DisposableTestObject) lof.GetObject("singleton");
+ sing = (DisposableTestObject)lof.GetObject("singleton");
- lof.GetObject("prototype");
- lof.GetObject("prototype");
- lof.GetObject("prototype");
- lof.GetObject("prototype");
- }
- Assert.AreEqual(1, sing.NumTimesDisposed);
- }
+ lof.GetObject("prototype");
+ lof.GetObject("prototype");
+ lof.GetObject("prototype");
+ lof.GetObject("prototype");
+ }
+ Assert.AreEqual(1, sing.NumTimesDisposed);
+ }
- private sealed class DisposableTestObject : TestObject, IDisposable
- {
- private int _numTimesDisposed;
+ private sealed class DisposableTestObject : TestObject, IDisposable
+ {
+ private int _numTimesDisposed;
- public int NumTimesDisposed
- {
- get { return _numTimesDisposed; }
- }
+ public int NumTimesDisposed
+ {
+ get { return _numTimesDisposed; }
+ }
- public void Dispose()
- {
- ++_numTimesDisposed;
- }
- }
+ public void Dispose()
+ {
+ ++_numTimesDisposed;
+ }
+ }
- [Test]
- public void GetObjectPostProcessorCount()
- {
- DynamicMock mock1 = new DynamicMock(typeof (IObjectPostProcessor));
- IObjectPostProcessor proc1 = (IObjectPostProcessor) mock1.Object;
- DynamicMock mock2 = new DynamicMock(typeof (IObjectPostProcessor));
- IObjectPostProcessor proc2 = (IObjectPostProcessor) mock2.Object;
+ [Test]
+ public void GetObjectPostProcessorCount()
+ {
+ DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
+ IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
+ DynamicMock mock2 = new DynamicMock(typeof(IObjectPostProcessor));
+ IObjectPostProcessor proc2 = (IObjectPostProcessor)mock2.Object;
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
- Assert.AreEqual(0, lof.ObjectPostProcessorCount, errMsg);
- lof.AddObjectPostProcessor(proc1);
- Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
- lof.AddObjectPostProcessor(proc2);
- Assert.AreEqual(2, lof.ObjectPostProcessorCount, errMsg);
- }
+ const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
+ Assert.AreEqual(0, lof.ObjectPostProcessorCount, errMsg);
+ lof.AddObjectPostProcessor(proc1);
+ Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
+ lof.AddObjectPostProcessor(proc2);
+ Assert.AreEqual(2, lof.ObjectPostProcessorCount, errMsg);
+ }
- ///
- /// The ObjectPostProcessorCount property must only return the count of
- /// processors registered with the current factory, and not
- /// surf up any hierarchy.
- ///
- [Test]
- public void GetObjectPostProcessorCountDoesntRespectHierarchy()
- {
- DynamicMock mock1 = new DynamicMock(typeof (IObjectPostProcessor));
- IObjectPostProcessor proc1 = (IObjectPostProcessor) mock1.Object;
- DynamicMock mock2 = new DynamicMock(typeof (IObjectPostProcessor));
- IObjectPostProcessor proc2 = (IObjectPostProcessor) mock2.Object;
+ ///
+ /// The ObjectPostProcessorCount property must only return the count of
+ /// processors registered with the current factory, and not
+ /// surf up any hierarchy.
+ ///
+ [Test]
+ public void GetObjectPostProcessorCountDoesntRespectHierarchy()
+ {
+ DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
+ IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
+ DynamicMock mock2 = new DynamicMock(typeof(IObjectPostProcessor));
+ IObjectPostProcessor proc2 = (IObjectPostProcessor)mock2.Object;
- DefaultListableObjectFactory child = new DefaultListableObjectFactory();
- DefaultListableObjectFactory parent = new DefaultListableObjectFactory(child);
+ DefaultListableObjectFactory child = new DefaultListableObjectFactory();
+ DefaultListableObjectFactory parent = new DefaultListableObjectFactory(child);
- const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
- Assert.AreEqual(0, child.ObjectPostProcessorCount, errMsg);
- Assert.AreEqual(0, parent.ObjectPostProcessorCount, errMsg);
- child.AddObjectPostProcessor(proc1);
- Assert.AreEqual(1, child.ObjectPostProcessorCount, errMsg);
- Assert.AreEqual(0, parent.ObjectPostProcessorCount, errMsg);
- parent.AddObjectPostProcessor(proc2);
- Assert.AreEqual(1, child.ObjectPostProcessorCount, errMsg);
- Assert.AreEqual(1, parent.ObjectPostProcessorCount, errMsg);
- child.AddObjectPostProcessor(proc2);
- Assert.AreEqual(2, child.ObjectPostProcessorCount, errMsg);
- Assert.AreEqual(1, parent.ObjectPostProcessorCount, errMsg);
- }
+ const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
+ Assert.AreEqual(0, child.ObjectPostProcessorCount, errMsg);
+ Assert.AreEqual(0, parent.ObjectPostProcessorCount, errMsg);
+ child.AddObjectPostProcessor(proc1);
+ Assert.AreEqual(1, child.ObjectPostProcessorCount, errMsg);
+ Assert.AreEqual(0, parent.ObjectPostProcessorCount, errMsg);
+ parent.AddObjectPostProcessor(proc2);
+ Assert.AreEqual(1, child.ObjectPostProcessorCount, errMsg);
+ Assert.AreEqual(1, parent.ObjectPostProcessorCount, errMsg);
+ child.AddObjectPostProcessor(proc2);
+ Assert.AreEqual(2, child.ObjectPostProcessorCount, errMsg);
+ Assert.AreEqual(1, parent.ObjectPostProcessorCount, errMsg);
+ }
- [Test]
- public void TestIInstantiationAwareObjectPostProcessorsInterception()
- {
- ProxyingInstantiationAwareObjectPostProcessorStub proc
- = new ProxyingInstantiationAwareObjectPostProcessorStub("TheAgony");
+ [Test]
+ public void TestIInstantiationAwareObjectPostProcessorsInterception()
+ {
+ ProxyingInstantiationAwareObjectPostProcessorStub proc
+ = new ProxyingInstantiationAwareObjectPostProcessorStub("TheAgony");
- MutablePropertyValues props = new MutablePropertyValues();
- props.Add("Name", "Rick");
- RootObjectDefinition toBeProxied
- = new RootObjectDefinition(typeof (TestObject), props);
+ MutablePropertyValues props = new MutablePropertyValues();
+ props.Add("Name", "Rick");
+ RootObjectDefinition toBeProxied
+ = new RootObjectDefinition(typeof(TestObject), props);
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.AddObjectPostProcessor(proc);
- lof.RegisterObjectDefinition("toBeProxied", toBeProxied);
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.AddObjectPostProcessor(proc);
+ lof.RegisterObjectDefinition("toBeProxied", toBeProxied);
- object proxy = lof["toBeProxied"];
- Assert.IsNotNull(proxy);
- Assert.AreEqual("TheAgony", proxy);
- }
+ object proxy = lof["toBeProxied"];
+ Assert.IsNotNull(proxy);
+ Assert.AreEqual("TheAgony", proxy);
+ }
- [Test]
- public void TestIInstantiationAwareObjectPostProcessorsPassThrough()
- {
- NullInstantiationAwareObjectPostProcessorStub proc
- = new NullInstantiationAwareObjectPostProcessorStub();
+ [Test]
+ public void TestIInstantiationAwareObjectPostProcessorsPassThrough()
+ {
+ NullInstantiationAwareObjectPostProcessorStub proc
+ = new NullInstantiationAwareObjectPostProcessorStub();
- MutablePropertyValues props = new MutablePropertyValues();
- props.Add("Name", "Rick");
- RootObjectDefinition not
- = new RootObjectDefinition(typeof (TestObject), props);
+ MutablePropertyValues props = new MutablePropertyValues();
+ props.Add("Name", "Rick");
+ RootObjectDefinition not
+ = new RootObjectDefinition(typeof(TestObject), props);
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.AddObjectPostProcessor(proc);
- lof.RegisterObjectDefinition("notToBeProxied", not);
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.AddObjectPostProcessor(proc);
+ lof.RegisterObjectDefinition("notToBeProxied", not);
- object foo = lof["notToBeProxied"];
- Assert.IsNotNull(foo);
- Assert.AreEqual(typeof (TestObject), foo.GetType());
- TestObject to = (TestObject) foo;
- Assert.AreEqual("Rick", to.Name);
- }
+ object foo = lof["notToBeProxied"];
+ Assert.IsNotNull(foo);
+ Assert.AreEqual(typeof(TestObject), foo.GetType());
+ TestObject to = (TestObject)foo;
+ Assert.AreEqual("Rick", to.Name);
+ }
- private sealed class NullInstantiationAwareObjectPostProcessorStub
- : IInstantiationAwareObjectPostProcessor
- {
- public NullInstantiationAwareObjectPostProcessorStub()
- {
- }
+ private sealed class NullInstantiationAwareObjectPostProcessorStub
+ : IInstantiationAwareObjectPostProcessor
+ {
+ public NullInstantiationAwareObjectPostProcessorStub()
+ {
+ }
- public object PostProcessBeforeInitialization(object obj, string name)
- {
- return obj;
- }
+ public object PostProcessBeforeInitialization(object obj, string name)
+ {
+ return obj;
+ }
- public object PostProcessBeforeInstantiation(Type objectType, string objectName)
- {
+ public object PostProcessBeforeInstantiation(Type objectType, string objectName)
+ {
//proceed with default instantiation
- return null;
- }
+ return null;
+ }
- public bool PostProcessAfterInstantiation(object objectInstance, string objectName)
- {
+ public bool PostProcessAfterInstantiation(object objectInstance, string objectName)
+ {
//proceed to set properties on the object
- return true;
- }
+ return true;
+ }
- #region IInstantiationAwareObjectPostProcessor Members
+ #region IInstantiationAwareObjectPostProcessor Members
- public IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, PropertyInfo[] pis, object objectInstance,
- string objectName)
- {
- return pvs;
- }
+ public IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, PropertyInfo[] pis, object objectInstance,
+ string objectName)
+ {
+ return pvs;
+ }
- #endregion
+ #endregion
- public object PostProcessAfterInitialization(object obj, string objectName)
- {
- return obj;
- }
- }
+ public object PostProcessAfterInitialization(object obj, string objectName)
+ {
+ return obj;
+ }
+ }
- private sealed class ProxyingInstantiationAwareObjectPostProcessorStub
- : IInstantiationAwareObjectPostProcessor
- {
- public ProxyingInstantiationAwareObjectPostProcessorStub()
- {
- }
+ private sealed class ProxyingInstantiationAwareObjectPostProcessorStub
+ : IInstantiationAwareObjectPostProcessor
+ {
+ public ProxyingInstantiationAwareObjectPostProcessorStub()
+ {
+ }
- public ProxyingInstantiationAwareObjectPostProcessorStub(object proxy)
- {
- _proxy = proxy;
- }
+ public ProxyingInstantiationAwareObjectPostProcessorStub(object proxy)
+ {
+ _proxy = proxy;
+ }
- private object _proxy;
+ private object _proxy;
- public object Proxy
- {
- get { return _proxy; }
- set { _proxy = value; }
- }
+ public object Proxy
+ {
+ get { return _proxy; }
+ set { _proxy = value; }
+ }
- public object PostProcessBeforeInitialization(object obj, string name)
- {
- throw new NotImplementedException();
- }
+ public object PostProcessBeforeInitialization(object obj, string name)
+ {
+ throw new NotImplementedException();
+ }
- public object PostProcessBeforeInstantiation(Type objectType, string objectName)
- {
- return _proxy;
- }
+ public object PostProcessBeforeInstantiation(Type objectType, string objectName)
+ {
+ return _proxy;
+ }
- public bool PostProcessAfterInstantiation(object objectInstance, string objectName)
- {
- return true;
- }
+ public bool PostProcessAfterInstantiation(object objectInstance, string objectName)
+ {
+ return true;
+ }
- #region IInstantiationAwareObjectPostProcessor Members
+ #region IInstantiationAwareObjectPostProcessor Members
- public IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, PropertyInfo[] pis, object objectInstance,
- string objectName)
- {
- return pvs;
- }
+ public IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, PropertyInfo[] pis, object objectInstance,
+ string objectName)
+ {
+ return pvs;
+ }
- #endregion
+ #endregion
- public object PostProcessAfterInitialization(object obj, string objectName)
- {
- throw new NotImplementedException();
- }
- }
+ public object PostProcessAfterInitialization(object obj, string objectName)
+ {
+ throw new NotImplementedException();
+ }
+ }
- [Test]
- public void PreInstantiateSingletonsMustNotIgnoreObjectsWithUnresolvedObjectTypes()
- {
- KnowsIfInstantiated.ClearInstantiationRecord();
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
- RootObjectDefinition def = new RootObjectDefinition();
- def.ObjectTypeName = typeof (KnowsIfInstantiated).FullName;
- lof.RegisterObjectDefinition("x1", def);
- Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
- lof.PreInstantiateSingletons();
- Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
- }
+ [Test]
+ public void PreInstantiateSingletonsMustNotIgnoreObjectsWithUnresolvedObjectTypes()
+ {
+ KnowsIfInstantiated.ClearInstantiationRecord();
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
+ RootObjectDefinition def = new RootObjectDefinition();
+ def.ObjectTypeName = typeof(KnowsIfInstantiated).FullName;
+ lof.RegisterObjectDefinition("x1", def);
+ Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
+ lof.PreInstantiateSingletons();
+ Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
+ }
- [Test]
- public void LazyInitialization()
- {
- KnowsIfInstantiated.ClearInstantiationRecord();
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ [Test]
+ public void LazyInitialization()
+ {
+ KnowsIfInstantiated.ClearInstantiationRecord();
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition def = new RootObjectDefinition();
- def.ObjectTypeName = typeof (KnowsIfInstantiated).FullName;
- def.IsLazyInit = true;
- lof.RegisterObjectDefinition("x1", def);
+ RootObjectDefinition def = new RootObjectDefinition();
+ def.ObjectTypeName = typeof(KnowsIfInstantiated).FullName;
+ def.IsLazyInit = true;
+ lof.RegisterObjectDefinition("x1", def);
- Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
- lof.RegisterObjectDefinition("x1", def);
- Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
- lof.PreInstantiateSingletons();
- Assert.IsFalse(KnowsIfInstantiated.WasInstantiated, "Singleton was instantiated by the container (it must NOT be 'cos LazyInit was set to TRUE).");
- lof.GetObject("x1");
- Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
- }
+ Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
+ lof.RegisterObjectDefinition("x1", def);
+ Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
+ lof.PreInstantiateSingletons();
+ Assert.IsFalse(KnowsIfInstantiated.WasInstantiated, "Singleton was instantiated by the container (it must NOT be 'cos LazyInit was set to TRUE).");
+ lof.GetObject("x1");
+ Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
+ }
- [Test]
- public void SingletonFactoryObjectMustNotCreatePrototypeOnPreInstantiateSingletonsCall()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ [Test]
+ public void SingletonFactoryObjectMustNotCreatePrototypeOnPreInstantiateSingletonsCall()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition def = new RootObjectDefinition();
- def.ObjectType = typeof (DummyFactory);
- def.IsSingleton = true;
- def.PropertyValues.Add("IsSingleton", false);
+ RootObjectDefinition def = new RootObjectDefinition();
+ def.ObjectType = typeof(DummyFactory);
+ def.IsSingleton = true;
+ def.PropertyValues.Add("IsSingleton", false);
- DummyFactory.Reset();
+ DummyFactory.Reset();
- Assert.IsFalse(DummyFactory.WasPrototypeCreated,
- "Prototype appears to be instantiated before the test is even run.");
- lof.RegisterObjectDefinition("x1", def);
- Assert.IsFalse(DummyFactory.WasPrototypeCreated,
- "Prototype instantiated after object definition registration (must NOT be).");
- lof.PreInstantiateSingletons();
- Assert.IsFalse(DummyFactory.WasPrototypeCreated,
- "Prototype instantiated after call to PreInstantiateSingletons(); must NOT be.");
- lof.GetObject("x1");
- Assert.IsTrue(DummyFactory.WasPrototypeCreated, "Prototype was not instantiated.");
- }
+ Assert.IsFalse(DummyFactory.WasPrototypeCreated,
+ "Prototype appears to be instantiated before the test is even run.");
+ lof.RegisterObjectDefinition("x1", def);
+ Assert.IsFalse(DummyFactory.WasPrototypeCreated,
+ "Prototype instantiated after object definition registration (must NOT be).");
+ lof.PreInstantiateSingletons();
+ Assert.IsFalse(DummyFactory.WasPrototypeCreated,
+ "Prototype instantiated after call to PreInstantiateSingletons(); must NOT be.");
+ lof.GetObject("x1");
+ Assert.IsTrue(DummyFactory.WasPrototypeCreated, "Prototype was not instantiated.");
+ }
- [Test]
- public void Empty()
- {
- IListableObjectFactory lof = new DefaultListableObjectFactory();
- Assert.IsTrue(lof.GetObjectDefinitionNames() != null, "No objects defined --> array != null");
- Assert.IsTrue(lof.GetObjectDefinitionNames().Length == 0, "No objects defined after no arg constructor");
- Assert.IsTrue(lof.ObjectDefinitionCount == 0, "No objects defined after no arg constructor");
- }
+ [Test]
+ public void Empty()
+ {
+ IListableObjectFactory lof = new DefaultListableObjectFactory();
+ Assert.IsTrue(lof.GetObjectDefinitionNames() != null, "No objects defined --> array != null");
+ Assert.IsTrue(lof.GetObjectDefinitionNames().Length == 0, "No objects defined after no arg constructor");
+ Assert.IsTrue(lof.ObjectDefinitionCount == 0, "No objects defined after no arg constructor");
+ }
- [Test]
- public void ObjectDefinitionCountIsZeroBeforeAnythingIsRegistered()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- Assert.AreEqual(0, lof.ObjectDefinitionCount, "No objects must be defined straight off the bat.");
- }
+ [Test]
+ public void ObjectDefinitionCountIsZeroBeforeAnythingIsRegistered()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ Assert.AreEqual(0, lof.ObjectDefinitionCount, "No objects must be defined straight off the bat.");
+ }
- [Test]
- public void ObjectDefinitionOverriding()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof (TestObject), null));
- lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof (NestedTestObject), null));
- Assert.IsTrue(lof.GetObject("test") is NestedTestObject);
- }
+ [Test]
+ public void ObjectDefinitionOverriding()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof(TestObject), null));
+ lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof(NestedTestObject), null));
+ Assert.IsTrue(lof.GetObject("test") is NestedTestObject);
+ }
- [Test]
- [ExpectedException(typeof (ObjectDefinitionStoreException))]
- public void ObjectDefinitionOverridingNotAllowed()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.AllowObjectDefinitionOverriding = false;
- lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof (TestObject), null));
- lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof (NestedTestObject), null));
- }
+ [Test]
+ [ExpectedException(typeof(ObjectDefinitionStoreException))]
+ public void ObjectDefinitionOverridingNotAllowed()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.AllowObjectDefinitionOverriding = false;
+ lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof(TestObject), null));
+ lof.RegisterObjectDefinition("test", new RootObjectDefinition(typeof(NestedTestObject), null));
+ }
- [Test]
- public void CustomEditor()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- NumberFormatInfo nfi = new CultureInfo("en-GB", false).NumberFormat;
- lof.RegisterCustomConverter(typeof (Single), new CustomNumberConverter(typeof (Single), nfi, true));
- MutablePropertyValues pvs = new MutablePropertyValues();
- pvs.Add("myFloat", "1.1");
- lof.RegisterObjectDefinition("testObject", new RootObjectDefinition(typeof (TestObject), pvs));
- TestObject testObject = (TestObject) lof.GetObject("testObject");
- Assert.IsTrue(testObject.MyFloat == 1.1f);
- }
+ [Test]
+ public void CustomEditor()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ NumberFormatInfo nfi = new CultureInfo("en-GB", false).NumberFormat;
+ lof.RegisterCustomConverter(typeof(Single), new CustomNumberConverter(typeof(Single), nfi, true));
+ MutablePropertyValues pvs = new MutablePropertyValues();
+ pvs.Add("myFloat", "1.1");
+ lof.RegisterObjectDefinition("testObject", new RootObjectDefinition(typeof(TestObject), pvs));
+ TestObject testObject = (TestObject)lof.GetObject("testObject");
+ Assert.IsTrue(testObject.MyFloat == 1.1f);
+ }
- [Test]
- public void RegisterExistingSingletonWithReference()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ [Test]
+ public void RegisterExistingSingletonWithReference()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition def = new RootObjectDefinition();
- def.ObjectType = typeof (TestObject);
- def.PropertyValues.Add("Name", "Rick");
- def.PropertyValues.Add("Age", 30);
- def.PropertyValues.Add("Spouse", new RuntimeObjectReference("singletonObject"));
- lof.RegisterObjectDefinition("test", def);
+ RootObjectDefinition def = new RootObjectDefinition();
+ def.ObjectType = typeof(TestObject);
+ def.PropertyValues.Add("Name", "Rick");
+ def.PropertyValues.Add("Age", 30);
+ def.PropertyValues.Add("Spouse", new RuntimeObjectReference("singletonObject"));
+ lof.RegisterObjectDefinition("test", def);
- object singletonObject = new TestObject();
- lof.RegisterSingleton("singletonObject", singletonObject);
- Assert.IsTrue(lof.IsSingleton("singletonObject"));
- TestObject test = (TestObject) lof.GetObject("test");
- Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
- Assert.AreEqual(singletonObject, test.Spouse);
- Hashtable objectsOfType = (Hashtable) lof.GetObjectsOfType(typeof (TestObject), false, true);
- Assert.AreEqual(2, objectsOfType.Count);
- Assert.IsTrue(objectsOfType.ContainsValue(test));
- Assert.IsTrue(objectsOfType.ContainsValue(singletonObject));
- }
+ object singletonObject = new TestObject();
+ lof.RegisterSingleton("singletonObject", singletonObject);
+ Assert.IsTrue(lof.IsSingleton("singletonObject"));
+ TestObject test = (TestObject)lof.GetObject("test");
+ Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
+ Assert.AreEqual(singletonObject, test.Spouse);
+ Hashtable objectsOfType = (Hashtable)lof.GetObjectsOfType(typeof(TestObject), false, true);
+ Assert.AreEqual(2, objectsOfType.Count);
+ Assert.IsTrue(objectsOfType.ContainsValue(test));
+ Assert.IsTrue(objectsOfType.ContainsValue(singletonObject));
+ }
- [Test]
- public void ApplyPropertyValues()
- {
- DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
- MutablePropertyValues properties = new MutablePropertyValues();
- properties.Add("age", "99");
- factory.RegisterObjectDefinition("test", new RootObjectDefinition(typeof (TestObject), properties));
- TestObject obj = new TestObject();
- Assert.AreEqual(0, obj.Age);
- factory.ApplyObjectPropertyValues(obj, "test");
- Assert.AreEqual(99, obj.Age, "Property values were not applied to the existing instance.");
- }
+ [Test]
+ public void ApplyPropertyValues()
+ {
+ DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
+ MutablePropertyValues properties = new MutablePropertyValues();
+ properties.Add("age", "99");
+ factory.RegisterObjectDefinition("test", new RootObjectDefinition(typeof(TestObject), properties));
+ TestObject obj = new TestObject();
+ Assert.AreEqual(0, obj.Age);
+ factory.ApplyObjectPropertyValues(obj, "test");
+ Assert.AreEqual(99, obj.Age, "Property values were not applied to the existing instance.");
+ }
- [Test]
- public void ApplyPropertyValuesWithIncompleteDefinition()
- {
- DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
- MutablePropertyValues properties = new MutablePropertyValues();
- properties.Add("age", "99");
- factory.RegisterObjectDefinition("test", new RootObjectDefinition(null, properties));
- TestObject obj = new TestObject();
- Assert.AreEqual(0, obj.Age);
- factory.ApplyObjectPropertyValues(obj, "test");
- Assert.AreEqual(99, obj.Age, "Property values were not applied to the existing instance.");
- }
+ [Test]
+ public void ApplyPropertyValuesWithIncompleteDefinition()
+ {
+ DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
+ MutablePropertyValues properties = new MutablePropertyValues();
+ properties.Add("age", "99");
+ factory.RegisterObjectDefinition("test", new RootObjectDefinition(null, properties));
+ TestObject obj = new TestObject();
+ Assert.AreEqual(0, obj.Age);
+ factory.ApplyObjectPropertyValues(obj, "test");
+ Assert.AreEqual(99, obj.Age, "Property values were not applied to the existing instance.");
+ }
- [Test]
- public void RegisterExistingSingletonWithAutowire()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- MutablePropertyValues pvs = new MutablePropertyValues();
- pvs.Add("name", "Tony");
- pvs.Add("age", "48");
- RootObjectDefinition rod = new RootObjectDefinition(typeof (DependenciesObject), pvs, true);
- rod.DependencyCheck = DependencyCheckingMode.Objects;
- rod.AutowireMode = AutoWiringMode.ByType;
- lof.RegisterObjectDefinition("test", rod);
- object singletonObject = new TestObject();
- lof.RegisterSingleton("singletonObject", singletonObject);
- Assert.IsTrue(lof.ContainsObject("singletonObject"));
- Assert.IsTrue(lof.IsSingleton("singletonObject"));
- Assert.AreEqual(0, lof.GetAliases("singletonObject").Length);
- DependenciesObject test = (DependenciesObject) lof.GetObject("test");
- Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
- Assert.AreEqual(singletonObject, test.Spouse);
- }
+ [Test]
+ public void RegisterExistingSingletonWithAutowire()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ MutablePropertyValues pvs = new MutablePropertyValues();
+ pvs.Add("name", "Tony");
+ pvs.Add("age", "48");
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(DependenciesObject), pvs, true);
+ rod.DependencyCheck = DependencyCheckingMode.Objects;
+ rod.AutowireMode = AutoWiringMode.ByType;
+ lof.RegisterObjectDefinition("test", rod);
+ object singletonObject = new TestObject();
+ lof.RegisterSingleton("singletonObject", singletonObject);
+ Assert.IsTrue(lof.ContainsObject("singletonObject"));
+ Assert.IsTrue(lof.IsSingleton("singletonObject"));
+ Assert.AreEqual(0, lof.GetAliases("singletonObject").Length);
+ DependenciesObject test = (DependenciesObject)lof.GetObject("test");
+ Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
+ Assert.AreEqual(singletonObject, test.Spouse);
+ }
- [Test]
- [ExpectedException(typeof (ObjectDefinitionStoreException))]
- public void RegisterExistingSingletonWithAlreadyBound()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- object singletonObject = new TestObject();
- lof.RegisterSingleton("singletonObject", singletonObject);
- lof.RegisterSingleton("singletonObject", singletonObject);
- }
+ [Test]
+ [ExpectedException(typeof(ObjectDefinitionStoreException))]
+ public void RegisterExistingSingletonWithAlreadyBound()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ object singletonObject = new TestObject();
+ lof.RegisterSingleton("singletonObject", singletonObject);
+ lof.RegisterSingleton("singletonObject", singletonObject);
+ }
- [Test]
- public void AutowireConstructor()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("spouse", rod);
- ConstructorDependenciesObject cdo = (ConstructorDependenciesObject) lof.Autowire(typeof (ConstructorDependenciesObject),
- AutoWiringMode.Constructor, true);
- object spouse = lof.GetObject("spouse");
- Assert.IsTrue(cdo.Spouse1 == spouse);
- Assert.IsTrue(ObjectFactoryUtils.ObjectOfType(lof, typeof (TestObject)) == spouse);
- }
+ [Test]
+ public void AutowireConstructor()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("spouse", rod);
+ ConstructorDependenciesObject cdo = (ConstructorDependenciesObject)lof.Autowire(typeof(ConstructorDependenciesObject),
+ AutoWiringMode.Constructor, true);
+ object spouse = lof.GetObject("spouse");
+ Assert.IsTrue(cdo.Spouse1 == spouse);
+ Assert.IsTrue(ObjectFactoryUtils.ObjectOfType(lof, typeof(TestObject)) == spouse);
+ }
- [Test]
- public void AutowireObjectByName()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rodDefinition = new RootObjectDefinition(typeof (TestObject));
- rodDefinition.PropertyValues.Add("name", "Rod");
- rodDefinition.AutowireMode = AutoWiringMode.ByName;
- RootObjectDefinition kerryDefinition = new RootObjectDefinition(typeof (TestObject));
- kerryDefinition.PropertyValues.Add("name", "Kerry");
- lof.RegisterObjectDefinition("rod", rodDefinition);
- lof.RegisterObjectDefinition("Spouse", kerryDefinition);
- DependenciesObject obj = (DependenciesObject) lof.Autowire(typeof (DependenciesObject),
- AutoWiringMode.ByName, true);
- TestObject objRod = (TestObject) lof.GetObject("rod");
- Assert.AreEqual(obj.Spouse, objRod.Spouse);
- }
+ [Test]
+ public void AutowireObjectByName()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rodDefinition = new RootObjectDefinition(typeof(TestObject));
+ rodDefinition.PropertyValues.Add("name", "Rod");
+ rodDefinition.AutowireMode = AutoWiringMode.ByName;
+ RootObjectDefinition kerryDefinition = new RootObjectDefinition(typeof(TestObject));
+ kerryDefinition.PropertyValues.Add("name", "Kerry");
+ lof.RegisterObjectDefinition("rod", rodDefinition);
+ lof.RegisterObjectDefinition("Spouse", kerryDefinition);
+ DependenciesObject obj = (DependenciesObject)lof.Autowire(typeof(DependenciesObject),
+ AutoWiringMode.ByName, true);
+ TestObject objRod = (TestObject)lof.GetObject("rod");
+ Assert.AreEqual(obj.Spouse, objRod.Spouse);
+ }
- [Test]
- public void AutowireObjectByNameIsNotCaseInsensitive()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rodDefinition = new RootObjectDefinition(typeof (TestObject));
- rodDefinition.PropertyValues.Add("name", "Rod");
- rodDefinition.AutowireMode = AutoWiringMode.ByName;
- RootObjectDefinition kerryDefinition = new RootObjectDefinition(typeof (TestObject));
- kerryDefinition.PropertyValues.Add("name", "Kerry");
- lof.RegisterObjectDefinition("rod", rodDefinition);
- lof.RegisterObjectDefinition("spouse", kerryDefinition); // property name is Spouse (capital S)
- TestObject objRod = (TestObject) lof.GetObject("rod");
- Assert.IsNull(objRod.Spouse, "Mmm, Spouse property appears to have been autowired by name, even though there is no object in the factory with a name 'Spouse'.");
- }
+ [Test]
+ public void AutowireObjectByNameIsNotCaseInsensitive()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rodDefinition = new RootObjectDefinition(typeof(TestObject));
+ rodDefinition.PropertyValues.Add("name", "Rod");
+ rodDefinition.AutowireMode = AutoWiringMode.ByName;
+ RootObjectDefinition kerryDefinition = new RootObjectDefinition(typeof(TestObject));
+ kerryDefinition.PropertyValues.Add("name", "Kerry");
+ lof.RegisterObjectDefinition("rod", rodDefinition);
+ lof.RegisterObjectDefinition("spouse", kerryDefinition); // property name is Spouse (capital S)
+ TestObject objRod = (TestObject)lof.GetObject("rod");
+ Assert.IsNull(objRod.Spouse, "Mmm, Spouse property appears to have been autowired by name, even though there is no object in the factory with a name 'Spouse'.");
+ }
- [Test]
- [ExpectedException(typeof (UnsatisfiedDependencyException))]
- public void AutowireObjectByNameWithDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("Spous", rod);
- lof.Autowire(typeof (DependenciesObject), AutoWiringMode.ByName, true);
- }
+ [Test]
+ [ExpectedException(typeof(UnsatisfiedDependencyException))]
+ public void AutowireObjectByNameWithDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("Spous", rod);
+ lof.Autowire(typeof(DependenciesObject), AutoWiringMode.ByName, true);
+ }
- [Test]
- public void AutowireObjectByNameWithNoDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("Spous", rod);
- DependenciesObject obj = (DependenciesObject) lof.Autowire(typeof (DependenciesObject), AutoWiringMode.ByName, false);
- Assert.IsNull(obj.Spouse);
- }
+ [Test]
+ public void AutowireObjectByNameWithNoDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("Spous", rod);
+ DependenciesObject obj = (DependenciesObject)lof.Autowire(typeof(DependenciesObject), AutoWiringMode.ByName, false);
+ Assert.IsNull(obj.Spouse);
+ }
- [Test]
- public void AutowireObjectByType()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("test", rod);
- DependenciesObject obj = (DependenciesObject) lof.Autowire(typeof (DependenciesObject), AutoWiringMode.ByType, true);
- TestObject test = (TestObject) lof.GetObject("test");
- Assert.AreEqual(obj.Spouse, test);
- }
+ [Test]
+ public void AutowireObjectByType()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("test", rod);
+ DependenciesObject obj = (DependenciesObject)lof.Autowire(typeof(DependenciesObject), AutoWiringMode.ByType, true);
+ TestObject test = (TestObject)lof.GetObject("test");
+ Assert.AreEqual(obj.Spouse, test);
+ }
- [Test]
- [ExpectedException(typeof (UnsatisfiedDependencyException))]
- public void AutowireObjectByTypeWithDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- lof.Autowire(typeof (DependenciesObject), AutoWiringMode.ByType, true);
- Assert.Fail("Should have thrown UnsatisfiedDependencyException");
- }
+ [Test]
+ [ExpectedException(typeof(UnsatisfiedDependencyException))]
+ public void AutowireObjectByTypeWithDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ lof.Autowire(typeof(DependenciesObject), AutoWiringMode.ByType, true);
+ Assert.Fail("Should have thrown UnsatisfiedDependencyException");
+ }
- [Test]
- public void AutowireObjectByTypeWithNoDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- DependenciesObject obj = (DependenciesObject) lof.Autowire(typeof (DependenciesObject), AutoWiringMode.ByType, false);
- Assert.IsNull(obj.Spouse);
- }
+ [Test]
+ public void AutowireObjectByTypeWithNoDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ DependenciesObject obj = (DependenciesObject)lof.Autowire(typeof(DependenciesObject), AutoWiringMode.ByType, false);
+ Assert.IsNull(obj.Spouse);
+ }
- [Test]
- public void AutowireExistingObjectByName()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("Spouse", rod);
- DependenciesObject existingObj = new DependenciesObject();
- lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, true);
- TestObject spouse = (TestObject) lof.GetObject("Spouse");
- Assert.AreEqual(existingObj.Spouse, spouse);
- Assert.IsTrue(ObjectFactoryUtils.ObjectOfType(lof, typeof (TestObject)) == spouse);
- }
+ [Test]
+ public void AutowireExistingObjectByName()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("Spouse", rod);
+ DependenciesObject existingObj = new DependenciesObject();
+ lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, true);
+ TestObject spouse = (TestObject)lof.GetObject("Spouse");
+ Assert.AreEqual(existingObj.Spouse, spouse);
+ Assert.IsTrue(ObjectFactoryUtils.ObjectOfType(lof, typeof(TestObject)) == spouse);
+ }
- [Test]
- [ExpectedException(typeof (UnsatisfiedDependencyException))]
- public void AutowireExistingObjectByNameWithDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("Spous", rod);
- DependenciesObject existingObj = new DependenciesObject();
- lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, true);
- Assert.Fail("Should have thrown UnsatisfiedDependencyException");
- }
+ [Test]
+ [ExpectedException(typeof(UnsatisfiedDependencyException))]
+ public void AutowireExistingObjectByNameWithDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("Spous", rod);
+ DependenciesObject existingObj = new DependenciesObject();
+ lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, true);
+ Assert.Fail("Should have thrown UnsatisfiedDependencyException");
+ }
- [Test]
- public void AutowireExistingObjectByNameWithNoDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("Spous", rod);
- DependenciesObject existingObj = new DependenciesObject();
- lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, false);
- Assert.IsNull(existingObj.Spouse);
- }
+ [Test]
+ public void AutowireExistingObjectByNameWithNoDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("Spous", rod);
+ DependenciesObject existingObj = new DependenciesObject();
+ lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, false);
+ Assert.IsNull(existingObj.Spouse);
+ }
- [Test]
- public void AutowireExistingObjectByType()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("test", rod);
- DependenciesObject existingObj = new DependenciesObject();
- lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, true);
- TestObject test = (TestObject) lof.GetObject("test");
- Assert.AreEqual(existingObj.Spouse, test);
- }
+ [Test]
+ public void AutowireExistingObjectByType()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("test", rod);
+ DependenciesObject existingObj = new DependenciesObject();
+ lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, true);
+ TestObject test = (TestObject)lof.GetObject("test");
+ Assert.AreEqual(existingObj.Spouse, test);
+ }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void AutowireByTypeWithInvalidAutowireMode()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- DependenciesObject obj = new DependenciesObject();
- lof.AutowireObjectProperties(obj, AutoWiringMode.Constructor, true);
- }
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void AutowireByTypeWithInvalidAutowireMode()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ DependenciesObject obj = new DependenciesObject();
+ lof.AutowireObjectProperties(obj, AutoWiringMode.Constructor, true);
+ }
- [Test]
- [ExpectedException(typeof (UnsatisfiedDependencyException))]
- public void AutowireExistingObjectByTypeWithDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- DependenciesObject existingObj = new DependenciesObject();
- lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, true);
- }
+ [Test]
+ [ExpectedException(typeof(UnsatisfiedDependencyException))]
+ public void AutowireExistingObjectByTypeWithDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ DependenciesObject existingObj = new DependenciesObject();
+ lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, true);
+ }
- [Test]
- public void AutowireExistingObjectByTypeWithNoDependencyCheck()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- DependenciesObject existingObj = new DependenciesObject();
- lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, false);
- Assert.IsNull(existingObj.Spouse);
- }
+ [Test]
+ public void AutowireExistingObjectByTypeWithNoDependencyCheck()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ DependenciesObject existingObj = new DependenciesObject();
+ lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, false);
+ Assert.IsNull(existingObj.Spouse);
+ }
- [Test]
- public void AutowireWithNoDependencies()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject));
- lof.RegisterObjectDefinition("rod", rod);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- object registered = lof.Autowire(typeof (NoDependencies), AutoWiringMode.AutoDetect, false);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- Assert.IsTrue(registered is NoDependencies);
- }
+ [Test]
+ public void AutowireWithNoDependencies()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
+ lof.RegisterObjectDefinition("rod", rod);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ object registered = lof.Autowire(typeof(NoDependencies), AutoWiringMode.AutoDetect, false);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ Assert.IsTrue(registered is NoDependencies);
+ }
- [Test]
- public void AutowireWithSatisfiedObjectDependency()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- MutablePropertyValues pvs = new MutablePropertyValues();
- pvs.Add(new PropertyValue("name", "Rod"));
- RootObjectDefinition rood = new RootObjectDefinition(typeof (TestObject), pvs);
- lof.RegisterObjectDefinition("rod", rood);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- // Depends on age, name and spouse (TestObject)
- object registered = lof.Autowire(typeof (DependenciesObject), AutoWiringMode.AutoDetect, true);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- DependenciesObject kerry = (DependenciesObject) registered;
- TestObject rod = (TestObject) lof.GetObject("rod");
- Assert.AreSame(rod, kerry.Spouse);
- }
+ [Test]
+ public void AutowireWithSatisfiedObjectDependency()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ MutablePropertyValues pvs = new MutablePropertyValues();
+ pvs.Add(new PropertyValue("name", "Rod"));
+ RootObjectDefinition rood = new RootObjectDefinition(typeof(TestObject), pvs);
+ lof.RegisterObjectDefinition("rod", rood);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ // Depends on age, name and spouse (TestObject)
+ object registered = lof.Autowire(typeof(DependenciesObject), AutoWiringMode.AutoDetect, true);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ DependenciesObject kerry = (DependenciesObject)registered;
+ TestObject rod = (TestObject)lof.GetObject("rod");
+ Assert.AreSame(rod, kerry.Spouse);
+ }
- [Test]
- public void AutowireWithSatisfiedConstructorDependency()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- MutablePropertyValues pvs = new MutablePropertyValues();
- pvs.Add(new PropertyValue("name", "Rod"));
- RootObjectDefinition rood = new RootObjectDefinition(typeof (TestObject), pvs);
- lof.RegisterObjectDefinition("rod", rood);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- object registered = lof.Autowire(typeof (ConstructorDependency), AutoWiringMode.AutoDetect, false);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- ConstructorDependency kerry = (ConstructorDependency) registered;
- TestObject rod = (TestObject) lof.GetObject("rod");
- Assert.AreSame(rod, kerry._spouse);
- }
+ [Test]
+ public void AutowireWithSatisfiedConstructorDependency()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ MutablePropertyValues pvs = new MutablePropertyValues();
+ pvs.Add(new PropertyValue("name", "Rod"));
+ RootObjectDefinition rood = new RootObjectDefinition(typeof(TestObject), pvs);
+ lof.RegisterObjectDefinition("rod", rood);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ object registered = lof.Autowire(typeof(ConstructorDependency), AutoWiringMode.AutoDetect, false);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ ConstructorDependency kerry = (ConstructorDependency)registered;
+ TestObject rod = (TestObject)lof.GetObject("rod");
+ Assert.AreSame(rod, kerry._spouse);
+ }
- [Test]
- [ExpectedException(typeof (UnsatisfiedDependencyException))]
- public void AutowireWithUnsatisfiedConstructorDependency()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- MutablePropertyValues pvs = new MutablePropertyValues();
- pvs.Add(new PropertyValue("name", "Rod"));
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject), pvs);
- lof.RegisterObjectDefinition("rod", rod);
- Assert.AreEqual(1, lof.ObjectDefinitionCount);
- lof.Autowire(typeof (UnsatisfiedConstructorDependency), AutoWiringMode.AutoDetect, true);
- Assert.Fail("Should have unsatisfied constructor dependency on SideEffectObject");
- }
+ [Test]
+ [ExpectedException(typeof(UnsatisfiedDependencyException))]
+ public void AutowireWithUnsatisfiedConstructorDependency()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ MutablePropertyValues pvs = new MutablePropertyValues();
+ pvs.Add(new PropertyValue("name", "Rod"));
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), pvs);
+ lof.RegisterObjectDefinition("rod", rod);
+ Assert.AreEqual(1, lof.ObjectDefinitionCount);
+ lof.Autowire(typeof(UnsatisfiedConstructorDependency), AutoWiringMode.AutoDetect, true);
+ Assert.Fail("Should have unsatisfied constructor dependency on SideEffectObject");
+ }
- [Test]
- public void ExtensiveCircularReference()
- {
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
- for (int i = 0; i < 1000; i++)
- {
- MutablePropertyValues pvs = new MutablePropertyValues();
- pvs.Add(new PropertyValue("Spouse", new RuntimeObjectReference("object" + (i < 99 ? i + 1 : 0))));
- RootObjectDefinition rod = new RootObjectDefinition(typeof (TestObject), pvs);
- lof.RegisterObjectDefinition("object" + i, rod);
- }
- lof.PreInstantiateSingletons();
- for (int i = 0; i < 1000; i++)
- {
- TestObject obj = (TestObject) lof.GetObject("object" + i);
- TestObject otherObj = (TestObject) lof.GetObject("object" + (i < 99 ? i + 1 : 0));
- Assert.IsTrue(obj.Spouse == otherObj);
- }
- }
+ [Test]
+ public void ExtensiveCircularReference()
+ {
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ for (int i = 0; i < 1000; i++)
+ {
+ MutablePropertyValues pvs = new MutablePropertyValues();
+ pvs.Add(new PropertyValue("Spouse", new RuntimeObjectReference("object" + (i < 99 ? i + 1 : 0))));
+ RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), pvs);
+ lof.RegisterObjectDefinition("object" + i, rod);
+ }
+ lof.PreInstantiateSingletons();
+ for (int i = 0; i < 1000; i++)
+ {
+ TestObject obj = (TestObject)lof.GetObject("object" + i);
+ TestObject otherObj = (TestObject)lof.GetObject("object" + (i < 99 ? i + 1 : 0));
+ Assert.IsTrue(obj.Spouse == otherObj);
+ }
+ }
- [Test]
- public void PullingObjectWithFactoryMethodAlsoInjectsDependencies()
- {
- string expectedName = "Terese Raquin";
- MutablePropertyValues props = new MutablePropertyValues();
- props.Add(new PropertyValue("Name", expectedName));
+ [Test]
+ public void PullingObjectWithFactoryMethodAlsoInjectsDependencies()
+ {
+ string expectedName = "Terese Raquin";
+ MutablePropertyValues props = new MutablePropertyValues();
+ props.Add(new PropertyValue("Name", expectedName));
- RootObjectDefinition def = new RootObjectDefinition(typeof (MySingleton), props);
- def.FactoryMethodName = "GetInstance";
+ RootObjectDefinition def = new RootObjectDefinition(typeof(MySingleton), props);
+ def.FactoryMethodName = "GetInstance";
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", def);
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", def);
- object foo = fac["foo"];
- Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory using factory method instantiation.");
- MySingleton sing = (MySingleton) foo;
- Assert.AreEqual(expectedName, sing.Name, "Dependency was not resolved pulling manually registered instance out of the factory using factory method instantiation.");
- }
+ object foo = fac["foo"];
+ Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory using factory method instantiation.");
+ MySingleton sing = (MySingleton)foo;
+ Assert.AreEqual(expectedName, sing.Name, "Dependency was not resolved pulling manually registered instance out of the factory using factory method instantiation.");
+ }
[Test(Description = "http://opensource.atlassian.com/projects/spring/browse/SPRNET-368")]
public void GetObjectWithCtorArgsAndCtorAutowiring()
@@ -863,11 +938,11 @@ namespace Spring.Objects.Factory
using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
{
RootObjectDefinition prototype
- = new RootObjectDefinition(typeof (TestObject));
- prototype.IsSingleton = false;
+ = new RootObjectDefinition(typeof(TestObject));
+ prototype.IsSingleton = false;
lof.RegisterObjectDefinition("prototype", prototype);
-
- TestObject to = lof.GetObject("prototype", new object[] {"Mark", 35}) as TestObject;
+
+ TestObject to = lof.GetObject("prototype", new object[] { "Mark", 35 }) as TestObject;
Assert.IsNotNull(to);
Assert.AreEqual(35, to.Age);
Assert.AreEqual("Mark", to.Name);
@@ -887,11 +962,12 @@ namespace Spring.Objects.Factory
try
{
- TestObject to2 = lof.GetObject("prototype", new object[] {35, "Mark"}) as TestObject;
+ TestObject to2 = lof.GetObject("prototype", new object[] { 35, "Mark" }) as TestObject;
Assert.IsNotNull(to2);
Assert.AreEqual(35, to2.Age);
Assert.AreEqual("Mark", to2.Name);
- } catch (ObjectCreationException ex)
+ }
+ catch (ObjectCreationException ex)
{
Assert.IsTrue(ex.Message.IndexOf("'Object of type 'System.Int32' cannot be converted to type 'System.String'") >= 0);
}
@@ -940,155 +1016,155 @@ namespace Spring.Objects.Factory
}
}
- [Test]
- public void CreateObjectWithAllNamedCtorArguments()
- {
- string expectedName = "Bingo";
- int expectedAge = 1023;
- ConstructorArgumentValues values = new ConstructorArgumentValues();
- values.AddNamedArgumentValue("age", expectedAge);
- values.AddNamedArgumentValue("name", expectedName);
- RootObjectDefinition def = new RootObjectDefinition(typeof (TestObject), values, new MutablePropertyValues());
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", def);
+ [Test]
+ public void CreateObjectWithAllNamedCtorArguments()
+ {
+ string expectedName = "Bingo";
+ int expectedAge = 1023;
+ ConstructorArgumentValues values = new ConstructorArgumentValues();
+ values.AddNamedArgumentValue("age", expectedAge);
+ values.AddNamedArgumentValue("name", expectedName);
+ RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", def);
- ITestObject foo = fac["foo"] as ITestObject;
- Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
- Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved using a named ctor arg.");
- Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
- }
+ ITestObject foo = fac["foo"] as ITestObject;
+ Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
+ Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved using a named ctor arg.");
+ Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
+ }
- [Test]
- public void CreateObjectWithAllNamedCtorArgumentsIsCaseInsensitive()
- {
- string expectedName = "Bingo";
- int expectedAge = 1023;
- ConstructorArgumentValues values = new ConstructorArgumentValues();
- values.AddNamedArgumentValue("aGe", expectedAge);
- values.AddNamedArgumentValue("naME", expectedName);
- RootObjectDefinition def = new RootObjectDefinition(typeof (TestObject), values, new MutablePropertyValues());
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", def);
+ [Test]
+ public void CreateObjectWithAllNamedCtorArgumentsIsCaseInsensitive()
+ {
+ string expectedName = "Bingo";
+ int expectedAge = 1023;
+ ConstructorArgumentValues values = new ConstructorArgumentValues();
+ values.AddNamedArgumentValue("aGe", expectedAge);
+ values.AddNamedArgumentValue("naME", expectedName);
+ RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", def);
- ITestObject foo = fac["foo"] as ITestObject;
- Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
- Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved using a named ctor arg.");
- Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
- }
+ ITestObject foo = fac["foo"] as ITestObject;
+ Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
+ Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved using a named ctor arg.");
+ Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
+ }
- [Test]
- public void CreateObjectWithMixOfNamedAndIndexedCtorArguments()
- {
- string expectedName = "Bingo";
- int expectedAge = 1023;
- ConstructorArgumentValues values = new ConstructorArgumentValues();
- values.AddNamedArgumentValue("age", expectedAge);
- values.AddIndexedArgumentValue(0, expectedName);
- RootObjectDefinition def = new RootObjectDefinition(typeof (TestObject), values, new MutablePropertyValues());
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", def);
+ [Test]
+ public void CreateObjectWithMixOfNamedAndIndexedCtorArguments()
+ {
+ string expectedName = "Bingo";
+ int expectedAge = 1023;
+ ConstructorArgumentValues values = new ConstructorArgumentValues();
+ values.AddNamedArgumentValue("age", expectedAge);
+ values.AddIndexedArgumentValue(0, expectedName);
+ RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", def);
- ITestObject foo = fac["foo"] as ITestObject;
- Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
- Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
- Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
- }
+ ITestObject foo = fac["foo"] as ITestObject;
+ Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
+ Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
+ Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
+ }
- [Test]
- public void CreateObjectWithMixOfNamedAndIndexedAndAutowiredCtorArguments()
- {
- string expectedCompany = "Griffin's Foosball Arcade";
- MutablePropertyValues autoProps = new MutablePropertyValues();
- autoProps.Add(new PropertyValue("Company", expectedCompany));
- RootObjectDefinition autowired = new RootObjectDefinition(typeof (NestedTestObject), autoProps);
+ [Test]
+ public void CreateObjectWithMixOfNamedAndIndexedAndAutowiredCtorArguments()
+ {
+ string expectedCompany = "Griffin's Foosball Arcade";
+ MutablePropertyValues autoProps = new MutablePropertyValues();
+ autoProps.Add(new PropertyValue("Company", expectedCompany));
+ RootObjectDefinition autowired = new RootObjectDefinition(typeof(NestedTestObject), autoProps);
- string expectedName = "Bingo";
- int expectedAge = 1023;
- ConstructorArgumentValues values = new ConstructorArgumentValues();
- values.AddNamedArgumentValue("age", expectedAge);
- values.AddIndexedArgumentValue(0, expectedName);
- RootObjectDefinition def = new RootObjectDefinition(typeof (TestObject), values, new MutablePropertyValues());
- def.AutowireMode = AutoWiringMode.Constructor;
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", def);
- fac.RegisterObjectDefinition("doctor", autowired);
+ string expectedName = "Bingo";
+ int expectedAge = 1023;
+ ConstructorArgumentValues values = new ConstructorArgumentValues();
+ values.AddNamedArgumentValue("age", expectedAge);
+ values.AddIndexedArgumentValue(0, expectedName);
+ RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
+ def.AutowireMode = AutoWiringMode.Constructor;
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", def);
+ fac.RegisterObjectDefinition("doctor", autowired);
- ITestObject foo = fac["foo"] as ITestObject;
- Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
- Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
- Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
- Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
- }
+ ITestObject foo = fac["foo"] as ITestObject;
+ Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
+ Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
+ Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
+ Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
+ }
- [Test]
- public void CreateObjectWithMixOfIndexedAndTwoNamedSameTypeCtorArguments()
- {
- // this object will be passed in as a named constructor argument
- string expectedCompany = "Griffin's Foosball Arcade";
- MutablePropertyValues autoProps = new MutablePropertyValues();
- autoProps.Add(new PropertyValue("Company", expectedCompany));
- RootObjectDefinition autowired = new RootObjectDefinition(typeof (NestedTestObject), autoProps);
+ [Test]
+ public void CreateObjectWithMixOfIndexedAndTwoNamedSameTypeCtorArguments()
+ {
+ // this object will be passed in as a named constructor argument
+ string expectedCompany = "Griffin's Foosball Arcade";
+ MutablePropertyValues autoProps = new MutablePropertyValues();
+ autoProps.Add(new PropertyValue("Company", expectedCompany));
+ RootObjectDefinition autowired = new RootObjectDefinition(typeof(NestedTestObject), autoProps);
- // this object will be passed in as a named constructor argument
- string expectedLawyersCompany = "Pollack, Pounce, & Pulverise";
- MutablePropertyValues lawyerProps = new MutablePropertyValues();
- lawyerProps.Add(new PropertyValue("Company", expectedLawyersCompany));
- RootObjectDefinition lawyer = new RootObjectDefinition(typeof (NestedTestObject), lawyerProps);
+ // this object will be passed in as a named constructor argument
+ string expectedLawyersCompany = "Pollack, Pounce, & Pulverise";
+ MutablePropertyValues lawyerProps = new MutablePropertyValues();
+ lawyerProps.Add(new PropertyValue("Company", expectedLawyersCompany));
+ RootObjectDefinition lawyer = new RootObjectDefinition(typeof(NestedTestObject), lawyerProps);
- // this simple string object will be passed in as an indexed constructor argument
- string expectedName = "Bingo";
+ // this simple string object will be passed in as an indexed constructor argument
+ string expectedName = "Bingo";
- // this simple integer object will be passed in as a named constructor argument
- int expectedAge = 1023;
+ // this simple integer object will be passed in as a named constructor argument
+ int expectedAge = 1023;
- ConstructorArgumentValues values = new ConstructorArgumentValues();
+ ConstructorArgumentValues values = new ConstructorArgumentValues();
- // lets mix the order up a little...
- values.AddNamedArgumentValue("age", expectedAge);
- values.AddIndexedArgumentValue(0, expectedName);
- values.AddNamedArgumentValue("doctor", new RuntimeObjectReference("a_doctor"));
- values.AddNamedArgumentValue("lawyer", new RuntimeObjectReference("a_lawyer"));
+ // lets mix the order up a little...
+ values.AddNamedArgumentValue("age", expectedAge);
+ values.AddIndexedArgumentValue(0, expectedName);
+ values.AddNamedArgumentValue("doctor", new RuntimeObjectReference("a_doctor"));
+ values.AddNamedArgumentValue("lawyer", new RuntimeObjectReference("a_lawyer"));
- RootObjectDefinition def = new RootObjectDefinition(typeof (TestObject), values, new MutablePropertyValues());
+ RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- // the object we're attempting to resolve...
- fac.RegisterObjectDefinition("foo", def);
- // the object that will be looked up and passed as a named parameter to a ctor call...
- fac.RegisterObjectDefinition("a_doctor", autowired);
- // another object that will be looked up and passed as a named parameter to a ctor call...
- fac.RegisterObjectDefinition("a_lawyer", lawyer);
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ // the object we're attempting to resolve...
+ fac.RegisterObjectDefinition("foo", def);
+ // the object that will be looked up and passed as a named parameter to a ctor call...
+ fac.RegisterObjectDefinition("a_doctor", autowired);
+ // another object that will be looked up and passed as a named parameter to a ctor call...
+ fac.RegisterObjectDefinition("a_lawyer", lawyer);
- ITestObject foo = fac["foo"] as ITestObject;
- Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
- Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
- Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
- Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
- Assert.AreEqual(expectedLawyersCompany, foo.Lawyer.Company, "Dependency 'lawyer.Company' was not resolved using another named ctor arg.");
- }
+ ITestObject foo = fac["foo"] as ITestObject;
+ Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
+ Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
+ Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
+ Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
+ Assert.AreEqual(expectedLawyersCompany, foo.Lawyer.Company, "Dependency 'lawyer.Company' was not resolved using another named ctor arg.");
+ }
- [Test]
- public void CircularDependencyIsCorrectlyDetected()
- {
- RootObjectDefinition foo = new RootObjectDefinition(typeof (TestObject));
- foo.ConstructorArgumentValues.AddNamedArgumentValue("spouse", new RuntimeObjectReference("bar"));
- RootObjectDefinition bar = new RootObjectDefinition(typeof (TestObject));
- bar.ConstructorArgumentValues.AddNamedArgumentValue("spouse", new RuntimeObjectReference("foo"));
+ [Test]
+ public void CircularDependencyIsCorrectlyDetected()
+ {
+ RootObjectDefinition foo = new RootObjectDefinition(typeof(TestObject));
+ foo.ConstructorArgumentValues.AddNamedArgumentValue("spouse", new RuntimeObjectReference("bar"));
+ RootObjectDefinition bar = new RootObjectDefinition(typeof(TestObject));
+ bar.ConstructorArgumentValues.AddNamedArgumentValue("spouse", new RuntimeObjectReference("foo"));
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", foo);
- fac.RegisterObjectDefinition("bar", bar);
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", foo);
+ fac.RegisterObjectDefinition("bar", bar);
- try
- {
- fac.GetObject("foo");
- }
- catch (ObjectCreationException ex)
- {
- Assert.AreEqual(typeof (ObjectCurrentlyInCreationException), ex.GetBaseException().GetType(),
- "Circular dependency was set up; should have caught an ObjectCurrentlyInCreationException instance.");
- }
- }
+ try
+ {
+ fac.GetObject("foo");
+ }
+ catch (ObjectCreationException ex)
+ {
+ Assert.AreEqual(typeof(ObjectCurrentlyInCreationException), ex.GetBaseException().GetType(),
+ "Circular dependency was set up; should have caught an ObjectCurrentlyInCreationException instance.");
+ }
+ }
[Test]
public void ConfigurableFactoryObjectInline()
@@ -1102,7 +1178,7 @@ namespace Spring.Objects.Factory
RootObjectDefinition factory = new RootObjectDefinition();
factory.ObjectType = typeof(DummyConfigurableFactory);
- factory.PropertyValues = new MutablePropertyValues();
+ factory.PropertyValues = new MutablePropertyValues();
factory.PropertyValues.Add("ProductTemplate", everyman);
dlof.RegisterObjectDefinition("factory", factory);
@@ -1138,144 +1214,144 @@ namespace Spring.Objects.Factory
Assert.AreEqual(9781, instance.Age, "Age dependency injected via IObjectFactory.ConfigureObject(instance) failed (was 25).");
}
- [Test]
- public void ConfigureObject()
- {
- TestObject instance = new TestObject();
- RootObjectDefinition everyman = new RootObjectDefinition();
- everyman.IsAbstract = true;
- everyman.PropertyValues = new MutablePropertyValues();
- everyman.PropertyValues.Add("name", "Noone");
- everyman.PropertyValues.Add("age", 9781);
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition(instance.GetType().FullName, everyman);
+ [Test]
+ public void ConfigureObject()
+ {
+ TestObject instance = new TestObject();
+ RootObjectDefinition everyman = new RootObjectDefinition();
+ everyman.IsAbstract = true;
+ everyman.PropertyValues = new MutablePropertyValues();
+ everyman.PropertyValues.Add("name", "Noone");
+ everyman.PropertyValues.Add("age", 9781);
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition(instance.GetType().FullName, everyman);
fac.ConfigureObject(instance, instance.GetType().FullName);
- Assert.AreEqual("Noone", instance.Name, "Name dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
- Assert.AreEqual(9781, instance.Age, "Age dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
- }
+ Assert.AreEqual("Noone", instance.Name, "Name dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
+ Assert.AreEqual(9781, instance.Age, "Age dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
+ }
- [Test]
- public void ConfigureObjectViaExplicitName()
- {
- TestObject instance = new TestObject();
- RootObjectDefinition everyman = new RootObjectDefinition();
- everyman.IsAbstract = true;
- everyman.PropertyValues = new MutablePropertyValues();
- everyman.PropertyValues.Add("name", "Noone");
- everyman.PropertyValues.Add("age", 9781);
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("everyman", everyman);
- fac.ConfigureObject(instance, "everyman");
+ [Test]
+ public void ConfigureObjectViaExplicitName()
+ {
+ TestObject instance = new TestObject();
+ RootObjectDefinition everyman = new RootObjectDefinition();
+ everyman.IsAbstract = true;
+ everyman.PropertyValues = new MutablePropertyValues();
+ everyman.PropertyValues.Add("name", "Noone");
+ everyman.PropertyValues.Add("age", 9781);
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("everyman", everyman);
+ fac.ConfigureObject(instance, "everyman");
Assert.AreEqual(true, instance.InitCompleted, "AfterPropertiesSet() was not invoked by IObjectFactory.ConfigureObject(instance).");
Assert.AreEqual("Noone", instance.Name, "Name dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
- Assert.AreEqual(9781, instance.Age, "Age dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
- }
+ Assert.AreEqual(9781, instance.Age, "Age dependency injected via IObjectFactory.ConfigureObject(instance) failed (was null).");
+ }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void ConfigureObjectViaNullName()
- {
- TestObject instance = new TestObject();
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.ConfigureObject(instance, null);
- }
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void ConfigureObjectViaNullName()
+ {
+ TestObject instance = new TestObject();
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.ConfigureObject(instance, null);
+ }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void ConfigureObjectViaLoadOfOldWhitespaceName()
- {
- TestObject instance = new TestObject();
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.ConfigureObject(instance, " \t");
- }
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void ConfigureObjectViaLoadOfOldWhitespaceName()
+ {
+ TestObject instance = new TestObject();
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.ConfigureObject(instance, " \t");
+ }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void ConfigureObjectViaEmptyName()
- {
- TestObject instance = new TestObject();
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.ConfigureObject(instance, string.Empty);
- }
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void ConfigureObjectViaEmptyName()
+ {
+ TestObject instance = new TestObject();
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.ConfigureObject(instance, string.Empty);
+ }
- [Test]
- public void DisposeCyclesThroughAllSingletonsEvenIfTheirDisposeThrowsAnException()
- {
- RootObjectDefinition foo = new RootObjectDefinition(typeof (GoodDisposable));
- foo.IsSingleton = true;
- RootObjectDefinition bar = new RootObjectDefinition(typeof (BadDisposable));
- bar.IsSingleton = true;
- RootObjectDefinition baz = new RootObjectDefinition(typeof (GoodDisposable));
- baz.IsSingleton = true;
+ [Test]
+ public void DisposeCyclesThroughAllSingletonsEvenIfTheirDisposeThrowsAnException()
+ {
+ RootObjectDefinition foo = new RootObjectDefinition(typeof(GoodDisposable));
+ foo.IsSingleton = true;
+ RootObjectDefinition bar = new RootObjectDefinition(typeof(BadDisposable));
+ bar.IsSingleton = true;
+ RootObjectDefinition baz = new RootObjectDefinition(typeof(GoodDisposable));
+ baz.IsSingleton = true;
- using (DefaultListableObjectFactory fac = new DefaultListableObjectFactory())
- {
- fac.RegisterObjectDefinition("foo", foo);
- fac.RegisterObjectDefinition("bar", bar);
- fac.RegisterObjectDefinition("baz", baz);
- fac.PreInstantiateSingletons();
- }
- Assert.AreEqual(2, GoodDisposable.DisposeCount, "All IDisposable singletons must have their Dispose() method called... one of them bailed, and as a result the rest were (apparently) not Dispose()d.");
- GoodDisposable.DisposeCount = 0;
- }
+ using (DefaultListableObjectFactory fac = new DefaultListableObjectFactory())
+ {
+ fac.RegisterObjectDefinition("foo", foo);
+ fac.RegisterObjectDefinition("bar", bar);
+ fac.RegisterObjectDefinition("baz", baz);
+ fac.PreInstantiateSingletons();
+ }
+ Assert.AreEqual(2, GoodDisposable.DisposeCount, "All IDisposable singletons must have their Dispose() method called... one of them bailed, and as a result the rest were (apparently) not Dispose()d.");
+ GoodDisposable.DisposeCount = 0;
+ }
- [Test]
- public void StaticInitializationViaDependsOnSingletonMethodInvokingFactoryObject()
- {
- RootObjectDefinition initializer = new RootObjectDefinition(typeof (MethodInvokingFactoryObject));
- initializer.PropertyValues.Add("TargetMethod", "Init");
- initializer.PropertyValues.Add("TargetType", typeof (StaticInitializer).AssemblyQualifiedName);
+ [Test]
+ public void StaticInitializationViaDependsOnSingletonMethodInvokingFactoryObject()
+ {
+ RootObjectDefinition initializer = new RootObjectDefinition(typeof(MethodInvokingFactoryObject));
+ initializer.PropertyValues.Add("TargetMethod", "Init");
+ initializer.PropertyValues.Add("TargetType", typeof(StaticInitializer).AssemblyQualifiedName);
- RootObjectDefinition foo = new RootObjectDefinition(typeof (TestObject));
- foo.DependsOn = new string[] {"force-init"};
+ RootObjectDefinition foo = new RootObjectDefinition(typeof(TestObject));
+ foo.DependsOn = new string[] { "force-init" };
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", foo);
- fac.RegisterObjectDefinition("force-init", initializer);
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", foo);
+ fac.RegisterObjectDefinition("force-init", initializer);
- fac.GetObject("foo");
- Assert.IsTrue(StaticInitializer.InitWasCalled, "Boing");
- }
+ fac.GetObject("foo");
+ Assert.IsTrue(StaticInitializer.InitWasCalled, "Boing");
+ }
- ///
- /// There is a similar test in XmlObjectFactoryTests that actually supplies another boolean
- /// object in the factory that is used to autowire the object; this test puts no such second
- /// object in the factory, so when the factory tries to autowire the second (missing) argument
- /// to the ctor, it should (must) choke.
- ///
- [Test]
- [ExpectedException(typeof (UnsatisfiedDependencyException),
- "Error creating object with name 'foo' : Unsatisfied dependency " +
- "expressed through constructor argument with index 1 of type [System.Boolean] : " +
+ ///
+ /// There is a similar test in XmlObjectFactoryTests that actually supplies another boolean
+ /// object in the factory that is used to autowire the object; this test puts no such second
+ /// object in the factory, so when the factory tries to autowire the second (missing) argument
+ /// to the ctor, it should (must) choke.
+ ///
+ [Test]
+ [ExpectedException(typeof(UnsatisfiedDependencyException),
+ "Error creating object with name 'foo' : Unsatisfied dependency " +
+ "expressed through constructor argument with index 1 of type [System.Boolean] : " +
"No unique object of type [System.Boolean] is defined : Unsatisfied dependency of type [System.Boolean]: expected at least 1 matching object to wire the [b2] parameter on the constructor of object [foo]")]
- public void DoubleBooleanAutowire()
- {
- RootObjectDefinition def = new RootObjectDefinition(typeof (DoubleBooleanConstructorObject));
- ConstructorArgumentValues args = new ConstructorArgumentValues();
- args.AddGenericArgumentValue(true, "bool");
- def.ConstructorArgumentValues = args;
- def.AutowireMode = AutoWiringMode.Constructor;
- def.IsSingleton = true;
-
- DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- fac.RegisterObjectDefinition("foo", def);
-
- fac.GetObject("foo");
- }
-
- [Test]
- public void CanSetPropertyThatUsesNewModifierOnDerivedClass()
- {
- string nick = "Banjo";
- string expectedNickname = DerivedTestObject.NicknamePrefix + nick;
-
- RootObjectDefinition def = new RootObjectDefinition(typeof (DerivedTestObject));
- def.PropertyValues.Add("Nickname", nick);
+ public void DoubleBooleanAutowire()
+ {
+ RootObjectDefinition def = new RootObjectDefinition(typeof(DoubleBooleanConstructorObject));
+ ConstructorArgumentValues args = new ConstructorArgumentValues();
+ args.AddGenericArgumentValue(true, "bool");
+ def.ConstructorArgumentValues = args;
+ def.AutowireMode = AutoWiringMode.Constructor;
+ def.IsSingleton = true;
DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
fac.RegisterObjectDefinition("foo", def);
- DerivedTestObject tob = (DerivedTestObject) fac.GetObject("foo");
+ fac.GetObject("foo");
+ }
+
+ [Test]
+ public void CanSetPropertyThatUsesNewModifierOnDerivedClass()
+ {
+ string nick = "Banjo";
+ string expectedNickname = DerivedTestObject.NicknamePrefix + nick;
+
+ RootObjectDefinition def = new RootObjectDefinition(typeof(DerivedTestObject));
+ def.PropertyValues.Add("Nickname", nick);
+
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+ fac.RegisterObjectDefinition("foo", def);
+
+ DerivedTestObject tob = (DerivedTestObject)fac.GetObject("foo");
Assert.AreEqual(expectedNickname, tob.Nickname,
"Property is not being set to the NEWed property on the subclass.");
}
@@ -1283,77 +1359,77 @@ namespace Spring.Objects.Factory
[Test]
public void CanSetPropertyThatUsesOddNewModifierOnDerivedClass()
{
- RootObjectDefinition def = new RootObjectDefinition(typeof (DerivedFoo));
+ RootObjectDefinition def = new RootObjectDefinition(typeof(DerivedFoo));
def.PropertyValues.Add("Bar", new DerivedBar());
DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
fac.RegisterObjectDefinition("foo", def);
- DerivedFoo foo = (DerivedFoo) fac.GetObject("foo");
+ DerivedFoo foo = (DerivedFoo)fac.GetObject("foo");
Assert.AreEqual(typeof(DerivedBar), foo.Bar.GetType());
}
- [Test]
- public void ChildReferencesParentByAnAliasOfTheParent()
- {
- const string TheParentsAlias = "theParentsAlias";
- const int ExpectedAge = 31;
- const string ExpectedName = "Rick Evans";
+ [Test]
+ 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);
+ 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);
+ ChildObjectDefinition childDef = new ChildObjectDefinition(TheParentsAlias);
- TestObject child = (TestObject) fac.GetObject("child");
- Assert.AreEqual(ExpectedName, child.Name);
- Assert.AreEqual(ExpectedAge, child.Age);
- }
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
- [Test]
- public void GetObjectDefinitionResolvesAliases()
- {
- const string TheParentsAlias = "theParentsAlias";
- const int ExpectedAge = 31;
- const string ExpectedName = "Rick Evans";
+ fac.RegisterObjectDefinition("parent", parentDef);
+ fac.RegisterAlias("parent", TheParentsAlias);
+ fac.RegisterObjectDefinition("child", childDef);
- RootObjectDefinition parentDef = new RootObjectDefinition(typeof (TestObject));
- parentDef.IsAbstract = true;
- parentDef.PropertyValues.Add("name", ExpectedName);
- parentDef.PropertyValues.Add("age", ExpectedAge);
+ TestObject child = (TestObject)fac.GetObject("child");
+ Assert.AreEqual(ExpectedName, child.Name);
+ Assert.AreEqual(ExpectedAge, child.Age);
+ }
- 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);
- }
+ [Test]
+ public void GetObjectDefinitionResolvesAliases()
+ {
+ const string TheParentsAlias = "theParentsAlias";
+ const int ExpectedAge = 31;
+ const string ExpectedName = "Rick Evans";
- [Test]
- public void IgnoreObjectPostProcessorDuplicates()
- {
- DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
- IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
+ RootObjectDefinition parentDef = new RootObjectDefinition(typeof(TestObject));
+ parentDef.IsAbstract = true;
+ parentDef.PropertyValues.Add("name", ExpectedName);
+ parentDef.PropertyValues.Add("age", ExpectedAge);
- DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+ ChildObjectDefinition childDef = new ChildObjectDefinition(TheParentsAlias);
- const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
- Assert.AreEqual(0, lof.ObjectPostProcessorCount, errMsg);
- lof.AddObjectPostProcessor(proc1);
- Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
- lof.AddObjectPostProcessor(proc1);
- Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
- }
+ DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
+
+ fac.RegisterObjectDefinition("parent", parentDef);
+ fac.RegisterAlias("parent", TheParentsAlias);
+
+ IObjectDefinition od = fac.GetObjectDefinition(TheParentsAlias);
+ Assert.IsNotNull(od);
+ }
+
+ [Test]
+ public void IgnoreObjectPostProcessorDuplicates()
+ {
+ DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
+ IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
+
+ DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
+
+ const string errMsg = "Wrong number of IObjectPostProcessors being reported by the ObjectPostProcessorCount property.";
+ Assert.AreEqual(0, lof.ObjectPostProcessorCount, errMsg);
+ lof.AddObjectPostProcessor(proc1);
+ Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
+ lof.AddObjectPostProcessor(proc1);
+ Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
+ }
[Test]
public void ConfigureObjectReturnsOriginalInstanceIfNoDefinitionFound()
@@ -1364,98 +1440,98 @@ namespace Spring.Objects.Factory
Assert.AreSame(testObject, resultObject);
}
- #region Helper Classes
+ #region Helper Classes
- public class GoodDisposable : IDisposable
- {
- public static int DisposeCount = 0;
+ public class GoodDisposable : IDisposable
+ {
+ public static int DisposeCount = 0;
- public void Dispose()
- {
- ++DisposeCount;
- }
- }
+ public void Dispose()
+ {
+ ++DisposeCount;
+ }
+ }
- public class BadDisposable : IDisposable
- {
- public void Dispose()
- {
- throw new FormatException();
- }
- }
+ public class BadDisposable : IDisposable
+ {
+ public void Dispose()
+ {
+ throw new FormatException();
+ }
+ }
- public sealed class MySingleton
- {
- private MySingleton()
- {
- }
+ public sealed class MySingleton
+ {
+ private MySingleton()
+ {
+ }
- private static MySingleton _instance = new MySingleton();
+ private static MySingleton _instance = new MySingleton();
- public static MySingleton GetInstance()
- {
- return _instance;
- }
+ public static MySingleton GetInstance()
+ {
+ return _instance;
+ }
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
+ public string Name
+ {
+ get { return _name; }
+ set { _name = value; }
+ }
- private string _name;
- }
+ private string _name;
+ }
- public class NoDependencies
- {
- }
+ public class NoDependencies
+ {
+ }
- public class ConstructorDependency
- {
- public TestObject _spouse;
+ public class ConstructorDependency
+ {
+ public TestObject _spouse;
- public ConstructorDependency(TestObject spouse)
- {
- this._spouse = spouse;
- }
- }
+ public ConstructorDependency(TestObject spouse)
+ {
+ this._spouse = spouse;
+ }
+ }
- public class UnsatisfiedConstructorDependency
- {
- public UnsatisfiedConstructorDependency(TestObject to, SideEffectObject seo)
- {
- _to = to;
- _seo = seo;
- }
+ public class UnsatisfiedConstructorDependency
+ {
+ public UnsatisfiedConstructorDependency(TestObject to, SideEffectObject seo)
+ {
+ _to = to;
+ _seo = seo;
+ }
- public object Seo
- {
- get { return _seo; }
- }
+ public object Seo
+ {
+ get { return _seo; }
+ }
- public TestObject To
- {
- get { return _to; }
- }
+ public TestObject To
+ {
+ get { return _to; }
+ }
- private object _seo;
- private TestObject _to;
- }
+ private object _seo;
+ private TestObject _to;
+ }
- private sealed class StaticInitializer
- {
- public static bool InitWasCalled = false;
+ private sealed class StaticInitializer
+ {
+ public static bool InitWasCalled = false;
- public static void Init()
- {
- InitWasCalled = true;
- }
- }
+ public static void Init()
+ {
+ InitWasCalled = true;
+ }
+ }
- #endregion
- }
+ #endregion
+ }
- public class Foo
+ public class Foo
{
private IBar bar;
@@ -1466,20 +1542,20 @@ namespace Spring.Objects.Factory
}
}
- public class DerivedFoo : Foo
+ public class DerivedFoo : Foo
{
public new IDerivedBar Bar
{
- get { return (IDerivedBar) base.Bar; }
+ get { return (IDerivedBar)base.Bar; }
set { base.Bar = value; }
}
}
- public interface IBar {}
+ public interface IBar { }
- public interface IDerivedBar : IBar {}
+ public interface IDerivedBar : IBar { }
- public class Bar : IBar {}
+ public class Bar : IBar { }
- public class DerivedBar : IDerivedBar {}
+ public class DerivedBar : IDerivedBar { }
}
\ No newline at end of file
diff --git a/test/Spring/Spring.Core.Tests/Util/CollectionUtilsTests.cs b/test/Spring/Spring.Core.Tests/Util/CollectionUtilsTests.cs
index 13c29c00..33c5f4f3 100644
--- a/test/Spring/Spring.Core.Tests/Util/CollectionUtilsTests.cs
+++ b/test/Spring/Spring.Core.Tests/Util/CollectionUtilsTests.cs
@@ -355,5 +355,21 @@ namespace Spring.Util
}
}
+
+ [Test]
+ public void ToArray()
+ {
+ ArrayList list = new ArrayList();
+ list.Add("mystring");
+ string[] strList = (string[]) CollectionUtils.ToArray(list, typeof(string));
+ Assert.AreEqual(1, strList.Length);
+
+ try
+ {
+ CollectionUtils.ToArray(list, typeof(Type));
+ Assert.Fail("should fail");
+ }
+ catch(InvalidCastException) {}
+ }
}
}