Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Proxy
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv3108
Modified Files:
AbstractProxyTypeBuilderTests.cs
Log Message:
Problems with Attributes in proxy generation [SPRNET-606]
Index: AbstractProxyTypeBuilderTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Proxy/AbstractProxyTypeBuilderTests.cs,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** AbstractProxyTypeBuilderTests.cs 3 Dec 2007 09:07:54 -0000 1.18
--- AbstractProxyTypeBuilderTests.cs 3 Dec 2007 23:31:38 -0000 1.19
***************
*** 22,25 ****
--- 22,27 ----
using System;
+ using System.Net;
+ using System.Security.Permissions;
using System.Reflection;
using System.Reflection.Emit;
***************
*** 209,212 ****
--- 211,239 ----
}
+ // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=296032
+ // should not fail
+ // Not fixed by .NET 2.0 SP1.
+ [Test]
+ public void ProxySpecificTargetTypeAttributeWithPublicEnumProperty()
+ {
+ IProxyTypeBuilder builder = GetProxyBuilder();
+ builder.TargetType = typeof(ClassWithPublicEnumPropertyAttribute);
+ Type proxy = builder.BuildProxyType();
+ Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null.");
+ MethodInfo method = proxy.GetMethod("Spring.Proxy.ISomeMarkerInterface.MarkerMethod", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (method == null)
+ {
+ method = proxy.GetMethod("MarkerMethod");
+ }
+ Assert.IsNotNull(method);
+ object[] attrs = method.GetCustomAttributes(false);
+ Assert.IsNotNull(attrs, "Should have 1 attribute applied to the target method.");
+ Assert.AreEqual(1, attrs.Length, "Should have 1 attribute applied to the target method.");
+ Assert.AreEqual(typeof(PublicEnumPropertyAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the target method.");
+
+ PublicEnumPropertyAttribute pepa = attrs[0] as PublicEnumPropertyAttribute;
+ Assert.AreEqual(AttributeTargets.All, pepa.Data);
+ }
+
// http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=161522
// should not fail
***************
*** 232,235 ****
--- 259,332 ----
}
+ // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94803
+ [Test]
+ [Ignore("http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94803")]
+ public void ProxySecurityAttribute()
+ {
+ IProxyTypeBuilder builder = GetProxyBuilder();
+ builder.TargetType = typeof(ClassWithSecurityAttribute);
+
+ Type proxy = builder.BuildProxyType();
+ Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null.");
+
+ object[] attrs = proxy.GetCustomAttributes(false);
+ Assert.IsNotNull(attrs, "Should have had 2 attribute applied to the target type.");
+ Assert.AreEqual(2, attrs.Length, "Should have had 2 attribute applied to the target type.");
+ Assert.AreEqual(typeof(WebPermissionAttribute), attrs[1].GetType(), "Wrong System.Type of Attribute applied to the target type.");
+
+ WebPermissionAttribute wpa = attrs[0] as WebPermissionAttribute;
+ Assert.AreEqual(SecurityAction.Deny, wpa.Action);
+ }
+
+ [Test]
+ public void ProxySpecificTargetTypeAttributeWithArrayConstructor()
+ {
+ IProxyTypeBuilder builder = GetProxyBuilder();
+ builder.TargetType = typeof(ClassWithArrayConstructorAttribute);
+ Type proxy = builder.BuildProxyType();
+ Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null.");
+
+ MethodInfo method = proxy.GetMethod("Spring.Proxy.ISomeMarkerInterface.MarkerMethod", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (method == null)
+ {
+ method = proxy.GetMethod("MarkerMethod");
+ }
+ Assert.IsNotNull(method);
+ object[] attrs = method.GetCustomAttributes(false);
+ Assert.IsNotNull(attrs, "Should have 1 attribute applied to the target method.");
+ Assert.AreEqual(1, attrs.Length, "Should have 1 attribute applied to the target method.");
+ Assert.AreEqual(typeof(ArrayConstructorPropertyAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the target method.");
+
+ ArrayConstructorPropertyAttribute acpa = attrs[0] as ArrayConstructorPropertyAttribute;
+ Assert.AreEqual(false, acpa.ReadOnly);
+ Assert.AreEqual(1, acpa.Types.Length);
+ Assert.AreEqual(typeof(string), acpa.Types[0]);
+ }
+
+ [Test]
+ public void ProxySpecificTargetTypeAttributeWithArrayProperty()
+ {
+ IProxyTypeBuilder builder = GetProxyBuilder();
+ builder.TargetType = typeof(ClassWithArrayPropertyAttribute);
+ Type proxy = builder.BuildProxyType();
+ Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null.");
+
+ MethodInfo method = proxy.GetMethod("Spring.Proxy.IAnotherMarkerInterface.MarkerMethod", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (method == null)
+ {
+ method = proxy.GetMethod("MarkerMethod");
+ }
+ Assert.IsNotNull(method);
+ object[] attrs = method.GetCustomAttributes(false);
+ Assert.IsNotNull(attrs, "Should have 1 attribute applied to the target method.");
+ Assert.AreEqual(1, attrs.Length, "Should have 1 attribute applied to the target method.");
+ Assert.AreEqual(typeof(ArrayConstructorPropertyAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the target method.");
+
+ ArrayConstructorPropertyAttribute acpa = attrs[0] as ArrayConstructorPropertyAttribute;
+ Assert.AreEqual(true, acpa.ReadOnly);
+ Assert.AreEqual(2, acpa.Types.Length);
+ Assert.AreEqual(typeof(int), acpa.Types[0]);
+ Assert.AreEqual(typeof(string), acpa.Types[1]);
+ }
[Test]
***************
*** 637,640 ****
--- 734,771 ----
}
+ // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=296032
+ public class ClassWithPublicEnumPropertyAttribute : ISomeMarkerInterface
+ {
+ [PublicEnumProperty(AttributeTargets.All)]
+ public string MarkerMethod(int param1, string param2)
+ {
+ return null;
+ }
+ }
+
+ // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94803
+ [Marker]
+ [WebPermission(SecurityAction.Deny)]
+ public class ClassWithSecurityAttribute : IMarkerInterface
+ {
+ }
+
+ public class ClassWithArrayConstructorAttribute : ISomeMarkerInterface
+ {
+ [ArrayConstructorPropertyAttribute(false, new Type[1] { typeof(string) })]
+ public string MarkerMethod(int param1, string param2)
+ {
+ return null;
+ }
+ }
+
+ public class ClassWithArrayPropertyAttribute : IAnotherMarkerInterface
+ {
+ [ArrayConstructorPropertyAttribute(ReadOnly = true, Types = new Type[2] { typeof(int), typeof(string) })]
+ public void MarkerMethod()
+ {
+ }
+ }
+
public class SomeMarkerClass : ISomeMarkerInterface
{
***************
*** 666,669 ****
--- 797,848 ----
}
+ public class ArrayConstructorPropertyAttribute : Attribute
+ {
+ private bool _readOnly = false;
+ private Type[] _types = Type.EmptyTypes;
+
+ public ArrayConstructorPropertyAttribute()
+ {
+ }
+
+ public ArrayConstructorPropertyAttribute(bool readOnly, Type[] types)
+ {
+ this._readOnly = readOnly;
+ this._types = types;
+ }
+
+ public bool ReadOnly
+ {
+ get { return _readOnly; }
+ set { _readOnly = value; }
+ }
+
+ public Type[] Types
+ {
+ get { return _types; }
+ set { _types = value; }
+ }
+ }
+
+ public class PublicEnumPropertyAttribute : Attribute
+ {
+ private Enum _data;
+
+ public PublicEnumPropertyAttribute(AttributeTargets data)
+ {
+ _data = data;
+ }
+
+ public PublicEnumPropertyAttribute(TypeCode data)
+ {
+ _data = data;
+ }
+
+ public Enum Data
+ {
+ get { return _data; }
+ }
+ }
+
public sealed class MarkerAttribute : Attribute
{
|