User: xtoff
Date: 2009/10/31 04:47 PM
Modified:
/DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
InterfaceProxyBaseTypeTestCase.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
InterfaceProxyWithTargetGenerator.cs
Log:
- Fixed DYNPROXY-ISSUE-117 - Fix BaseTypeForInterfaceProxy. Added checks for
base type being null, not a class type, being sealed and not having default
accessible constructor. Should be more than enough... I guess barely anyone
uses it anyway.
File Changes:
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
=============================================================
File [modified]: InterfaceProxyBaseTypeTestCase.cs
Delta lines: +0 -0
===================================================================
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
==================================================================
File [modified]: InterfaceProxyWithTargetGenerator.cs
Delta lines: +103 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/InterfaceProxyBaseTypeTestCase.cs
2009-10-31 22:31:23 UTC (rev 6297)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/InterfaceProxyBaseTypeTestCase.cs
2009-10-31 23:47:28 UTC (rev 6298)
@@ -14,11 +14,113 @@
namespace Castle.DynamicProxy.Tests
{
+ using System;
+
+ using Castle.DynamicProxy.Tests.Classes;
+
using NUnit.Framework;
[TestFixture]
public class InterfaceProxyBaseTypeTestCase:BasePEVerifyTestCase
{
- //TODO: implement me
+ [Test]
+ public void Sealed_class_as_base_type()
+ {
+ var exception =
Assert.Throws(typeof(ArgumentException), () =>
+
generator.CreateInterfaceProxyWithoutTarget(typeof(ISimpleInterface),
+
Type.EmptyTypes,
+
WithBase<Sealed>()));
+ Assert.AreEqual(
+ string.Format(
+ "Type {0} is not valid base type for
interface proxy, because it is sealed. " +
+ "Only a non-sealed class with
non-private default constructor can be used as base type for interface proxy. "
+
+ "Please use some other valid type.",
+ typeof(Sealed)), exception.Message);
+ }
+
+ [Test]
+ public void Interface_as_base_type()
+ {
+ var exception =
Assert.Throws(typeof(ArgumentException), () =>
+
generator.CreateInterfaceProxyWithoutTarget(typeof(ISimpleInterface),
+
Type.EmptyTypes,
+
WithBase<ISomething>()));
+ Assert.AreEqual(
+ string.Format(
+ "Type {0} is not valid base type for
interface proxy, because it is not a class type. " +
+ "Only a non-sealed class with
non-private default constructor can be used as base type for interface proxy. "
+
+ "Please use some other valid type.",
+ typeof(ISomething)), exception.Message);
+ }
+
+ [Test]
+ public void Class_with_no_default_ctor_as_base_type()
+ {
+ var exception =
Assert.Throws(typeof(ArgumentException), () =>
+
generator.CreateInterfaceProxyWithoutTarget(typeof(ISimpleInterface),
+
Type.EmptyTypes,
+
WithBase<NoDefaultCtor>()));
+ Assert.AreEqual(
+ string.Format(
+ "Type {0} is not valid base type for
interface proxy, because it does not have accessible parameterless constructor.
" +
+ "Only a non-sealed class with
non-private default constructor can be used as base type for interface proxy. "
+
+ "Please use some other valid type.",
+ typeof(NoDefaultCtor)),
exception.Message);
+ }
+
+ [Test]
+ public void Class_with_private_default_ctor_as_base_type()
+ {
+ var exception =
Assert.Throws(typeof(ArgumentException), () =>
+
generator.CreateInterfaceProxyWithoutTarget(typeof(ISimpleInterface),
+
Type.EmptyTypes,
+
WithBase<DefaultPrivateCtor>()));
+ Assert.AreEqual(
+ string.Format(
+ "Type {0} is not valid base type for
interface proxy, because it does not have accessible parameterless constructor.
" +
+ "Only a non-sealed class with
non-private default constructor can be used as base type for interface proxy. "
+
+ "Please use some other valid type.",
+ typeof(DefaultPrivateCtor)),
exception.Message);
+ }
+
+ [Test]
+ public void Same_Class_as_base_and_target_works_fine()
+ {
+ var @interface =
generator.CreateInterfaceProxyWithTarget(typeof(ISimpleInterface),
+
new ClassWithInterface(),
+
WithBase<ClassWithInterface>()) as ISimpleInterface;
+ @interface.Do();
+ }
+ [Test]
+ public void
Class_with_protected_default_ctor_as_base_type_is_fine()
+ {
+ var @interface =
generator.CreateInterfaceProxyWithTargetInterface(typeof(ISimpleInterface),
+
new
ClassWithInterface(),
+
WithBase<DefaultProtectedCtor>()) as ISimpleInterface;
+ @interface.Do();
+ }
+
+ private ProxyGenerationOptions WithBase<T>()
+ {
+ return new ProxyGenerationOptions() {
BaseTypeForInterfaceProxy = typeof(T) };
+ }
}
+
+ public sealed class Sealed{}
+
+ public class NoDefaultCtor
+ {
+ public NoDefaultCtor(string someParam){}
+ }
+
+ public class DefaultProtectedCtor
+ {
+ protected DefaultProtectedCtor() { }
+ }
+
+ public class DefaultPrivateCtor
+ {
+ private DefaultPrivateCtor() { }
+ }
+
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---