User: xtoff
Date: 2010/01/24 01:07 PM

Modified:
 /DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
  BasicClassProxyTestCase.cs, BasicInterfaceProxyWithoutTargetTestCase.cs, 
BugsReportedTestCase.cs
 /DynamicProxy/trunk/src/Castle.DynamicProxy/
  AbstractInvocation.cs, CompositionInvocation.cs, InheritanceInvocation.cs
 /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
  BaseProxyGenerator.cs, InterfaceInvocationTypeGenerator.cs, 
InvocationTypeGenerator.cs
 /DynamicProxy/trunk/src/Castle.DynamicProxy/Tokens/
  InvocationMethods.cs

Log:
 - unified and extended exception messages being thrown when proceed is called 
on a method without target.

File Changes:

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

File [modified]: AbstractInvocation.cs
Delta lines: +7 -9
===================================================================

--- DynamicProxy/trunk/src/Castle.DynamicProxy/CompositionInvocation.cs 
2010-01-24 18:11:14 UTC (rev 6712)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/CompositionInvocation.cs 
2010-01-24 20:07:04 UTC (rev 6713)
@@ -53,28 +53,25 @@
                        {
                                return null;
                        }
+
                        return targetObject.GetType();
                }
 
                protected void EnsureValidTarget()
                {
-                       string message;
                        if (target == null)
                        {
-                               message = "This is a DynamicProxy2 error: the 
interceptor attempted " +
-                                         "to 'Proceed' for method '" + 
Method.ToString() + "' which has no target." +
-                                         " When calling method without target 
there is no implementation to 'proceed' to " +
-                                         "and it is the responsibility of the 
interceptor to mimic the implementation (set return value, out arguments etc)";
-                               throw new NotImplementedException(message);
+                               ThrowOnNoTarget();
                        }
 
                        if (!ReferenceEquals(target, proxyObject))
                        {
                                return;
                        }
-                       message = "This is a DynamicProxy2 error: target of 
invocation has been set to the proxy itself. " +
-                                 "This may result in recursively calling the 
method over and over again until stack overflow, which may destabilize your 
program." +
-                                 "This usually signifies a bug in the calling 
code. Make sure no interceptor sets proxy as its invocation target.";
+
+                       string message = "This is a DynamicProxy2 error: target 
of invocation has been set to the proxy itself. " +
+                                        "This may result in recursively 
calling the method over and over again until stack overflow, which may 
destabilize your program." +
+                                        "This usually signifies a bug in the 
calling code. Make sure no interceptor sets proxy as its invocation target.";
                        throw new InvalidOperationException(message);
                }
 
@@ -89,6 +86,7 @@
                        {
                                return;
                        }
+
                        var message = "This is a DynamicProxy2 error: target of 
proxy has been set to the proxy itself. " +
                                                  "This would result in 
recursively calling proxy methods over and over again until stack overflow, 
which may destabilize your program." +

File [modified]: CompositionInvocation.cs
Delta lines: +1 -1
===================================================================

--- DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/BaseProxyGenerator.cs 
2010-01-24 18:11:14 UTC (rev 6712)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/BaseProxyGenerator.cs 
2010-01-24 20:07:04 UTC (rev 6713)
@@ -319,7 +319,7 @@
                        mapping.Add(@interface, implementer);
                }
 
