User: xtoff
Date: 2009/11/14 02:21 PM

Added:
 /DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
  ChangeProxyTargetInterceptor.cs

Modified:
 /DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
  Castle.DynamicProxy.Tests-vs2008.csproj, 
InterfaceProxyWithTargetInterfaceTestCase.cs

Log:
 - added some tests for recently added functionality

File Changes:

Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
=============================================================

File [modified]: Castle.DynamicProxy.Tests-vs2008.csproj
Delta lines: +38 -0
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/ChangeProxyTargetInterceptor.cs
                            (rev 0)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/ChangeProxyTargetInterceptor.cs
    2009-11-14 21:21:55 UTC (rev 6328)
@@ -0,0 +1,38 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.DynamicProxy.Tests
+{
+       using Castle.Core.Interceptor;
+
+       using NUnit.Framework;
+
+       public class ChangeProxyTargetInterceptor : IInterceptor
+       {
+               private readonly object target;
+
+               public ChangeProxyTargetInterceptor(object target)
+               {
+                       this.target = target;
+               }
+
+               public void Intercept(IInvocation invocation)
+               {
+                       var change = invocation as IChangeProxyTarget;
+                       Assert.IsNotNull(change);
+                       change.ChangeProxyTarget(target);
+                       invocation.Proceed();
+               }
+       }
+}

File [added]: ChangeProxyTargetInterceptor.cs
Delta lines: +31 -0
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/InterfaceProxyWithTargetInterfaceTestCase.cs
       2009-11-14 19:12:50 UTC (rev 6327)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/InterfaceProxyWithTargetInterfaceTestCase.cs
       2009-11-14 21:21:55 UTC (rev 6328)
@@ -100,5 +100,36 @@
 
                        (proxy as ITwo).TwoMethod());
                }
+
+               [Test]
+               public void 
ChangeProxyTarget_should_change_proxy_target_permanently()
+               {
+                       var interceptor = new ChangeProxyTargetInterceptor(new 
OneTwo());
+                       var proxy = 
generator.CreateInterfaceProxyWithTargetInterface<IOne>(new One(), interceptor);
+                       
+                       proxy.OneMethod();
+
+                       var type = GetTargetType(proxy);
+                       Assert.AreEqual(typeof(OneTwo), type);
+               }
+
+               [Test]
+               public void 
ChangeProxyTarget_should_not_affect_invocation_target()
+               {
+                       var first = new ChangeProxyTargetInterceptor(new 
OneTwo());
+                       var second = new KeepDataInterceptor();
+                       var proxy = 
generator.CreateInterfaceProxyWithTargetInterface<IOne>(new One(),
+                                                                               
            first,
+                                                                               
            second);
+
+                       proxy.OneMethod();
+
+                       Assert.AreEqual(typeof(One), 
second.Invocation.InvocationTarget.GetType());
+               }
+
+               private Type GetTargetType(object proxy)
+               {
+                       return (proxy as 
IProxyTargetAccessor).DynProxyGetTarget().GetType();
+               }
        }

File [modified]: InterfaceProxyWithTargetInterfaceTestCase.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=.


Reply via email to