Commit 29fd729

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-05-06 14:22:18
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@211 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 9c416a6
trunk/product/MyMoney/boot/container/registration/proxy_configuration/InterceptingFilter.cs
@@ -0,0 +1,20 @@
+using Castle.Core.Interceptor;
+using Gorilla.Commons.Utility.Core;
+
+namespace MoMoney.boot.container.registration.proxy_configuration
+{
+    public class InterceptingFilter : IInterceptor
+    {
+        readonly ISpecification<IInvocation> condition;
+
+        public InterceptingFilter(ISpecification<IInvocation> condition)
+        {
+            this.condition = condition;
+        }
+
+        public void Intercept(IInvocation invocation)
+        {
+            if (condition.is_satisfied_by(invocation)) invocation.Proceed();
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/proxy_configuration/InterceptingFilterFactory.cs
@@ -0,0 +1,18 @@
+using Castle.Core.Interceptor;
+using Gorilla.Commons.Utility.Core;
+
+namespace MoMoney.boot.container.registration.proxy_configuration
+{
+    public interface IInterceptingFilterFactory
+    {
+        IInterceptor create_for(ISpecification<IInvocation> specification);
+    }
+
+    public class InterceptingFilterFactory : IInterceptingFilterFactory
+    {
+        public IInterceptor create_for(ISpecification<IInvocation> specification)
+        {
+            return new InterceptingFilter(specification);
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/proxy_configuration/InterceptingFilterFactorySpecs.cs
@@ -0,0 +1,27 @@
+using Castle.Core.Interceptor;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+using Gorilla.Commons.Utility.Core;
+
+namespace MoMoney.boot.container.registration.proxy_configuration
+{
+    public class InterceptingFilterFactorySpecs
+    {
+        public class when_creating_an_intercepting_filter :
+            concerns_for<IInterceptingFilterFactory, InterceptingFilterFactory>
+        {
+            context c = () => { condition = an<ISpecification<IInvocation>>(); };
+
+            because b = () => { result = sut.create_for(condition); };
+
+            it should_return_a_filter = () =>
+                                            {
+                                                result.should_not_be_null();
+                                                result.should_be_an_instance_of<InterceptingFilter>();
+                                            };
+
+            static ISpecification<IInvocation> condition;
+            static IInterceptor result;
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/proxy_configuration/InterceptingFilterSpecs.cs
@@ -1,5 +1,3 @@
-using System.Security.Principal;
-using System.Threading;
 using Castle.Core.Interceptor;
 using developwithpassion.bdd.contexts;
 using Gorilla.Commons.Testing;
@@ -9,49 +7,41 @@ namespace MoMoney.boot.container.registration.proxy_configuration
 {
     public class InterceptingFilterSpecs
     {
-    }
+        public class when_intercepting_a_call : concerns_for<IInterceptor, InterceptingFilter>
+        {
+            context c = () => { condition = the_dependency<ISpecification<IInvocation>>(); };
 
-    public abstract class when_attempting_to_perform_an_action_that_requires_authentication :
-        concerns_for< SecuringProxy>
-    {
-        context c = () => { filter = the_dependency<ISpecification<IPrincipal>>(); };
+            static protected ISpecification<IInvocation> condition;
+        }
 
-        static protected ISpecification<IPrincipal> filter;
-    }
+        public class when_a_condition_is_not_met : when_intercepting_a_call
+        {
+            context c = () =>
+                            {
+                                invocation = an<IInvocation>();
+                                when_the(condition).is_told_to(x => x.is_satisfied_by(invocation)).it_will_return(false);
+                            };
 
-    public class when_logged_in_as_a_user_that_belongs_to_the_proper_role :
-        when_attempting_to_perform_an_action_that_requires_authentication
-    {
-        context c = () =>
-                        {
-                            invocation = an<IInvocation>();
-                            when_the(filter)
-                                .is_told_to(x => x.is_satisfied_by(Thread.CurrentPrincipal))
-                                .it_will_return(true);
-                        };
+            because b = () => sut.Intercept(invocation);
 
-        because b = () => sut.Intercept(invocation);
+            it should_not_forward_the_call_to_the_target = () => invocation.was_not_told_to(x => x.Proceed());
 
-        it should_proceed_with_request = () => invocation.was_told_to(x => x.Proceed());
+            static IInvocation invocation;
+        }
 
-        static IInvocation invocation;
-    }
-
-    public class when_not_logged_in_as_a_user_that_belongs_to_the_proper_role :
-        when_attempting_to_perform_an_action_that_requires_authentication
-    {
-        context c = () =>
-                        {
-                            invocation = an<IInvocation>();
-                            when_the(filter)
-                                .is_told_to(x => x.is_satisfied_by(Thread.CurrentPrincipal))
-                                .it_will_return(false);
-                        };
+        public class when_a_condition_is_met : when_intercepting_a_call
+        {
+            context c = () =>
+                            {
+                                invocation = an<IInvocation>();
+                                when_the(condition).is_told_to(x => x.is_satisfied_by(invocation)).it_will_return(true);
+                            };
 
-        because b = () => sut.Intercept(invocation);
+            because b = () => sut.Intercept(invocation);
 
-        it should_not_proceed_with_request = () => invocation.was_not_told_to(x => x.Proceed());
+            it should_forward_the_call_to_the_target = () => invocation.was_told_to(x => x.Proceed());
 
-        static IInvocation invocation;
+            static IInvocation invocation;
+        }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/proxy_configuration/SecuringProxySpecs.cs
@@ -0,0 +1,57 @@
+using System.Security.Principal;
+using System.Threading;
+using Castle.Core.Interceptor;
+using developwithpassion.bdd.contexts;
+using Gorilla.Commons.Testing;
+using Gorilla.Commons.Utility.Core;
+
+namespace MoMoney.boot.container.registration.proxy_configuration
+{
+    public class SecuringProxySpecs
+    {
+    }
+
+    public class when_attempting_to_perform_an_action_that_requires_authentication :
+        concerns_for< SecuringProxy>
+    {
+        context c = () => { filter = the_dependency<ISpecification<IPrincipal>>(); };
+
+        static protected ISpecification<IPrincipal> filter;
+    }
+
+    public class when_logged_in_as_a_user_that_belongs_to_the_proper_role :
+        when_attempting_to_perform_an_action_that_requires_authentication
+    {
+        context c = () =>
+                        {
+                            invocation = an<IInvocation>();
+                            when_the(filter)
+                                .is_told_to(x => x.is_satisfied_by(Thread.CurrentPrincipal))
+                                .it_will_return(true);
+                        };
+
+        because b = () => sut.Intercept(invocation);
+
+        it should_proceed_with_request = () => invocation.was_told_to(x => x.Proceed());
+
+        static IInvocation invocation;
+    }
+
+    public class when_not_logged_in_as_a_user_that_belongs_to_the_proper_role :
+        when_attempting_to_perform_an_action_that_requires_authentication
+    {
+        context c = () =>
+                        {
+                            invocation = an<IInvocation>();
+                            when_the(filter)
+                                .is_told_to(x => x.is_satisfied_by(Thread.CurrentPrincipal))
+                                .it_will_return(false);
+                        };
+
+        because b = () => sut.Intercept(invocation);
+
+        it should_not_proceed_with_request = () => invocation.was_not_told_to(x => x.Proceed());
+
+        static IInvocation invocation;
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -142,9 +142,13 @@
     <Compile Include="boot\container\registration\mapping\PropertyResolutionException.cs" />
     <Compile Include="boot\container\registration\mapping\PropertyResolver.cs" />
     <Compile Include="boot\container\registration\mapping\TargetActionFactory.cs" />
+    <Compile Include="boot\container\registration\proxy_configuration\InterceptingFilter.cs" />
+    <Compile Include="boot\container\registration\proxy_configuration\InterceptingFilterFactory.cs" />
+    <Compile Include="boot\container\registration\proxy_configuration\InterceptingFilterFactorySpecs.cs" />
+    <Compile Include="boot\container\registration\proxy_configuration\InterceptingFilterSpecs.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\NoConfiguration.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\SecuringProxy.cs" />
-    <Compile Include="boot\container\registration\proxy_configuration\InterceptingFilterSpecs.cs" />
+    <Compile Include="boot\container\registration\proxy_configuration\SecuringProxySpecs.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\ServiceLayerConfiguration.cs" />
     <Compile Include="boot\container\registration\proxy_configuration\SynchronizedConfiguration.cs" />
     <Compile Include="boot\container\registration\wire_up_the_infrastructure_in_to_the.cs" />