-               protected void AddMappingForISerializable(IDictionary<Type, 
ITypeContributor> typeImplementerMapping, ProxyInstanceContributor instance)
+               protected void AddMappingForISerializable(IDictionary<Type, 
ITypeContributor> typeImplementerMapping, ITypeContributor instance)
                {
 #if SILVERLIGHT

File [modified]: InheritanceInvocation.cs
Delta lines: +3 -1
===================================================================

--- DynamicProxy/trunk/src/Castle.DynamicProxy/Tokens/InvocationMethods.cs      
2010-01-24 18:11:14 UTC (rev 6712)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Tokens/InvocationMethods.cs      
2010-01-24 20:07:04 UTC (rev 6713)
@@ -35,10 +35,12 @@
                public static readonly MethodInfo GetArgumentValue =
                        
typeof(AbstractInvocation).GetMethod("GetArgumentValue");
 
-
                public static readonly MethodInfo GetReturnValue =
                        typeof(AbstractInvocation).GetMethod("get_ReturnValue");
 
+               public static readonly MethodInfo ThrowOnNoTarget =
+                       typeof(AbstractInvocation).GetMethod("ThrowOnNoTarget", 
BindingFlags.Instance | BindingFlags.NonPublic);
+
                public static readonly MethodInfo SetArgumentValue =
                        
typeof(AbstractInvocation).GetMethod("SetArgumentValue");

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

File [modified]: BasicClassProxyTestCase.cs
Delta lines: +1 -1
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/BasicInterfaceProxyWithoutTargetTestCase.cs
        2010-01-24 18:11:14 UTC (rev 6712)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/BasicInterfaceProxyWithoutTargetTestCase.cs
        2010-01-24 20:07:04 UTC (rev 6713)
@@ -36,7 +36,7 @@
                 service.Sum(1, 2));
 
                Assert.AreEqual(
-                       "This is a DynamicProxy2 error: the interceptor 
attempted to 'Proceed' for method 'Int32 Sum(Int32, Int32)' which has no 
target. " +
+                               "This is a DynamicProxy2 error: The interceptor 
attempted to 'Proceed' for method 'Int32 Sum(Int32, Int32)' which has no 
target. " +
                        "When calling method without target there is no 
implementation to 'proceed' to and it is the responsibility of the interceptor 
" +
                        "to mimic the implementation (set return value, out 
arguments etc)",

File [modified]: BasicInterfaceProxyWithoutTargetTestCase.cs
Delta lines: +29 -12
===================================================================

--- DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/BugsReportedTestCase.cs    
2010-01-24 18:11:14 UTC (rev 6712)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/BugsReportedTestCase.cs    
2010-01-24 20:07:04 UTC (rev 6713)
@@ -52,28 +52,45 @@
                }
 
                [Test]
-               [ExpectedException(typeof (NotImplementedException),
-                       ExpectedMessage =
-                               "This is a DynamicProxy2 error: the interceptor 
attempted to 'Proceed' for a method without a target, for example, an interface 
method or an abstract method"
-                       )]
-               public void CallingProceedOnAbstractMethodShouldThrowException()
+               public void 
CallingProceedWithInterceptorOnAbstractMethodShouldThrowException()
                {
-                       AbstractClass proxy = (AbstractClass)
-                                             generator.CreateClassProxy(typeof 
(AbstractClass), ProxyGenerationOptions.Default,
-                                                                        new 
StandardInterceptor());
+                       var proxy = 
generator.CreateClassProxy<AbstractClass>(ProxyGenerationOptions.Default, new 
StandardInterceptor());
+                       Assert.IsNotNull(proxy);
 
+                       TestDelegate callProxyMethod = ()=>
+                       proxy.Foo();
+
+                       var message =
+                               "This is a DynamicProxy2 error: The interceptor 
attempted to 'Proceed' for method 'System.String Foo()' which is abstract. " +
+                               "When calling an abstract method there is no 
implementation to 'proceed' to " +
+                               "and it is the responsibility of the 
interceptor to mimic the implementation (set return value, out arguments etc)";
+                       var exception =
+                       Assert.Throws(typeof(NotImplementedException), 
callProxyMethod);
+                       Assert.AreEqual(message, exception.Message);
+               }
+
+               [Test]
+               public void 
CallingProceedWithoutInterceptorOnAbstractMethodShouldThrowException()
+               {
+                       var proxy = generator.CreateClassProxy<AbstractClass>();
                        Assert.IsNotNull(proxy);
 
+                       TestDelegate callProxyMethod = () =>
                        proxy.Foo();
+
+                       var message =
+                               "This is a DynamicProxy2 error: There are no 
interceptors specified for method 'System.String Foo()' which is abstract. " +
+                               "When calling an abstract method there is no 
implementation to 'proceed' to " +
+                               "and it is the responsibility of the 
interceptor to mimic the implementation (set return value, out arguments etc)";
+                       var exception =
+                       Assert.Throws(typeof(NotImplementedException), 
callProxyMethod);
+                       Assert.AreEqual(message, exception.Message);
                }
 
                [Test]
                public void ProxyTypeThatInheritFromGenericType()
                {
-                       IUserRepository proxy = (IUserRepository)
-                                               
generator.CreateInterfaceProxyWithoutTarget(typeof (IUserRepository),
-                                                                               
 new DoNothingInterceptor());
-
+                       var proxy = 
generator.CreateInterfaceProxyWithoutTarget<IUserRepository>(new 
DoNothingInterceptor());
                        Assert.IsNotNull(proxy);
                }

