|
From: <and...@us...> - 2009-10-07 17:18:08
|
Revision: 267
http://structuremap.svn.sourceforge.net/structuremap/?rev=267&view=rev
Author: andreas_ohlund
Date: 2009-10-07 17:17:56 +0000 (Wed, 07 Oct 2009)
Log Message:
-----------
WithCtorArg can now be used with both simple and non simple types
Modified Paths:
--------------
trunk/Source/StructureMap/Pipeline/PropertyExpression.cs
trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
Modified: trunk/Source/StructureMap/Pipeline/PropertyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-10-07 16:59:34 UTC (rev 266)
+++ trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-10-07 17:17:56 UTC (rev 267)
@@ -23,7 +23,12 @@
/// <returns></returns>
public T EqualTo(object propertyValue)
{
- _instance.SetProperty(_propertyName, propertyValue.ToString());
+ if(propertyValue.GetType().IsSimple())
+ _instance.SetProperty(_propertyName, propertyValue.ToString());
+ else
+ {
+ _instance.SetChild(_propertyName,new LiteralInstance(propertyValue));
+ }
return (T) _instance;
}
Modified: trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 16:59:34 UTC (rev 266)
+++ trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 17:17:56 UTC (rev 267)
@@ -98,8 +98,31 @@
});
}
+ [Test]
+ public void specify_ctorarg_with_non_simple_argument()
+ {
+ var widget = new ColorWidget("Red");
+ var container = new Container(x => x.ForRequestedType<ClassWithWidget>()
+ .TheDefault.Is.OfConcreteType<ClassWithWidget>()
+ .WithCtorArg("widget").EqualTo(widget));
+ Assert.AreSame(widget, container.GetInstance<ClassWithWidget>().Widget);
+ }
+
+
[Test]
+ public void specify_a_non_simple_property_with_equal_to()
+ {
+ var widget = new ColorWidget("Red");
+ var container = new Container(x => x.ForRequestedType<ClassWithWidgetProperty>()
+ .TheDefault.Is.OfConcreteType<ClassWithWidgetProperty>()
+ .WithProperty(o => o.Widget).EqualTo(widget));
+
+ Assert.AreSame(widget, container.GetInstance<ClassWithWidgetProperty>().Widget);
+ }
+
+
+ [Test]
public void specify_an_array_as_a_constructor()
{
IWidget widget1 = new AWidget();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|