User: xtoff
Date: 2010/01/20 10:15 AM
Modified:
/InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Registration/
DynamicParametersTestCase.cs
/InversionOfControl/trunk/src/Castle.MicroKernel/Context/
CreationContext.cs
Log:
- fixed IOC-ISSUE-190 - "Resolve with argumentsAsAnonymousType overload is now
case sensitive".
CreationContext no longer tries to duplicate passed IDictionary when it's
readonly, with the exception of ReflectionBasedDictionaryAdapter.
This allows for things like usage of custom IDictionary implementation with
custom logic, which previous implementation would wipe away.
ReflectionBasedDictionaryAdapters are replicated but using OrdinalIgnoreCase
string comparer, which means their behavior does not change.
This fixed a regression bug introduced in v2.1, and brings the behavior back
to what it was in v2.0.
File Changes:
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel/Context/
====================================================================
File [modified]: CreationContext.cs
Delta lines: +51 -2
===================================================================
---
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Registration/DynamicParametersTestCase.cs
2010-01-18 19:46:17 UTC (rev 6702)
+++
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Registration/DynamicParametersTestCase.cs
2010-01-20 17:15:55 UTC (rev 6703)
@@ -14,6 +14,10 @@
namespace Castle.MicroKernel.Tests.Registration
{
+ using System;
+ using System.Collections;
+ using System.Collections.Generic;
+
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.Tests.ClassComponents;
using NUnit.Framework;
@@ -98,6 +102,37 @@
}
[Test]
+ public void
Arguments_are_case_insensitive_when_using_anonymous_object()
+ {
+ var wasCalled = false;
+
Kernel.Register(Component.For<ClassWithArguments>().LifeStyle.Transient.DynamicParameters((k,
d) =>
+ {
+ Assert.IsTrue(d.Contains("ArG1"));
+ wasCalled = true;
+ }));
+
+ Kernel.Resolve<ClassWithArguments>(new { arg2 = 2, arg1
= "foo" });
+
+ Assert.IsTrue(wasCalled);
+ }
+
+ [Test]
+ public void
DynamicParameters_will_not_enforce_passed_IDictionary_to_be_writeable()
+ {
+ var wasCalled = false;
+
Kernel.Register(Component.For<DefaultCustomer>().LifeStyle.Transient.DynamicParameters((k,
d) =>
+ {
+ Assert.Throws(typeof(NotSupportedException), ()
=>
+ d.Add("foo", "It will throw"));
+ wasCalled = true;
+ }));
+
+ Kernel.Resolve<DefaultCustomer>(new
ReadOnlyDictionary());
+
+ Assert.IsTrue(wasCalled);
+ }
+
+ [Test]
public void Should_handle_multiple_calls()
{
string arg1 = "bar";
@@ -127,8 +162,9 @@
d["arg1"] = arg1;
d["arg2"] = arg2;
}));
- //Assert.DoesNotThrow(() =>
- Kernel.Resolve<ClassWithArguments>();//);
+
+ Assert.DoesNotThrow(() =>
+ Kernel.Resolve<ClassWithArguments>());
}
[Test]
@@ -179,4 +215,17 @@
Assert.AreEqual(2, releaseCalled);
}
}
+
+ public class ReadOnlyDictionary : Dictionary<object, object>,
IDictionary
+ {
+ public bool IsReadOnly
+ {
+ get { return true; }
+ }
+
+ public new void Add(object key, object value)
+ {
+ throw new NotSupportedException();
+ }
+ }
}
Directory: /InversionOfControl/trunk/src/Castle.MicroKernel.Tests/Registration/
===============================================================================
File [modified]: DynamicParametersTestCase.cs
Delta lines: +0 -0
===================================================================
--
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en.