File [modified]: BugsReportedTestCase.cs
Delta lines: +0 -0
===================================================================

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

File [modified]: BaseProxyGenerator.cs
Delta lines: +1 -0
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceInvocationTypeGenerator.cs
   2010-01-24 18:11:14 UTC (rev 6712)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceInvocationTypeGenerator.cs
   2010-01-24 20:07:04 UTC (rev 6713)
@@ -64,6 +64,7 @@
                                        new ArgumentReference(typeof(object[])),
                                };
                        }
+
                        baseConstructor = 
InvocationMethods.CompositionInvocationConstructorWithSelector;
                        return new[]

File [modified]: InterfaceInvocationTypeGenerator.cs
Delta lines: +3 -6
===================================================================

--- 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InvocationTypeGenerator.cs
    2010-01-24 18:11:14 UTC (rev 6712)
+++ 
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InvocationTypeGenerator.cs
    2010-01-24 20:07:04 UTC (rev 6713)
@@ -235,13 +235,10 @@
 
                protected void 
CreateEmptyIInvocationInvokeOnTarget(AbstractTypeEmitter nested)
                {
-                       MethodEmitter invokeMethodOnTarget = 
nested.CreateMethod("InvokeMethodOnTarget");
+                       var invokeMethodOnTarget = 
nested.CreateMethod("InvokeMethodOnTarget");
+                       var throwOnNoTarget = new ExpressionStatement(new 
MethodInvocationExpression(InvocationMethods.ThrowOnNoTarget));
 
-                       String message = "This is a DynamicProxy2 error: the 
interceptor attempted " +
-                                                        "to 'Proceed' for a 
method without a target, for example, an interface method or an abstract 
method";
-
-                       invokeMethodOnTarget.CodeBuilder.AddStatement(new 
ThrowStatement(typeof(NotImplementedException), message));
-
+                       
invokeMethodOnTarget.CodeBuilder.AddStatement(throwOnNoTarget);
                        invokeMethodOnTarget.CodeBuilder.AddStatement(new 
ReturnStatement());
                }

File [modified]: InvocationTypeGenerator.cs
Delta lines: +5 -5
===================================================================

--- DynamicProxy/trunk/src/Castle.DynamicProxy/InheritanceInvocation.cs 
2010-01-24 18:11:14 UTC (rev 6712)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/InheritanceInvocation.cs 
2010-01-24 20:07:04 UTC (rev 6713)
@@ -21,11 +21,6 @@
 
        public abstract class InheritanceInvocation : AbstractInvocation
        {
-               public override object InvocationTarget
-               {
-                       get { return Proxy; }
-               }
-
                private readonly Type targetType;
 
                protected InheritanceInvocation(
@@ -52,6 +47,11 @@
                        this.targetType = targetType;
                }
 
+               public override object InvocationTarget
+               {
+                       get { return Proxy; }
+               }
+
                public override Type TargetType
                {

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

File [modified]: InvocationMethods.cs
Delta lines: +1 -1
===================================================================

--- DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/BasicClassProxyTestCase.cs 
2010-01-24 18:11:14 UTC (rev 6712)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/BasicClassProxyTestCase.cs 
2010-01-24 20:07:04 UTC (rev 6713)
@@ -215,7 +215,7 @@
                        catch (NotImplementedException ex)
                        {
                                Assert.AreEqual(
-                                       "This is a DynamicProxy2 error: the 
interceptor attempted to 'Proceed' for method 'Void Dispose()' which has no 
target. " +
+                                       "This is a DynamicProxy2 error: The 
interceptor attempted to 'Proceed' for method 'Void Dispose()' which has no 
target. " +
                                        "When calling method without target 
there is no implementation to 'proceed' to and it is the responsibility of the 
interceptor " +
                                        "to mimic the implementation (set 
return value, out arguments etc)",

-- 
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.

Reply via email to