Add AutowireAttributePostProcessor for attribute driven auto wiring, fine grained control via QualifierAttribute or ValueAttribute (Expressions, PropertyPlaceHolder).
Updated XML configuration to support primary attribute. Also added possibility to add a Qualifier and Meta element to define an object for QualifierAttribute.
This commit is contained in:
@@ -1,160 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireAttributeCollectionTests
|
||||
{
|
||||
private GenericApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new GenericApplicationContext();
|
||||
|
||||
var objDef = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
|
||||
objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
|
||||
_applicationContext.RegisterObjectDefinition("AutowiredAttributeObjectPostProcessor", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ColFoo1));
|
||||
_applicationContext.RegisterObjectDefinition("Foo1", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ColFoo2));
|
||||
_applicationContext.RegisterObjectDefinition("Foo2", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ColTestObject1));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("ColTestObject1", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ColTestObject2));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("ColTestObject2", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ColTestObject3));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("ColTestObject3", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ColTestObject4));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("ColTestObject4", objDef);
|
||||
|
||||
_applicationContext.Refresh();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectAListOfObjects()
|
||||
{
|
||||
var testObj = (ColTestObject1)_applicationContext.GetObject("ColTestObject1");
|
||||
var objDef = _applicationContext.ObjectFactory.GetObjectDefinition("ColTestObject1");
|
||||
|
||||
Assert.That(testObj.Count, Is.EqualTo(2));
|
||||
Assert.That(objDef.DependsOn.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectASetOfObjects()
|
||||
{
|
||||
var testObj = (ColTestObject2)_applicationContext.GetObject("ColTestObject2");
|
||||
|
||||
Assert.That(testObj.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectADictionaryOfObjects()
|
||||
{
|
||||
var testObj = (ColTestObject3)_applicationContext.GetObject("ColTestObject3");
|
||||
|
||||
Assert.That(testObj.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectAnArrayOfObjects()
|
||||
{
|
||||
var testObj = (ColTestObject4)_applicationContext.GetObject("ColTestObject4");
|
||||
|
||||
Assert.That(testObj.Count, Is.EqualTo(2));
|
||||
}
|
||||
}
|
||||
|
||||
#region Test Objects
|
||||
|
||||
public interface IColFoo
|
||||
{
|
||||
string Name();
|
||||
}
|
||||
|
||||
public class ColFoo1 : IColFoo
|
||||
{
|
||||
public string Name()
|
||||
{
|
||||
return "Foo1";
|
||||
}
|
||||
}
|
||||
|
||||
public class ColFoo2 : IColFoo
|
||||
{
|
||||
public string Name()
|
||||
{
|
||||
return "Foo2";
|
||||
}
|
||||
}
|
||||
|
||||
public class ColTestObject1
|
||||
{
|
||||
[Autowired]
|
||||
private IList<IColFoo> _col;
|
||||
|
||||
public int Count { get { return _col.Count; } }
|
||||
}
|
||||
|
||||
public class ColTestObject2
|
||||
{
|
||||
[Autowired]
|
||||
private Spring.Collections.Generic.ISet<IColFoo> _col;
|
||||
|
||||
public int Count { get { return _col.Count; } }
|
||||
}
|
||||
|
||||
public class ColTestObject3
|
||||
{
|
||||
[Autowired]
|
||||
private IDictionary<string, IColFoo> _col;
|
||||
|
||||
public int Count { get { return _col.Count; } }
|
||||
}
|
||||
|
||||
public class ColTestObject4
|
||||
{
|
||||
[Autowired]
|
||||
private IColFoo[] _col;
|
||||
|
||||
public int Count { get { return _col.Length; } }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,343 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireAttributeConstructorTest
|
||||
{
|
||||
private GenericApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new GenericApplicationContext();
|
||||
|
||||
var objDef = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
|
||||
objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
|
||||
_applicationContext.RegisterObjectDefinition("AutowiredAttributeObjectPostProcessor", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsSimple));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsSimple", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsAdvanced));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsAdvanced", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsHello));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsHello", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsCiao));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsCiao", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject1));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject1", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject2));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject2", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject3));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject3", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject4));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject4", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject5));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject5", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject6));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject6", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(ConsTestObject7));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("ConsTestObject7", objDef);
|
||||
|
||||
_applicationContext.Refresh();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConstructorWithInjectParameter()
|
||||
{
|
||||
var testObj = (ConsTestObject1)_applicationContext.GetObject("ConsTestObject1");
|
||||
|
||||
Assert.That(testObj.IsSet(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectInjectConstructorOverDefault()
|
||||
{
|
||||
var testObj = (ConsTestObject2)_applicationContext.GetObject("ConsTestObject2");
|
||||
|
||||
Assert.That(testObj.IsSet(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectConstructorWithMostParamters()
|
||||
{
|
||||
var testObj = (ConsTestObject3)_applicationContext.GetObject("ConsTestObject3");
|
||||
|
||||
Assert.That(testObj.IsSet(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailIfParameterAreRequired()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (ConsTestObject4)_applicationContext.GetObject("ConsTestObject4");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Exception should be thrown");
|
||||
Assert.That(ex.Message, Is.StringContaining("Unsatisfied dependency expressed"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectCollection()
|
||||
{
|
||||
var testObj = (ConsTestObject5)_applicationContext.GetObject("ConsTestObject5");
|
||||
|
||||
Assert.That(testObj.IsSet(), Is.True);
|
||||
Assert.That(testObj.ObjectCount(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void SetParameterByParameterName()
|
||||
{
|
||||
var testObj = (ConsTestObject6)_applicationContext.GetObject("ConsTestObject6");
|
||||
|
||||
Assert.That(testObj.IsSet(), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetParameterByQualifier()
|
||||
{
|
||||
var testObj = (ConsTestObject7)_applicationContext.GetObject("ConsTestObject7");
|
||||
|
||||
Assert.That(testObj.IsSet(), Is.True);
|
||||
Assert.That(testObj.CorrectObject(), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
#region Test Objects
|
||||
|
||||
public interface IConsSimple
|
||||
{
|
||||
string Message();
|
||||
}
|
||||
|
||||
public class ConsSimple : IConsSimple
|
||||
{
|
||||
public string Message()
|
||||
{
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
public interface IConsAdvanced
|
||||
{
|
||||
string Message();
|
||||
}
|
||||
|
||||
public class ConsAdvanced : IConsAdvanced
|
||||
{
|
||||
public string Message()
|
||||
{
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
public interface INotSet
|
||||
{
|
||||
}
|
||||
|
||||
public interface IConsCol
|
||||
{
|
||||
string Message();
|
||||
}
|
||||
|
||||
public class ConsHello : IConsCol
|
||||
{
|
||||
public string Message()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsCiao : IConsCol
|
||||
{
|
||||
public string Message()
|
||||
{
|
||||
return "ciao";
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject1
|
||||
{
|
||||
private IConsSimple _consSimple;
|
||||
|
||||
[Autowired]
|
||||
public ConsTestObject1(IConsSimple consSimple)
|
||||
{
|
||||
_consSimple = consSimple;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _consSimple != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject2
|
||||
{
|
||||
private IConsSimple _consSimple;
|
||||
|
||||
public ConsTestObject2()
|
||||
{
|
||||
}
|
||||
|
||||
[Autowired]
|
||||
public ConsTestObject2(IConsSimple consSimple)
|
||||
{
|
||||
_consSimple = consSimple;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _consSimple != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject3
|
||||
{
|
||||
private IConsSimple _consSimple;
|
||||
private IConsAdvanced _consAdvanced;
|
||||
|
||||
[Autowired(Required = false)]
|
||||
public ConsTestObject3(IConsSimple consSimple)
|
||||
{
|
||||
_consSimple = consSimple;
|
||||
}
|
||||
|
||||
[Autowired(Required = false)]
|
||||
public ConsTestObject3(IConsSimple consSimple, IConsAdvanced consAdvanced)
|
||||
{
|
||||
_consSimple = consSimple;
|
||||
_consAdvanced = consAdvanced;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _consSimple != null && _consAdvanced != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject4
|
||||
{
|
||||
private INotSet _notSet;
|
||||
|
||||
[Autowired]
|
||||
public ConsTestObject4(INotSet notSet)
|
||||
{
|
||||
_notSet = notSet;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _notSet != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject5
|
||||
{
|
||||
private IDictionary<string,IConsCol> _consCol;
|
||||
|
||||
[Autowired]
|
||||
public ConsTestObject5(IDictionary<string, IConsCol> consCol)
|
||||
{
|
||||
_consCol = consCol;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _consCol != null;
|
||||
}
|
||||
|
||||
public int ObjectCount()
|
||||
{
|
||||
return _consCol.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject6
|
||||
{
|
||||
private IConsCol _consHello;
|
||||
|
||||
[Autowired]
|
||||
public ConsTestObject6(IConsCol consHello)
|
||||
{
|
||||
_consHello = consHello;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _consHello != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsTestObject7
|
||||
{
|
||||
private IConsCol _consHello;
|
||||
|
||||
[Autowired]
|
||||
public ConsTestObject7([Qualifier("ConsCiao")] IConsCol consHello)
|
||||
{
|
||||
_consHello = consHello;
|
||||
}
|
||||
|
||||
public bool IsSet()
|
||||
{
|
||||
return _consHello != null;
|
||||
}
|
||||
|
||||
public bool CorrectObject()
|
||||
{
|
||||
return _consHello.Message() == "ciao";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,290 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireAttributeFieldTest
|
||||
{
|
||||
private GenericApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new GenericApplicationContext();
|
||||
|
||||
var objDef = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
|
||||
objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
|
||||
_applicationContext.RegisterObjectDefinition("AutowiredAttributeObjectPostProcessor", objDef);
|
||||
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldFooImpl));
|
||||
_applicationContext.RegisterObjectDefinition("FldFoo", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldHello));
|
||||
_applicationContext.RegisterObjectDefinition("FldHello", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldCioa));
|
||||
_applicationContext.RegisterObjectDefinition("FldCioa", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldHola));
|
||||
_applicationContext.RegisterObjectDefinition("FldHola", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject1));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject1", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject2));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject2", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject3));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject3", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject4));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject4", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject5));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject5", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject6));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject6", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(FldTestObject7));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("FldTestObject7", objDef);
|
||||
|
||||
_applicationContext.Refresh();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectPropertyBasedOnFieldType()
|
||||
{
|
||||
var testObj = (FldTestObject1)_applicationContext.GetObject("FldTestObject1");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("FldTestObject1");
|
||||
|
||||
Assert.That(testObj.Test(), Is.EqualTo("foo"));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithTwoTypesRegisteredAndNoNameShouldFail()
|
||||
{
|
||||
Assert.That(delegate { var testObj = (FldTestObject2)_applicationContext.GetObject("FldTestObject2"); }, Throws.Exception.TypeOf<ObjectCreationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithQualifierName()
|
||||
{
|
||||
var testObj = (FldTestObject3)_applicationContext.GetObject("FldTestObject3");
|
||||
|
||||
Assert.That(testObj.Say(), Is.EqualTo("cioa"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithTwoTypesAndNoQualifierUsePopertyName()
|
||||
{
|
||||
var testObj = (FldTestObject4)_applicationContext.GetObject("FldTestObject4");
|
||||
|
||||
Assert.That(testObj.Say(), Is.EqualTo("cioa"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailIfTypeCantBeResolved()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (FldTestObject5)_applicationContext.GetObject("FldTestObject5");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Injection of autowired dependencies failed"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectedObjectAssignedToTwoInterfaces()
|
||||
{
|
||||
var testObj = (FldTestObject6)_applicationContext.GetObject("FldTestObject6");
|
||||
|
||||
Assert.That(testObj.Test(), Is.EqualTo("test"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsNotRequired()
|
||||
{
|
||||
var testObj = (FldTestObject7)_applicationContext.GetObject("FldTestObject7");
|
||||
|
||||
Assert.That(testObj.IsNull(), Is.True);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region Test Objects
|
||||
|
||||
public interface IFldNotAnObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IFldAnotherOne
|
||||
{
|
||||
string Quite();
|
||||
}
|
||||
|
||||
public interface IFldFoo
|
||||
{
|
||||
string Test();
|
||||
}
|
||||
|
||||
public class FldFooImpl : IFldFoo
|
||||
{
|
||||
public string Test()
|
||||
{
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
||||
public interface IFldSay
|
||||
{
|
||||
string Say();
|
||||
}
|
||||
|
||||
public class FldHello : IFldSay
|
||||
{
|
||||
public string Say()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
public class FldCioa : IFldSay
|
||||
{
|
||||
public string Say()
|
||||
{
|
||||
return "cioa";
|
||||
}
|
||||
}
|
||||
|
||||
public class FldHola : IFldFoo, IFldAnotherOne
|
||||
{
|
||||
public string Quite()
|
||||
{
|
||||
return "test";
|
||||
}
|
||||
|
||||
public string Test()
|
||||
{
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
|
||||
public class FldTestObject1
|
||||
{
|
||||
[Autowired]
|
||||
private IFldFoo _fldFoo;
|
||||
|
||||
public string Test()
|
||||
{
|
||||
return _fldFoo.Test();
|
||||
}
|
||||
}
|
||||
|
||||
// object with 2 possibilities should fail
|
||||
public class FldTestObject2
|
||||
{
|
||||
[Autowired]
|
||||
private IFldSay _wrongName;
|
||||
|
||||
public string Say()
|
||||
{
|
||||
return _wrongName.Say();
|
||||
}
|
||||
}
|
||||
|
||||
// should not fail but inject Cioa object
|
||||
public class FldTestObject3
|
||||
{
|
||||
[Autowired]
|
||||
[Qualifier("FldCioa")]
|
||||
private IFldSay _fldCioa;
|
||||
|
||||
public string Say()
|
||||
{
|
||||
return _fldCioa.Say();
|
||||
}
|
||||
}
|
||||
|
||||
// should not fail but inject Hello via Propertyname
|
||||
public class FldTestObject4
|
||||
{
|
||||
[Autowired]
|
||||
private IFldSay _fldCioa;
|
||||
|
||||
public string Say()
|
||||
{
|
||||
return _fldCioa.Say();
|
||||
}
|
||||
}
|
||||
|
||||
// should not fail but inject Hello via Propertyname
|
||||
public class FldTestObject5
|
||||
{
|
||||
[Autowired]
|
||||
private IFldNotAnObject _ohhh;
|
||||
}
|
||||
|
||||
public class FldTestObject6
|
||||
{
|
||||
[Autowired]
|
||||
private IFldAnotherOne _hola;
|
||||
|
||||
public string Test()
|
||||
{
|
||||
return _hola.Quite();
|
||||
}
|
||||
}
|
||||
|
||||
public class FldTestObject7
|
||||
{
|
||||
[Autowired(Required = false)]
|
||||
private IFldNotAnObject _nono;
|
||||
|
||||
public bool IsNull()
|
||||
{
|
||||
return (_nono == null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,371 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireAttributeMethodsTests
|
||||
{
|
||||
private GenericApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new GenericApplicationContext();
|
||||
|
||||
var objDef = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
|
||||
objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
|
||||
_applicationContext.RegisterObjectDefinition("AutowiredAttributeObjectPostProcessor", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(Simple));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("Simple", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodHello));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodHello", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodCiao));
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodCiao", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject1));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject1", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject2));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject2", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject3));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject3", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject4));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject4", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject5));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject5", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject6));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject6", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject7));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject7", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject8));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject8", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(MethodTestObject9));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.ObjectFactory.RegisterObjectDefinition("MethodTestObject9", objDef);
|
||||
|
||||
_applicationContext.Refresh();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InObjectByType()
|
||||
{
|
||||
var testObj = (MethodTestObject1)_applicationContext.GetObject("MethodTestObject1");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("MethodTestObject1");
|
||||
|
||||
Assert.That(testObj.GetObject(), Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectByParamterName()
|
||||
{
|
||||
var testObj = (MethodTestObject2)_applicationContext.GetObject("MethodTestObject2");
|
||||
|
||||
Assert.That(testObj.GetObject(), Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectByQualifier()
|
||||
{
|
||||
var testObj = (MethodTestObject3)_applicationContext.GetObject("MethodTestObject3");
|
||||
|
||||
Assert.That(testObj.GetObject(), Is.Not.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailIfTypeCantBeResolved()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (FldTestObject5)_applicationContext.GetObject("MethodTestObject4");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Injection of autowired dependencies failed"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectListOfObjects()
|
||||
{
|
||||
var testObj = (MethodTestObject5)_applicationContext.GetObject("MethodTestObject5");
|
||||
|
||||
Assert.That(testObj.GetObject(), Is.Not.Null);
|
||||
Assert.That(testObj.GetObject().Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectSeveralParameters()
|
||||
{
|
||||
var testObj = (MethodTestObject6)_applicationContext.GetObject("MethodTestObject6");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("MethodTestObject6");
|
||||
|
||||
Assert.That(testObj.GetObject(), Is.Not.Null);
|
||||
Assert.That(testObj.GetSimple(), Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailIfObjecNotAvailable()
|
||||
{
|
||||
Assert.That(delegate { var testObj = (MethodTestObject7)_applicationContext.GetObject("MethodTestObject7"); },
|
||||
Throws.Exception.TypeOf<ObjectCreationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PassIfObjectNotavailableButNotRequired()
|
||||
{
|
||||
var testObj1 = (MethodTestObject8)_applicationContext.GetObject("MethodTestObject8");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("MethodTestObject8");
|
||||
|
||||
Assert.That(testObj1.GetSimple(), Is.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
|
||||
var testObj2 = (MethodTestObject9)_applicationContext.GetObject("MethodTestObject9");
|
||||
objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("MethodTestObject9");
|
||||
|
||||
Assert.That(testObj2.GetrAdvanced(), Is.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region Test Objects
|
||||
|
||||
public interface ISimple
|
||||
{
|
||||
string Foo();
|
||||
}
|
||||
|
||||
public class Simple : ISimple
|
||||
{
|
||||
public string Foo()
|
||||
{
|
||||
return "simple";
|
||||
}
|
||||
}
|
||||
|
||||
public interface IAdvanced
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IMethodFoo
|
||||
{
|
||||
string Foo();
|
||||
}
|
||||
|
||||
public class MethodHello : IMethodFoo
|
||||
{
|
||||
public string Foo()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodCiao : IMethodFoo
|
||||
{
|
||||
public string Foo()
|
||||
{
|
||||
return "ciao";
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject1
|
||||
{
|
||||
private ISimple _impl;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare(ISimple impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public object GetObject()
|
||||
{
|
||||
return _impl;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject2
|
||||
{
|
||||
private IMethodFoo _methodCiao;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare(IMethodFoo methodCiao)
|
||||
{
|
||||
_methodCiao = methodCiao;
|
||||
}
|
||||
|
||||
public object GetObject()
|
||||
{
|
||||
return _methodCiao;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject3
|
||||
{
|
||||
private IMethodFoo _impl;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare([Qualifier("MethodHello")] IMethodFoo impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public object GetObject()
|
||||
{
|
||||
return _impl;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject4
|
||||
{
|
||||
private IMethodFoo _impl;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare([Qualifier("MethodHello")] IMethodFoo impl, string test)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public object GetObject()
|
||||
{
|
||||
return _impl;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject5
|
||||
{
|
||||
private IList<IMethodFoo> _impl;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare(IList<IMethodFoo> impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
public IList<IMethodFoo> GetObject()
|
||||
{
|
||||
return _impl;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject6
|
||||
{
|
||||
private IMethodFoo _impl;
|
||||
private ISimple _simple;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare(IMethodFoo methodHello, ISimple simple)
|
||||
{
|
||||
_impl = methodHello;
|
||||
_simple = simple;
|
||||
}
|
||||
|
||||
public object GetObject()
|
||||
{
|
||||
return _impl;
|
||||
}
|
||||
|
||||
public object GetSimple()
|
||||
{
|
||||
return _simple;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject7
|
||||
{
|
||||
private ISimple _simple;
|
||||
|
||||
[Autowired]
|
||||
public void Prepare([Qualifier("NotAvailable")] ISimple simple)
|
||||
{
|
||||
_simple = simple;
|
||||
}
|
||||
|
||||
public object GetSimple()
|
||||
{
|
||||
return _simple;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject8
|
||||
{
|
||||
private ISimple _simple;
|
||||
|
||||
[Autowired(Required = false)]
|
||||
public void Prepare([Qualifier("NotAvailable")] ISimple simple)
|
||||
{
|
||||
_simple = simple;
|
||||
}
|
||||
|
||||
public object GetSimple()
|
||||
{
|
||||
return _simple;
|
||||
}
|
||||
}
|
||||
|
||||
public class MethodTestObject9
|
||||
{
|
||||
private IAdvanced _advanced;
|
||||
|
||||
[Autowired(Required = false)]
|
||||
public void Prepare(IAdvanced advanced)
|
||||
{
|
||||
_advanced = advanced;
|
||||
}
|
||||
|
||||
public object GetrAdvanced()
|
||||
{
|
||||
return _advanced;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,254 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireAttributePropertyTest
|
||||
{
|
||||
private GenericApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new GenericApplicationContext();
|
||||
|
||||
var objDef = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
|
||||
objDef.Role = ObjectRole.ROLE_INFRASTRUCTURE;
|
||||
_applicationContext.RegisterObjectDefinition("AutowiredAttributeObjectPostProcessor", objDef);
|
||||
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropFooImpl));
|
||||
_applicationContext.RegisterObjectDefinition("PropFoo", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropHello));
|
||||
_applicationContext.RegisterObjectDefinition("PropHello", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropCioa));
|
||||
_applicationContext.RegisterObjectDefinition("PropCioa", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropTestObject1));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("PropTestObject1", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropTestObject2));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("PropTestObject2", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropTestObject3));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("PropTestObject3", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropTestObject4));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("PropTestObject4", objDef);
|
||||
|
||||
objDef = new RootObjectDefinition(typeof(PropTestObject5));
|
||||
objDef.Scope = "prototype";
|
||||
_applicationContext.RegisterObjectDefinition("PropTestObject5", objDef);
|
||||
|
||||
_applicationContext.Refresh();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectPropertyBasedOnPropertyType()
|
||||
{
|
||||
var testObj = (PropTestObject1)_applicationContext.GetObject("PropTestObject1");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("PropTestObject1");
|
||||
|
||||
Assert.That(testObj.Foo, Is.Not.Null);
|
||||
Assert.That(testObj.Test(), Is.EqualTo("foo"));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1), "Should have one Dependant Object");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithTwoTypesRegisteredAndNoNameShouldFail()
|
||||
{
|
||||
Assert.That(delegate { var testObj = (PropTestObject2)_applicationContext.GetObject("PropTestObject2"); }, Throws.Exception.TypeOf<ObjectCreationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithQualifierName()
|
||||
{
|
||||
var testObj = (PropTestObject3)_applicationContext.GetObject("PropTestObject3");
|
||||
|
||||
Assert.That(testObj.Cioa, Is.Not.Null);
|
||||
Assert.That(testObj.Say(), Is.EqualTo("cioa"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithTwoTypesAndNoQualifierUsePopertyName()
|
||||
{
|
||||
var testObj = (PropTestObject4)_applicationContext.GetObject("PropTestObject4");
|
||||
|
||||
Assert.That(testObj.PropCioa, Is.Not.Null);
|
||||
Assert.That(testObj.Say(), Is.EqualTo("cioa"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailIfTypeCantBeResolved()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (FldTestObject5)_applicationContext.GetObject("PropTestObject5");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Injection of autowired dependencies failed"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region Test Objects
|
||||
|
||||
public interface IPropNotAnObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IPropFoo
|
||||
{
|
||||
string Test();
|
||||
}
|
||||
|
||||
public class PropFooImpl : IPropFoo
|
||||
{
|
||||
public string Test()
|
||||
{
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPropSay
|
||||
{
|
||||
string PropSay();
|
||||
}
|
||||
|
||||
public class PropHello : IPropSay
|
||||
{
|
||||
public string PropSay()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
public class PropCioa : IPropSay
|
||||
{
|
||||
public string PropSay()
|
||||
{
|
||||
return "cioa";
|
||||
}
|
||||
}
|
||||
|
||||
public class PropTestObject1
|
||||
{
|
||||
private IPropFoo _foo;
|
||||
|
||||
[Autowired]
|
||||
public IPropFoo Foo
|
||||
{
|
||||
get { return _foo; }
|
||||
set { _foo = value; }
|
||||
}
|
||||
|
||||
public string Test()
|
||||
{
|
||||
return _foo.Test();
|
||||
}
|
||||
}
|
||||
|
||||
public class PropTestObject2
|
||||
{
|
||||
private IPropSay _hello;
|
||||
|
||||
[Autowired]
|
||||
public IPropSay WrongName
|
||||
{
|
||||
get { return _hello; }
|
||||
set { _hello = value; }
|
||||
}
|
||||
|
||||
public string Say()
|
||||
{
|
||||
return _hello.PropSay();
|
||||
}
|
||||
}
|
||||
|
||||
// should not fail but inject Cioa object
|
||||
public class PropTestObject3
|
||||
{
|
||||
private IPropSay _cioa;
|
||||
|
||||
[Autowired]
|
||||
[Qualifier("PropCioa")]
|
||||
public IPropSay Cioa
|
||||
{
|
||||
get { return _cioa; }
|
||||
set { _cioa = value; }
|
||||
}
|
||||
|
||||
public string Say()
|
||||
{
|
||||
return _cioa.PropSay();
|
||||
}
|
||||
}
|
||||
|
||||
// should not fail but inject Hello via Propertyname
|
||||
public class PropTestObject4
|
||||
{
|
||||
private IPropSay _obj;
|
||||
|
||||
[Autowired]
|
||||
public IPropSay PropCioa
|
||||
{
|
||||
get { return _obj; }
|
||||
set { _obj = value; }
|
||||
}
|
||||
|
||||
public string Say()
|
||||
{
|
||||
return _obj.PropSay();
|
||||
}
|
||||
}
|
||||
|
||||
// should not fail but inject Hello via Propertyname
|
||||
public class PropTestObject5
|
||||
{
|
||||
private IPropNotAnObject _obj;
|
||||
|
||||
[Autowired]
|
||||
public IPropNotAnObject Ohhh
|
||||
{
|
||||
get { return _obj; }
|
||||
set { _obj = value; }
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using AutowireTestConstructorNormal = Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestConstructorNormal;
|
||||
using AutowireTestFieldNormal = Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestFieldNormal;
|
||||
using AutowireTestMethodNormal = Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestMethodNormal;
|
||||
using AutowireTestPropertyNormal = Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestPropertyNormal;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByQualifierAttributeTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByQualifierAttributeObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnField()
|
||||
{
|
||||
var testObj = (AutowireTestFieldNormal) _applicationContext.GetObject("AutowireTestField");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestField");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(testObj.ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnProperty()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNormal) _applicationContext.GetObject("AutowireTestProperty");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestProperty");
|
||||
|
||||
Assert.That(testObj.Ciao, Is.Not.Null);
|
||||
Assert.That(testObj.Ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnMethod()
|
||||
{
|
||||
var testObj = (AutowireTestMethodNormal) _applicationContext.GetObject("AutowireTestMethod");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestMethod");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(testObj.ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnConstructor()
|
||||
{
|
||||
var testObj = (AutowireTestConstructorNormal)_applicationContext.GetObject("AutowireTestConstructor");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestConstructor");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(testObj.ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using AutowireTestConstructorNormal = Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestConstructorNormal;
|
||||
using AutowireTestFieldNormal = Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestFieldNormal;
|
||||
using AutowireTestMethodNormal = Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestMethodNormal;
|
||||
using AutowireTestPropertyNormal = Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestPropertyNormal;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByQualifierTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByQualifierObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnField()
|
||||
{
|
||||
var testObj = (AutowireTestFieldNormal) _applicationContext.GetObject("AutowireTestField");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestField");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(testObj.ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnProperty()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNormal) _applicationContext.GetObject("AutowireTestProperty");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestProperty");
|
||||
|
||||
Assert.That(testObj.Ciao, Is.Not.Null);
|
||||
Assert.That(testObj.Ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnMethod()
|
||||
{
|
||||
var testObj = (AutowireTestMethodNormal) _applicationContext.GetObject("AutowireTestMethod");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestMethod");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(testObj.ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnConstructor()
|
||||
{
|
||||
var testObj = (AutowireTestConstructorNormal)_applicationContext.GetObject("AutowireTestConstructor");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestConstructor");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(testObj.ciao.GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByTypeFailTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByTypeFailObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailFieldInjectionTooManyObjects()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (AutowireTestFieldNormal)_applicationContext.GetObject("AutowireTestFieldNormal");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Injection of autowired dependencies failed"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailPropertyInjectionTooManyObjects()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNormal)_applicationContext.GetObject("AutowireTestPropertyNormal");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Injection of autowired dependencies failed"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailMethodInjectionTooManyObjects()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (AutowireTestMethodNormal)_applicationContext.GetObject("AutowireTestMethodNormal");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Injection of autowired dependencies failed"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailConstructorInjectionTooManyObjects()
|
||||
{
|
||||
Exception ex = null;
|
||||
try
|
||||
{
|
||||
var testObj = (AutowireTestConstructorNormal)_applicationContext.GetObject("AutowireTestConstructorNormal");
|
||||
}
|
||||
catch (Exception e) { ex = e; }
|
||||
|
||||
Assert.That(ex, Is.Not.Null, "Should throw an exception");
|
||||
Assert.That(ex.Message, Is.StringContaining("Error creating object with name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByTypeNormalTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByTypeNormalObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnField()
|
||||
{
|
||||
var testObj = (AutowireTestFieldNormal) _applicationContext.GetObject("AutowireTestFieldNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestFieldNormal");
|
||||
|
||||
Assert.That(testObj.hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnProperty()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNormal) _applicationContext.GetObject("AutowireTestPropertyNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestPropertyNormal");
|
||||
|
||||
Assert.That(testObj.Hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnMethod()
|
||||
{
|
||||
var testObj = (AutowireTestMethodNormal) _applicationContext.GetObject("AutowireTestMethodNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestMethodNormal");
|
||||
|
||||
Assert.That(testObj.hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnConstructor()
|
||||
{
|
||||
var testObj = (AutowireTestConstructorNormal)_applicationContext.GetObject("AutowireTestConstructorNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestConstructorNormal");
|
||||
|
||||
Assert.That(testObj.hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByTypeNotRequiredTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByTypeNotRequiredObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnField()
|
||||
{
|
||||
var testObj = (AutowireTestFieldNotRequired) _applicationContext.GetObject("AutowireTestField");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestField");
|
||||
|
||||
Assert.That(testObj.hello, Is.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnProperty()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNotRequired) _applicationContext.GetObject("AutowireTestProperty");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestProperty");
|
||||
|
||||
Assert.That(testObj.Hello, Is.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnMethod()
|
||||
{
|
||||
var testObj = (AutowireTestMethodNotRequired) _applicationContext.GetObject("AutowireTestMethod");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestMethod");
|
||||
|
||||
Assert.That(testObj.hello, Is.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByTypePrimaryTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByTypePrimaryObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnField()
|
||||
{
|
||||
var testObj = (AutowireTestFieldNormal) _applicationContext.GetObject("AutowireTestFieldNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestFieldNormal");
|
||||
|
||||
Assert.That(testObj.hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnProperty()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNormal) _applicationContext.GetObject("AutowireTestPropertyNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestPropertyNormal");
|
||||
|
||||
Assert.That(testObj.Hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnMethod()
|
||||
{
|
||||
var testObj = (AutowireTestMethodNormal) _applicationContext.GetObject("AutowireTestMethodNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestMethodNormal");
|
||||
|
||||
Assert.That(testObj.hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnConstructor()
|
||||
{
|
||||
var testObj = (AutowireTestConstructorNormal)_applicationContext.GetObject("AutowireTestConstructorNormal");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestConstructorNormal");
|
||||
|
||||
Assert.That(testObj.hello, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Collections.Specialized;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByValue;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireByValueTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false, "assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByValueObjects.xml");
|
||||
ContextRegistry.RegisterContext(_applicationContext);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Dispose()
|
||||
{
|
||||
ContextRegistry.Clear();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnField()
|
||||
{
|
||||
var testObj = (AutowireTestFieldNormal) _applicationContext.GetObject("AutowireTestField");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestField");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnProperty()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyNormal) _applicationContext.GetObject("AutowireTestProperty");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestProperty");
|
||||
|
||||
Assert.That(testObj.Ciao, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnMethod()
|
||||
{
|
||||
var testObj = (AutowireTestMethodNormal) _applicationContext.GetObject("AutowireTestMethod");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestMethod");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectOnConstructor()
|
||||
{
|
||||
var testObj = (AutowireTestConstructorNormal)_applicationContext.GetObject("AutowireTestConstructor");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestConstructor");
|
||||
|
||||
Assert.That(testObj.ciao, Is.Not.Null);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectPropertyPlaceholderValue()
|
||||
{
|
||||
var testObj = (AutowireTestPropertyPlaceHolder)_applicationContext.GetObject("AutowireTestPropertyPlaceHolder");
|
||||
Assert.That(testObj.greeting, Is.EqualTo("ciao"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright © 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
using Spring.Objects.Factory.Attributes.Collections;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes
|
||||
{
|
||||
[TestFixture]
|
||||
public class AutowireCollectionTests
|
||||
{
|
||||
private XmlApplicationContext _applicationContext;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_applicationContext = new XmlApplicationContext(false,
|
||||
"assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/CollectionObjects.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectIntoList()
|
||||
{
|
||||
var testObj = (AutowireTestList)_applicationContext.GetObject("AutowireTestList");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestList");
|
||||
|
||||
Assert.That(testObj.foos, Is.Not.Null);
|
||||
Assert.That(testObj.foos.Count, Is.EqualTo(2));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectIntoSet()
|
||||
{
|
||||
var testObj = (AutowireTestSet)_applicationContext.GetObject("AutowireTestSet");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestSet");
|
||||
|
||||
Assert.That(testObj.foos, Is.Not.Null);
|
||||
Assert.That(testObj.foos.Count, Is.EqualTo(2));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectIntoDictionary()
|
||||
{
|
||||
var testObj = (AutowireTestDictionary)_applicationContext.GetObject("AutowireTestDictionary");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestDictionary");
|
||||
|
||||
Assert.That(testObj.foos, Is.Not.Null);
|
||||
Assert.That(testObj.foos.Count, Is.EqualTo(2));
|
||||
Assert.That(testObj.foos.ContainsKey("HelloFoo"), Is.True);
|
||||
Assert.That(testObj.foos.ContainsKey("CiaoFoo"), Is.True);
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectIntoDictionaryFail()
|
||||
{
|
||||
Exception ex = null;
|
||||
|
||||
try
|
||||
{
|
||||
var testObj = (AutowireTestDictionaryFail)_applicationContext.GetObject("AutowireTestDictionaryFail");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ex = e;
|
||||
}
|
||||
|
||||
Assert.That(ex, Is.Not.Null);
|
||||
Assert.That(ex.InnerException.InnerException.Message.Contains("first generic to be a string"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InjectIntoListWithQualifier()
|
||||
{
|
||||
var testObj = (AutowireTestQualifier)_applicationContext.GetObject("AutowireTestQualifier");
|
||||
var objectDefinition = _applicationContext.ObjectFactory.GetObjectDefinition("AutowireTestQualifier");
|
||||
|
||||
Assert.That(testObj.foos, Is.Not.Null);
|
||||
Assert.That(testObj.foos.Count, Is.EqualTo(1));
|
||||
Assert.That(testObj.foos[0].GetType(), Is.EqualTo(typeof(CiaoFoo)));
|
||||
Assert.That(objectDefinition.DependsOn.Count, Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Spring.Objects.Factory.Attributes.ByType;
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes.ByType
|
||||
{
|
||||
public interface IFoo
|
||||
{
|
||||
string Say();
|
||||
}
|
||||
|
||||
public class HelloFoo : IFoo
|
||||
{
|
||||
public string Say()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
public class CiaoFoo : IFoo
|
||||
{
|
||||
public string Say()
|
||||
{
|
||||
return "ciao";
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestFieldNormal
|
||||
{
|
||||
[Autowired]
|
||||
public IFoo hello;
|
||||
}
|
||||
|
||||
public class AutowireTestPropertyNormal
|
||||
{
|
||||
[Autowired]
|
||||
public IFoo Hello { get; set; }
|
||||
}
|
||||
|
||||
public class AutowireTestMethodNormal
|
||||
{
|
||||
public IFoo hello;
|
||||
|
||||
[Autowired]
|
||||
private void Prepare(IFoo hello)
|
||||
{
|
||||
this.hello = hello;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestConstructorNormal
|
||||
{
|
||||
public IFoo hello;
|
||||
|
||||
[Autowired]
|
||||
public AutowireTestConstructorNormal(IFoo hello)
|
||||
{
|
||||
this.hello = hello;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestFieldNotRequired
|
||||
{
|
||||
[Autowired(Required = false)]
|
||||
public IFoo hello;
|
||||
}
|
||||
|
||||
public class AutowireTestPropertyNotRequired
|
||||
{
|
||||
[Autowired(Required = false)]
|
||||
public IFoo Hello { get; set; }
|
||||
}
|
||||
|
||||
public class AutowireTestMethodNotRequired
|
||||
{
|
||||
public IFoo hello;
|
||||
|
||||
[Autowired(Required = false)]
|
||||
private void Prepare(IFoo hello)
|
||||
{
|
||||
this.hello = hello;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes.ByQualifier
|
||||
{
|
||||
public class AutowireTestFieldNormal
|
||||
{
|
||||
[Autowired]
|
||||
[Qualifier("ciao")]
|
||||
public IFoo ciao;
|
||||
}
|
||||
|
||||
public class AutowireTestPropertyNormal
|
||||
{
|
||||
[Autowired]
|
||||
[Qualifier("ciao")]
|
||||
public IFoo Ciao { get; set; }
|
||||
}
|
||||
|
||||
public class AutowireTestMethodNormal
|
||||
{
|
||||
public IFoo ciao;
|
||||
|
||||
[Autowired]
|
||||
private void Prepare([Qualifier("ciao")] IFoo ciao)
|
||||
{
|
||||
this.ciao = ciao;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestConstructorNormal
|
||||
{
|
||||
public IFoo ciao;
|
||||
|
||||
[Autowired]
|
||||
public AutowireTestConstructorNormal([Qualifier("ciao")] IFoo ciao)
|
||||
{
|
||||
this.ciao = ciao;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes.ByQualifierAttribute
|
||||
{
|
||||
public class DialectAttribute : QualifierAttribute
|
||||
{
|
||||
private string _language = "";
|
||||
|
||||
public string Language { get { return _language; } set { _language = value; } }
|
||||
}
|
||||
|
||||
public class AutowireTestFieldNormal
|
||||
{
|
||||
[Autowired]
|
||||
[Dialect(Language = "Italian")]
|
||||
public IFoo ciao;
|
||||
}
|
||||
|
||||
public class AutowireTestPropertyNormal
|
||||
{
|
||||
[Autowired]
|
||||
[Dialect(Language = "Italian")]
|
||||
public IFoo Ciao { get; set; }
|
||||
}
|
||||
|
||||
public class AutowireTestMethodNormal
|
||||
{
|
||||
public IFoo ciao;
|
||||
|
||||
[Autowired]
|
||||
private void Prepare([Dialect(Language = "Italian")] IFoo ciao)
|
||||
{
|
||||
this.ciao = ciao;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestConstructorNormal
|
||||
{
|
||||
public IFoo ciao;
|
||||
|
||||
[Autowired]
|
||||
public AutowireTestConstructorNormal([Dialect(Language = "Italian")] IFoo ciao)
|
||||
{
|
||||
this.ciao = ciao;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes.ByValue
|
||||
{
|
||||
public class AutowireTestFieldNormal
|
||||
{
|
||||
[Value("@(CiaoFoo)")]
|
||||
public IFoo ciao;
|
||||
}
|
||||
|
||||
public class AutowireTestPropertyNormal
|
||||
{
|
||||
[Value("@(CiaoFoo)")]
|
||||
public IFoo Ciao { get; set; }
|
||||
}
|
||||
|
||||
public class AutowireTestMethodNormal
|
||||
{
|
||||
public IFoo ciao;
|
||||
|
||||
[Autowired]
|
||||
private void Prepare([Value("@(CiaoFoo)")] IFoo ciao)
|
||||
{
|
||||
this.ciao = ciao;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestConstructorNormal
|
||||
{
|
||||
public IFoo ciao;
|
||||
|
||||
[Autowired]
|
||||
public AutowireTestConstructorNormal([Value("@(CiaoFoo)")] IFoo ciao)
|
||||
{
|
||||
this.ciao = ciao;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutowireTestPropertyPlaceHolder
|
||||
{
|
||||
[Value("${greeting}")]
|
||||
public string greeting;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Spring.Objects.Factory.Attributes.Collections
|
||||
{
|
||||
public class AutowireTestList
|
||||
{
|
||||
[Autowired]
|
||||
public IList<IFoo> foos;
|
||||
}
|
||||
|
||||
public class AutowireTestSet
|
||||
{
|
||||
[Autowired]
|
||||
public Spring.Collections.Generic.ISet<IFoo> foos;
|
||||
}
|
||||
|
||||
public class AutowireTestDictionary
|
||||
{
|
||||
[Autowired]
|
||||
public IDictionary<string, IFoo> foos;
|
||||
}
|
||||
|
||||
public class AutowireTestDictionaryFail
|
||||
{
|
||||
[Autowired]
|
||||
public IDictionary<IFoo, IFoo> foos;
|
||||
}
|
||||
|
||||
public class AutowireTestQualifier
|
||||
{
|
||||
[Autowired]
|
||||
[Qualifier("ciao")]
|
||||
public IList<IFoo> foos;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests">
|
||||
<qualifier type="Spring.Objects.Factory.Attributes.ByQualifierAttribute.DialectAttribute">
|
||||
<attribute key="Language" value="English" />
|
||||
</qualifier>
|
||||
</object>
|
||||
|
||||
<object id="CiaoFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.CiaoFoo, Spring.Core.Tests">
|
||||
<qualifier type="Spring.Objects.Factory.Attributes.ByQualifierAttribute.DialectAttribute">
|
||||
<attribute key="Language" value="Italian" />
|
||||
</qualifier>
|
||||
</object>
|
||||
|
||||
<object id="AutowireTestField"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestFieldNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestProperty"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestPropertyNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethod"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestMethodNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestConstructor"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifierAttribute.AutowireTestConstructorNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests">
|
||||
<qualifier value="hello" />
|
||||
</object>
|
||||
|
||||
<object id="CiaoFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.CiaoFoo, Spring.Core.Tests">
|
||||
<qualifier value="ciao" />
|
||||
</object>
|
||||
|
||||
<object id="AutowireTestField"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestFieldNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestProperty"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestPropertyNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethod"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestMethodNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestConstructor"
|
||||
type="Spring.Objects.Factory.Attributes.ByQualifier.AutowireTestConstructorNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests" />
|
||||
|
||||
<object id="CiaoFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.CiaoFoo, Spring.Core.Tests" />
|
||||
|
||||
<object id="AutowireTestFieldNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestFieldNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestPropertyNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestPropertyNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethodNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestMethodNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestConstructorNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestConstructorNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests" />
|
||||
|
||||
<object id="AutowireTestFieldNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestFieldNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestPropertyNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestPropertyNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethodNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestMethodNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestConstructorNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestConstructorNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="AutowireTestField"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestFieldNotRequired, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestProperty"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestPropertyNotRequired, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethod"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestMethodNotRequired, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests"
|
||||
primary="true"/>
|
||||
|
||||
<object id="CiaoFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.CiaoFoo, Spring.Core.Tests" />
|
||||
|
||||
<object id="AutowireTestFieldNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestFieldNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestPropertyNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestPropertyNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethodNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestMethodNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestConstructorNormal"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.AutowireTestConstructorNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
|
||||
<configSections>
|
||||
<sectionGroup name="spring">
|
||||
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
|
||||
</sectionGroup>
|
||||
<section name="NameValues" type="System.Configuration.NameValueSectionHandler"/>
|
||||
</configSections>
|
||||
|
||||
<NameValues>
|
||||
<add key="greeting" value="ciao"/>
|
||||
</NameValues>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object id="appPropertyConfigurer" type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
|
||||
<property name="Location" value="assembly://Spring.Core.Tests/Spring.Objects.Factory.Attributes/ByValueObjects.config" />
|
||||
<property name="ConfigSections" value="NameValues" />
|
||||
</object>
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests" />
|
||||
|
||||
<object id="CiaoFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.CiaoFoo, Spring.Core.Tests" />
|
||||
|
||||
<object id="AutowireTestField"
|
||||
type="Spring.Objects.Factory.Attributes.ByValue.AutowireTestFieldNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestProperty"
|
||||
type="Spring.Objects.Factory.Attributes.ByValue.AutowireTestPropertyNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestMethod"
|
||||
type="Spring.Objects.Factory.Attributes.ByValue.AutowireTestMethodNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestConstructor"
|
||||
type="Spring.Objects.Factory.Attributes.ByValue.AutowireTestConstructorNormal, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestPropertyPlaceHolder"
|
||||
type="Spring.Objects.Factory.Attributes.ByValue.AutowireTestPropertyPlaceHolder, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net">
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.AutowiredAttributeObjectPostProcessor, Spring.Core" />
|
||||
|
||||
<object id="HelloFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.HelloFoo, Spring.Core.Tests">
|
||||
<qualifier value="hello" />
|
||||
</object>
|
||||
|
||||
<object id="CiaoFoo"
|
||||
type="Spring.Objects.Factory.Attributes.ByType.CiaoFoo, Spring.Core.Tests">
|
||||
<qualifier value="ciao" />
|
||||
</object>
|
||||
|
||||
<object id="AutowireTestList"
|
||||
type="Spring.Objects.Factory.Attributes.Collections.AutowireTestList, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestSet"
|
||||
type="Spring.Objects.Factory.Attributes.Collections.AutowireTestSet, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestDictionary"
|
||||
type="Spring.Objects.Factory.Attributes.Collections.AutowireTestDictionary, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestDictionaryFail"
|
||||
type="Spring.Objects.Factory.Attributes.Collections.AutowireTestDictionaryFail, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
<object id="AutowireTestQualifier"
|
||||
type="Spring.Objects.Factory.Attributes.Collections.AutowireTestQualifier, Spring.Core.Tests"
|
||||
lazy-init="true" />
|
||||
|
||||
</objects>
|
||||
@@ -150,6 +150,7 @@ namespace Spring.Objects.Factory.Config
|
||||
IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof(IConfigurableListableObjectFactory));
|
||||
Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] {defName});
|
||||
Expect.Call(mock.GetObjectDefinition(defName)).Return(def);
|
||||
Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments();
|
||||
mocks.ReplayAll();
|
||||
|
||||
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
|
||||
@@ -422,6 +423,7 @@ namespace Spring.Objects.Factory.Config
|
||||
IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory));
|
||||
Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"});
|
||||
Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def);
|
||||
Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments();
|
||||
mocks.ReplayAll();
|
||||
|
||||
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
|
||||
@@ -451,6 +453,7 @@ namespace Spring.Objects.Factory.Config
|
||||
IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory));
|
||||
Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"});
|
||||
Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def);
|
||||
Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments();
|
||||
mocks.ReplayAll();
|
||||
|
||||
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
|
||||
@@ -548,6 +551,7 @@ namespace Spring.Objects.Factory.Config
|
||||
IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof(IConfigurableListableObjectFactory));
|
||||
Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] {defName});
|
||||
Expect.Call(mock.GetObjectDefinition(defName)).Return(def);
|
||||
Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments();
|
||||
mocks.ReplayAll();
|
||||
|
||||
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
|
||||
|
||||
@@ -73,6 +73,11 @@ namespace Spring.Objects.Factory
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool IsPrimary
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public string ParentName
|
||||
{
|
||||
get { return null; }
|
||||
|
||||
@@ -302,7 +302,19 @@
|
||||
<Compile Include="Globalization\Formatters\BooleanFormatterTests.cs" />
|
||||
<Compile Include="Globalization\Formatters\CurrencyFormatterTests.cs" />
|
||||
<Compile Include="Globalization\Formatters\DateTimeFormatterTests.cs" />
|
||||
<Compile Include="Globalization\Formatters\FilteringFormatterTests.cs" />
|
||||
<Compile Include="Globalization\Formatters\FilteringFormatterTests.cs" /> <Compile Include="Objects\Factory\Attributes\AutowireByTypeNormalTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeFailTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireTestObjects.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypePrimaryTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeNotRequiredTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByQualifierTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByQualifierAttributeTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByValueTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireCollectionTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\MyRequiredAttribute.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\RequiredAttributeObjectPostProcessorTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\RequiredTestObject.cs" />
|
||||
|
||||
<Compile Include="Globalization\Formatters\FloatFormatterTests.cs" />
|
||||
<Compile Include="Globalization\Formatters\HasTextFilteringFormatterTests.cs" />
|
||||
<Compile Include="Globalization\Formatters\IntegerFormatterTests.cs" />
|
||||
@@ -316,6 +328,15 @@
|
||||
</Compile>
|
||||
<Compile Include="HookableContextHandler.cs" />
|
||||
<Compile Include="Objects\ExpressionTestObject.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeNormalTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeFailTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireTestObjects.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypePrimaryTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeNotRequiredTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByQualifierTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByQualifierAttributeTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByValueTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireCollectionTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\MyRequiredAttribute.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\RequiredAttributeObjectPostProcessorTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\RequiredTestObject.cs" />
|
||||
@@ -864,6 +885,15 @@
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithThreeRequiredPropertiesOmitted.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithAllRequiredPropertiesProvided.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithCustomAttribute.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypeNormalObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypeFailObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypePrimaryObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypeNotRequiredObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByQualifierObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByQualifierAttributeObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByValueObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByValueObjects.config" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\CollectionObjects.xml" />
|
||||
<Content Include="Spring.Core.Tests.dll.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
@@ -318,11 +318,15 @@
|
||||
</Compile>
|
||||
<Compile Include="HookableContextHandler.cs" />
|
||||
<Compile Include="Objects\ExpressionTestObject.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireAttributeCollectionTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireAttributeConstructorTest.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireAttributeFieldTest.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireAttributeMethodsTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireAttributePropertyTest.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeNormalTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeFailTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireTestObjects.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypePrimaryTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByTypeNotRequiredTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByQualifierTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByQualifierAttributeTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireByValueTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\AutowireCollectionTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\MyRequiredAttribute.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\RequiredAttributeObjectPostProcessorTests.cs" />
|
||||
<Compile Include="Objects\Factory\Attributes\RequiredTestObject.cs" />
|
||||
@@ -872,6 +876,15 @@
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithThreeRequiredPropertiesOmitted.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithAllRequiredPropertiesProvided.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\RequiredWithCustomAttribute.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypeNormalObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypeFailObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypePrimaryObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByTypeNotRequiredObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByQualifierObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByQualifierAttributeObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByValueObjects.xml" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\ByValueObjects.config" />
|
||||
<EmbeddedResource Include="Objects\Factory\Attributes\CollectionObjects.xml" />
|
||||
<Content Include="Spring.Core.Tests.dll.config" />
|
||||
<EmbeddedResource Include="Resources\Spring.Context.Tests.de-AT.resx" />
|
||||
<EmbeddedResource Include="Resources\Spring.Context.Tests.de.resx" />
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<include name="**/*.vb" />
|
||||
<include name="**/*.properties" />
|
||||
<include name="**/*.xml" />
|
||||
<include name="**/*.config" />
|
||||
<!--
|
||||
<include name="**/SimpleAppContext.xml" />
|
||||
<include name="**/Factory/Attributes/*.xml" />
|
||||
|
||||
Reference in New Issue
Block a user