Support type alias resolution in <value/> element [SPRNET-1119]
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
<property name="TypeAliases">
|
||||
<dictionary>
|
||||
<entry key="TestObject" value="Spring.Objects.TestObject, Spring.Core.Tests" />
|
||||
<entry key="intAlias" value="System.Int32" />
|
||||
</dictionary>
|
||||
</property>
|
||||
</object>
|
||||
@@ -19,4 +20,12 @@
|
||||
<constructor-arg name="age" value="26"/>
|
||||
</object>
|
||||
|
||||
<!-- SPRNET-1119 -->
|
||||
<object id="testObject4" type="TestObject">
|
||||
<constructor-arg name="name" value="Bruno"/>
|
||||
<constructor-arg name="age">
|
||||
<value type="intAlias">30</value>
|
||||
</constructor-arg>
|
||||
</object>
|
||||
|
||||
</objects>
|
||||
@@ -124,6 +124,13 @@ namespace Spring.Objects.Factory.Config
|
||||
Assert.AreEqual(typeof(TestObject), obj3.GetType());
|
||||
Assert.AreEqual("Bruno", ((TestObject)obj3).Name);
|
||||
Assert.AreEqual(26, ((TestObject)obj3).Age);
|
||||
|
||||
// SPRNET-1119
|
||||
object obj4 = ctx.GetObject("testObject4");
|
||||
Assert.IsNotNull(obj4);
|
||||
Assert.AreEqual(typeof(TestObject), obj4.GetType());
|
||||
Assert.AreEqual("Bruno", ((TestObject)obj4).Name);
|
||||
Assert.AreEqual(30, ((TestObject)obj4).Age);
|
||||
}
|
||||
|
||||
private void CreateConfigurerAndTestLinkedList(IDictionary typeAliases)
|
||||
|
||||
@@ -40,20 +40,41 @@ namespace Spring.Objects.Factory.Config
|
||||
public void Instantiation()
|
||||
{
|
||||
string expectedNow = DateTime.Now.ToShortDateString();
|
||||
TypedStringValue tsv = new TypedStringValue(expectedNow, typeof (DateTime));
|
||||
|
||||
TypedStringValue tsv = new TypedStringValue(expectedNow, typeof (DateTime));
|
||||
Assert.AreEqual(expectedNow, tsv.Value);
|
||||
Assert.AreEqual(typeof (DateTime), tsv.TargetType);
|
||||
|
||||
tsv = new TypedStringValue(expectedNow);
|
||||
Assert.AreEqual(expectedNow, tsv.Value);
|
||||
|
||||
tsv = new TypedStringValue(expectedNow, typeof(DateTime).FullName);
|
||||
Assert.AreEqual(expectedNow, tsv.Value);
|
||||
Assert.AreEqual(typeof(DateTime).FullName, tsv.TargetTypeName);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof (ArgumentNullException))]
|
||||
public void InstantiationWithNullType()
|
||||
{
|
||||
new TypedStringValue(string.Empty, null);
|
||||
new TypedStringValue(string.Empty, (Type)null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void InstantiationWithNullTypeName()
|
||||
{
|
||||
new TypedStringValue(string.Empty, (string)null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void InstantiationWithEmptyTypeName()
|
||||
{
|
||||
new TypedStringValue(string.Empty, " ");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof (ArgumentNullException))]
|
||||
public void SetTargetTypePropertyToNullType()
|
||||
@@ -62,6 +83,14 @@ namespace Spring.Objects.Factory.Config
|
||||
tsv.TargetType = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void SetTargetTypeNamePropertyToEmptyString()
|
||||
{
|
||||
TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime));
|
||||
tsv.TargetTypeName = " ";
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsSerializable()
|
||||
{
|
||||
@@ -88,5 +117,33 @@ namespace Spring.Objects.Factory.Config
|
||||
Assert.AreEqual(expectedValue, deser.Value,
|
||||
"Serialization roundtrip yielded the wrong Value.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasTargetType()
|
||||
{
|
||||
TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime));
|
||||
Assert.IsTrue(tsv.HasTargetType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasTargetTypeReturnsFalseWhenTargetTypeNotResolved()
|
||||
{
|
||||
TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime).FullName);
|
||||
Assert.IsFalse(tsv.HasTargetType);
|
||||
|
||||
tsv = new TypedStringValue(string.Empty, typeof(DateTime));
|
||||
Assert.IsTrue(tsv.HasTargetType);
|
||||
tsv.TargetTypeName = typeof(DateTime).FullName;
|
||||
Assert.IsFalse(tsv.HasTargetType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResolveTargetType()
|
||||
{
|
||||
TypedStringValue tsv = new TypedStringValue(string.Empty, typeof(DateTime).FullName);
|
||||
Assert.IsFalse(tsv.HasTargetType);
|
||||
Assert.AreEqual(typeof(DateTime), tsv.ResolveTargetType());
|
||||
Assert.IsTrue(tsv.HasTargetType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user