User: xtoff
Date: 2009/12/18 11:18 AM
Modified:
/InversionOfControl/trunk/src/Castle.Windsor.Tests/
ModelInterceptorsSelectorTestCase.cs
/InversionOfControl/trunk/src/Castle.Windsor/Proxy/
AbstractProxyFactory.cs
Log:
- fixed IOC-ISSUE-151 - Cumulative IModelInterceptorsSelectors (patch by
Mauricio Scheffer)
File Changes:
Directory: /InversionOfControl/trunk/src/Castle.Windsor.Tests/
==============================================================
File [modified]: ModelInterceptorsSelectorTestCase.cs
Delta lines: +0 -0
===================================================================
Directory: /InversionOfControl/trunk/src/Castle.Windsor/Proxy/
==============================================================
File [modified]: AbstractProxyFactory.cs
Delta lines: +50 -10
===================================================================
---
InversionOfControl/trunk/src/Castle.Windsor.Tests/ModelInterceptorsSelectorTestCase.cs
2009-12-18 15:48:07 UTC (rev 6454)
+++
InversionOfControl/trunk/src/Castle.Windsor.Tests/ModelInterceptorsSelectorTestCase.cs
2009-12-18 18:18:19 UTC (rev 6455)
@@ -14,18 +14,18 @@
#if !SILVERLIGHT
-using System;
-using Castle.Core;
-using Castle.Core.Interceptor;
-using Castle.DynamicProxy;
-using Castle.MicroKernel;
-using Castle.MicroKernel.Proxy;
-using Castle.Windsor;
-using NUnit.Framework;
namespace Castle.Windsor.Tests
{
- [TestFixture]
+ using System;
+
+ using Castle.Core;
+ using Castle.Core.Interceptor;
+ using Castle.MicroKernel.Proxy;
+
+ using NUnit.Framework;
+
+ [TestFixture]
public class ModelInterceptorsSelectorTestCase
{
public interface IWatcher
@@ -48,7 +48,16 @@
WasCalled = true;
}
}
+ public class AnotherDummyInterceptor:
StandardInterceptor
+ {
+ public static bool WasCalled;
+ protected override void PreProceed(IInvocation invocation)
+ {
+
+ WasCalled = true;
+ }
+ }
public class Person
{
public IWatcher Watcher;
@@ -58,7 +67,18 @@
Watcher = watcher;
}
}
+ public class AnotherInterceptorSelector: IModelInterceptorsSelector
+ {
+ public InterceptorReference[] SelectInterceptors(ComponentModel
model)
+ {
+ return new[] {new
InterceptorReference(typeof(AnotherDummyInterceptor)), };
+ }
+ public bool HasInterceptors(ComponentModel model)
+ {
+ return model.Service == typeof(IWatcher);
+ }
+ }
public enum Interceptors
{
None,
@@ -75,7 +95,7 @@
return null;
if(Interceptors==Interceptors.None)
return null;
- return new InterceptorReference[]{new
InterceptorReference(typeof(DummyInterceptor)), };
+ return new[]{new
InterceptorReference(typeof(DummyInterceptor)), };
}
public bool HasInterceptors(ComponentModel model)
@@ -143,6 +163,26 @@
Assert.IsTrue(DummyInterceptor.WasCalled);
}
+ [Test]
+ public void InterceptorSelectors_Are_Cumulative()
+ {
+ IWindsorContainer container = new WindsorContainer();
+ container
+ .AddComponent<DummyInterceptor>()
+ .AddComponent<AnotherDummyInterceptor>()
+ .AddComponentLifeStyle<IWatcher, BirdWatcher>("bird.watcher",
LifestyleType.Transient);
+
+ WatcherInterceptorSelector selector = new
WatcherInterceptorSelector();
+ selector.Interceptors = Interceptors.Dummy;
+ container.Kernel.ProxyFactory.AddInterceptorSelector(selector);
+ container.Kernel.ProxyFactory.AddInterceptorSelector(new
AnotherInterceptorSelector());
+
+ IWatcher watcher = container.Resolve<IWatcher>();
+ watcher.OnSomethingInterestingToWatch += delegate { };
+ Assert.IsTrue(DummyInterceptor.WasCalled);
+ Assert.IsTrue(AnotherDummyInterceptor.WasCalled);
+ }
+
}
}
--
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.