Fixed.
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / CustomAttributeBuilderTest.cs
index 88de598e2dcd56382a5e1518c38017301777507b..175e0bdc3b562d4fec9832135da5a011a5ace3f0 100644 (file)
-// CustomAttributeBuilderTest.cs\r
-//\r
-// Author: Vineeth N <nvineeth@yahoo.com>\r
-//\r
-// (C) 2004 Ximian, Inc. http://www.ximian.com\r
-//\r
-using System;\r
-using System.Reflection;\r
-using System.Reflection.Emit;\r
-using System.Threading;\r
-using NUnit.Framework;\r
-\r
-namespace MonoTests.System.Reflection.Emit\r
-{\r
-       /// <summary>\r
-       /// TestFixture for CustomAttributeBuilderTest.\r
-       /// The members to be tested are as follows:\r
-       /// 4 constructors:\r
-       /// 1) public CustomAttributeBuilder(ConstructorInfo, object[]);\r
-       /// 2) public CustomAttributeBuilder(ConstructorInfo, object[], FieldInfo[], object[]);\r
-       /// 3) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[]);\r
-       /// 4) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);\r
-       /// and the exceptions that are thrown.\r
-       /// In the implementation , it can be seen that the first\r
-       /// three type of  constructors call the 4th type of ctor, which takes 6 args\r
-       /// by filling args and substituting null as required.\r
-       /// For testing constructors we have use 4 different test functions,\r
-       /// Various exceptions have been checked for 4th type of consturctor.\r
-       /// </summary>\r
-\r
-       [TestFixture]\r
-       public class CustomAttributeBuilderTest : Assertion\r
-       {\r
-               \r
-               // the CustomAttribute class is used for testing and it has to be public\r
-               //since it will be associated with a class that belongs to another assembly \r
-\r
-               [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Class)]\r
-               public class CustomAttribute: Attribute\r
-               {\r
-                       private string attr1;\r
-                       private string attr2;\r
-                       public string Feild; //used for testing the second type of constructor\r
-\r
-                       public CustomAttribute () {}\r
-                       public CustomAttribute (String s1 , String s2)\r
-                       {\r
-                               attr1 = s1;\r
-                               attr2=s2;\r
-                        }\r
-\r
-                       private CustomAttribute (String s1) {}\r
-                       static CustomAttribute () {}\r
-\r
-                       public string AttributeOne\r
-                       {\r
-                               get { return attr1; }\r
-                               set { attr1 = value; }\r
-                       }\r
-                       \r
-                       public string AttributeTwo\r
-                       {\r
-                               get { return attr2; }\r
-                               //the set is skipped and is used later in testing\r
-                       }\r
-\r
-               }\r
-               \r
-               private class TempClass\r
-               {\r
-                       //used for testing the ArgumentException\r
-                       public string Field;\r
-                       public string FieldProperty\r
-                       {\r
-                               get { return Field; }\r
-                               set { Field = value; }\r
-                       }\r
-               }\r
-\r
-               \r
-\r
-               \r
-               [Test]\r
-               public void CtorOneTest ()\r
-               {\r
-                       //test for the constructor with signature--\r
-                       // public CustomAttributeBuilder(ConstructorInfo, object[]);\r
-                       /*\r
-                        * WE build a imaginary type as follows\r
-                        * class TestType\r
-                        * {\r
-                        *      [CustomAttribute("one","two")]\r
-                        *      public string Str;\r
-                        * \r
-                        *      [CustomAttribute("hello","world")]\r
-                        *      public void Print()\r
-                        *      {Console.WriteLine("Hello World"); }\r
-                        * \r
-                        * }\r
-                        * And then check for the validity of attributes in the test functions\r
-                        */\r
-                       AssemblyName asmName = new AssemblyName ();\r
-                       asmName.Name = "TestAssembly.dll";\r
-\r
-                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
-                               asmName , AssemblyBuilderAccess.Run);\r
-                       \r
-                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
-                       \r
-                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
-                               TypeAttributes.Public);\r
-\r
-                       Type[] ctorParams = new Type[] { typeof (string),typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder feildCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "one","two" }\r
-                               ),\r
-                               methodCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "hello","world" }\r
-                               );\r
-                       //now let's build a feild of type string and associate a attribute with it\r
-                       FieldBuilder fieldBuilder= typeBuilder.DefineField ("Str",\r
-                               typeof (string), FieldAttributes.Public);\r
-                       fieldBuilder.SetCustomAttribute (feildCABuilder);\r
-                       //now build a method \r
-                       MethodBuilder methodBuilder= typeBuilder.DefineMethod ("Print",\r
-                               MethodAttributes.Public, null, null);\r
-                       methodBuilder.SetCustomAttribute (methodCABuilder);\r
-                       ILGenerator methodIL = methodBuilder.GetILGenerator ();\r
-                       methodIL.EmitWriteLine ("Hello, world!");\r
-                       methodIL.Emit (OpCodes.Ret);\r
-                       \r
-                       // create the type\r
-                       Type myType = typeBuilder.CreateType ();\r
-\r
-                       //Now check for the validity of the attributes.\r
-                       object testInstance = Activator.CreateInstance (myType);\r
-\r
-                       //check the validity of the attribute associated with Print method \r
-                       \r
-                       object [] methodAttrs =  myType.GetMember ("Print") [0].GetCustomAttributes (true);\r
-                       AssertEquals ("#method Print has exactly one attribute", methodAttrs.Length, 1);\r
-                       CustomAttribute methodAttr = methodAttrs [0] as CustomAttribute;\r
-                       AssertEquals ("#AttributeOne", methodAttr.AttributeOne, "hello");\r
-                       AssertEquals ("#AttributeTwo", methodAttr.AttributeTwo, "world");\r
-                       \r
-                       //check the validity of the attribute associated with Str feild\r
-\r
-                       object [] fieldAttrs = myType.GetField ("Str").GetCustomAttributes (true);\r
-                       AssertEquals("#feild Str has exactly one attribute", fieldAttrs.Length, 1);\r
-                       CustomAttribute fieldAttr = fieldAttrs [0] as CustomAttribute;\r
-                       AssertEquals("#AttributeOne", fieldAttr.AttributeOne, "one");\r
-                       AssertEquals("#AttributeTwo", fieldAttr.AttributeTwo, "two");\r
-               }\r
-\r
-               [Test]\r
-               public void CtorTwoTest ()\r
-               {\r
-                       //test for the constructor with signature--\r
-                       // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], FieldInfo[], Object[]) ;\r
-                       /*\r
-                        * WE build a imaginary type as follows\r
-                        * [CustomAttribute("Test","Type")]\r
-                        * public class TestType\r
-                        * {\r
-                        * \r
-                        * }\r
-                        * We also set the "Feild" of class CustomAttribute and the value;\r
-                        * And then check for the validity of attributes in the test functions\r
-                        */\r
-                                                                       \r
-                       AssemblyName asmName = new AssemblyName ();\r
-                       asmName.Name = "TestAssembly.dll";\r
-\r
-                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
-                               asmName, AssemblyBuilderAccess.Run);\r
-                       \r
-                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
-                       \r
-                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
-                               TypeAttributes.Public);\r
-\r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "Test","Type" },\r
-                               typeof(CustomAttribute).GetFields(),\r
-                               new object [] { "TestCase" }\r
-                               ); \r
-                               \r
-                       typeBuilder.SetCustomAttribute (typeCABuilder);\r
-                       \r
-                       // create the type\r
-                       Type myType = typeBuilder.CreateType ();\r
-\r
-                       //Now check for the validity of the attributes.\r
-                       object testInstance = Activator.CreateInstance (myType);\r
-\r
-                       //check the validity of the attribute associated with Print method \r
-                       object [] customAttrs = myType.GetCustomAttributes (false);\r
-                       AssertEquals ("#TestType has exactly one attribute", customAttrs.Length, 1);\r
-\r
-                       //Custom Attributes of TestType\r
-                       CustomAttribute attr = customAttrs [0] as CustomAttribute;\r
-                       AssertEquals ("#AttributeOne", attr.AttributeOne, "Test");\r
-                       AssertEquals ("#AttributeTwo", attr.AttributeTwo, "Type");\r
-                       AssertEquals ("#CustomAttribute.Feild",attr.Feild, "TestCase");\r
-\r
-               }\r
-\r
-               [Test]\r
-               public void CtorThreeTest ()\r
-               {\r
-                       //test for the constructor with signature--\r
-                       // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], PropertyInfo[], Object[]) ;\r
-                       /*\r
-                        * WE build a imaginary type as follows\r
-                        * [CustomAttribute()]\r
-                        * public class TestType\r
-                        * {\r
-                        * \r
-                        * }\r
-                        * We also set the "AttributeOne" of class CustomAttribute by means of the constuctor\r
-                        * And then check for the validity of attribute state \r
-                        */\r
-                       \r
-                       AssemblyName asmName = new AssemblyName ();\r
-                       asmName.Name = "TestAssembly.dll";\r
-\r
-                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
-                               asmName, AssemblyBuilderAccess.Run);\r
-                       \r
-                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
-                       \r
-                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
-                               TypeAttributes.Public);\r
-                                                               \r
-                       Type [] ctorParams = new Type [] { };\r
-\r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" }\r
-                               ); \r
-                               \r
-                       typeBuilder.SetCustomAttribute (typeCABuilder);\r
-                       \r
-                       // create the type\r
-                       Type myType = typeBuilder.CreateType ();\r
-\r
-                       //Now check for the validity of the attributes.\r
-                       object testInstance = Activator.CreateInstance (myType);\r
-\r
-                       //check the validity of the attribute associated with Print method \r
-                       object [] customAttrs = myType.GetCustomAttributes (false);\r
-                       AssertEquals ("#TestType has exactly one attribute", customAttrs.Length , 1);\r
-\r
-                       //Custom Attributes of TestType\r
-                       CustomAttribute attr = customAttrs [0] as CustomAttribute;\r
-                       AssertEquals("#AttributeOne", attr.AttributeOne, "TestCase");\r
-               }\r
-\r
-               [Test]\r
-               public void CtorFourTest ()\r
-               {\r
-                       //test for the constructor with signature--\r
-                       //public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);\r
-                       /*\r
-                        * WE build a imaginary type as follows\r
-                        * [CustomAttribute()]\r
-                        * public class TestType\r
-                        * {\r
-                        * \r
-                        * }\r
-                        * We also set the "AttributeOne" property ,\r
-                        * and "Feild" of class CustomAttribute \r
-                        * by means of the constuctor of CustomAttributeBuilder\r
-                        * And then check for the validity \r
-                        */\r
-                                       \r
-                       AssemblyName asmName = new AssemblyName ();\r
-                       asmName.Name = "TestAssembly.dll";\r
-\r
-                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
-                               asmName , AssemblyBuilderAccess.Run);\r
-                       \r
-                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
-                       \r
-                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
-                               TypeAttributes.Public);\r
-               \r
-                       Type [] ctorParams = new Type [] { };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder(\r
-                               classCtorInfo,\r
-                               new object [] { },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" },\r
-                               typeof(CustomAttribute).GetFields (),\r
-                               new object [] { "FieldValue" }\r
-                               ); \r
-                               \r
-                       typeBuilder.SetCustomAttribute (typeCABuilder);\r
-                       \r
-                       // create the type\r
-                       Type myType = typeBuilder.CreateType ();\r
-\r
-                       //Now check for the validity of the attributes.\r
-                       object testInstance = Activator.CreateInstance (myType);\r
-\r
-                       //check the validity of the attribute associated with Print method \r
-                       object [] customAttrs = myType.GetCustomAttributes (false);\r
-                       AssertEquals("#TestType has exactly one attribute",customAttrs.Length , 1);\r
-\r
-                       //Custom Attributes of TestType\r
-                       CustomAttribute attr = customAttrs [0] as CustomAttribute;\r
-                       AssertEquals ("#AttributeOne", attr.AttributeOne, "TestCase");\r
-                       AssertEquals ("#Field ", attr.Feild, "FieldValue");\r
-               }\r
-       \r
-               \r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_1 ()\r
-               {\r
-                       //here the constructor is static \r
-                                       \r
-                       Type [] ctorParams = new Type [] { };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (BindingFlags.Static | BindingFlags.NonPublic,\r
-                                                null, ctorParams, null);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { },\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FieldValue" }\r
-                               );\r
-               }\r
-\r
-               \r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_2 ()\r
-               {\r
-                       //here the consturctor is private\r
-                                       \r
-                       Type [] ctorParams = new Type[] {typeof(string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (BindingFlags.Instance |\r
-                                                BindingFlags.NonPublic, null, ctorParams, null);\r
-\r
-                       Assert ("#Custom Attribute has private constuctor ", classCtorInfo != null);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "hello" },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FieldValue" }\r
-                               );\r
-               }\r
-\r
-               \r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_3 ()\r
-               {\r
-                       // The lengths of the namedProperties and \r
-                       //propertyValues arrays are different. \r
-                       \r
-                       Type [] ctorParams = new Type [] { };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { },\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase","extra arg" },//<--here is the error\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FieldValue" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_4()\r
-               {\r
-                       //The length of the namedFields and\r
-                       //namedValues are different \r
-                       \r
-                       Type [] ctorParams = new Type [] { };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { },\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { }//<--here is the error\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_5 ()\r
-               {\r
-                       //This does not throw on .NET 1.1, so manually throw\r
-                       if (Environment.Version.Major == 1 && Environment.Version.Major == 1)\r
-                               throw new ArgumentException();\r
-\r
-                       //The number of supplied arguments does not match \r
-                       //the number of parameters of the constructor as \r
-                       //required by the calling convention of the constructor\r
-                       \r
-                       Type [] ctorParams = new Type [] { };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-/*\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "extra1", "extra2" }, //<--here is the error\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FeildValue" }\r
-                               );\r
-*/\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_6 ()\r
-               {\r
-                       //The type of supplied argument does not\r
-                       //match the type of the parameter declared \r
-                       //in the constructor.\r
-                       \r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "1", 123 },//<--here is the error,(int instead of string)\r
-                               new PropertyInfo[]{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FeildValue" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_7 ()\r
-               {\r
-                       //A property has no setter.(CustomAttribute.AttributeTwo)\r
-                                               \r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "1","2" },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeTwo") },\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FeildValue" }\r
-                               ); \r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_8 ()\r
-               {\r
-                       //A property doesnot belong to same class\r
-                       \r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "1","2" },\r
-                               new PropertyInfo [] { typeof (TempClass).GetProperty ("FieldProperty")}, //here is the error\r
-                               new object [] { "TestCase" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FeildValue" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_9 ()\r
-               {\r
-                       //A field doesnot belong to same class\r
-                       \r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "1","2" },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] {"TestCase"},\r
-                               typeof (TempClass).GetFields (), //<-- fields of TempClass are passed\r
-                               new object [] { "FeildValue" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_10 ()\r
-               {\r
-                       //The types of the property values do \r
-                       //not match the types of the named properties.\r
-                       \r
-                                       \r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "1","2" },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { (long)1212121212 }, //<---type mismatch error(long for string)\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "FeildValue" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentException))]\r
-               public void ArgumentExceptionTest_11 ()\r
-               {\r
-                       //The types of the field values do \r
-                       //not match the types of the named properties.\r
-                       \r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       Assert ("#ctor not null", classCtorInfo != null);\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "1","2" },\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "One" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object []{ 12.1212 } //<---type mismatch error(double for string)\r
-                               ); \r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentNullException))]\r
-               public void ArgumentNullException_1 ()\r
-               {\r
-                       //the ctor value array (2nd argument) is null\r
-                       Type [] ctorParams = new Type [] { typeof (string),typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       Assert ("#ctor not null", classCtorInfo != null);\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               null, //<-- here is the error\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] { "One" },\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "feild" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentNullException))]\r
-               public void ArgumentNullException_2 ()\r
-               {\r
-                       //the property value array (4th argument) is null\r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       Assert ("#ctor not null", classCtorInfo != null);\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "one","two" },\r
-                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               null, // <-- here is the error\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               new object [] { "feild" }\r
-                               );\r
-               }\r
-\r
-\r
-               [Test]\r
-               [ExpectedException (typeof (ArgumentNullException))]\r
-               public void ArgumentNullException_3 ()\r
-               {\r
-                       //the field value array (6th argument) is null\r
-                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
-                       \r
-                       ConstructorInfo classCtorInfo = \r
-                               typeof (CustomAttribute).GetConstructor (ctorParams);\r
-\r
-                       Assert ("#ctor not null", classCtorInfo != null);\r
-                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
-                               classCtorInfo,\r
-                               new object [] { "one","two" },\r
-                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
-                               new object [] {"property"},\r
-                               typeof (CustomAttribute).GetFields (),\r
-                               null // <-- here is the error\r
-                               );\r
-               }\r
-       }\r
-}\r
-\r
+// CustomAttributeBuilderTest.cs
+//
+// Author: Vineeth N <nvineeth@yahoo.com>
+//
+// (C) 2004 Ximian, Inc. http://www.ximian.com
+//
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Threading;
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection.Emit
+{
+       /// <summary>
+       /// TestFixture for CustomAttributeBuilderTest.
+       /// The members to be tested are as follows:
+       /// 4 constructors:
+       /// 1) public CustomAttributeBuilder(ConstructorInfo, object[]);
+       /// 2) public CustomAttributeBuilder(ConstructorInfo, object[], FieldInfo[], object[]);
+       /// 3) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[]);
+       /// 4) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);
+       /// and the exceptions that are thrown.
+       /// In the implementation , it can be seen that the first
+       /// three type of  constructors call the 4th type of ctor, which takes 6 args
+       /// by filling args and substituting null as required.
+       /// For testing constructors we have use 4 different test functions,
+       /// Various exceptions have been checked for 4th type of consturctor.
+       /// </summary>
+
+       [TestFixture]
+       public class CustomAttributeBuilderTest
+       {
+               
+               // the CustomAttribute class is used for testing and it has to be public
+               //since it will be associated with a class that belongs to another assembly 
+
+               [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Class)]
+               public class CustomAttribute: Attribute
+               {
+                       private string attr1;
+                       private string attr2;
+                       public string Feild; //used for testing the second type of constructor
+
+                       public CustomAttribute () {}
+                       public CustomAttribute (String s1 , String s2)
+                       {
+                               attr1 = s1;
+                               attr2=s2;
+                        }
+
+                       private CustomAttribute (String s1) {}
+                       static CustomAttribute () {}
+
+                       public string AttributeOne
+                       {
+                               get { return attr1; }
+                               set { attr1 = value; }
+                       }
+                       
+                       public string AttributeTwo
+                       {
+                               get { return attr2; }
+                               //the set is skipped and is used later in testing
+                       }
+
+               }
+               
+               private class TempClass
+               {
+                       //used for testing the ArgumentException
+                       public string Field;
+                       public string FieldProperty
+                       {
+                               get { return Field; }
+                               set { Field = value; }
+                       }
+               }
+
+               
+
+               
+               [Test]
+               public void CtorOneTest ()
+               {
+                       //test for the constructor with signature--
+                       // public CustomAttributeBuilder(ConstructorInfo, object[]);
+                       /*
+                        * WE build a imaginary type as follows
+                        * class TestType
+                        * {
+                        *      [CustomAttribute("one","two")]
+                        *      public string Str;
+                        * 
+                        *      [CustomAttribute("hello","world")]
+                        *      public void Print()
+                        *      {Console.WriteLine("Hello World"); }
+                        * 
+                        * }
+                        * And then check for the validity of attributes in the test functions
+                        */
+                       AssemblyName asmName = new AssemblyName ();
+                       asmName.Name = "TestAssembly.dll";
+
+                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
+                               asmName , AssemblyBuilderAccess.Run);
+                       
+                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
+                       
+                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
+                               TypeAttributes.Public);
+
+                       Type[] ctorParams = new Type[] { typeof (string),typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder feildCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "one","two" }
+                               ),
+                               methodCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "hello","world" }
+                               );
+                       //now let's build a feild of type string and associate a attribute with it
+                       FieldBuilder fieldBuilder= typeBuilder.DefineField ("Str",
+                               typeof (string), FieldAttributes.Public);
+                       fieldBuilder.SetCustomAttribute (feildCABuilder);
+                       //now build a method 
+                       MethodBuilder methodBuilder= typeBuilder.DefineMethod ("Print",
+                               MethodAttributes.Public, null, null);
+                       methodBuilder.SetCustomAttribute (methodCABuilder);
+                       ILGenerator methodIL = methodBuilder.GetILGenerator ();
+                       methodIL.EmitWriteLine ("Hello, world!");
+                       methodIL.Emit (OpCodes.Ret);
+                       
+                       // create the type
+                       Type myType = typeBuilder.CreateType ();
+
+                       //Now check for the validity of the attributes.
+                       object testInstance = Activator.CreateInstance (myType);
+
+                       //check the validity of the attribute associated with Print method 
+                       
+                       object [] methodAttrs =  myType.GetMember ("Print") [0].GetCustomAttributes (true);
+                       Assert.AreEqual (methodAttrs.Length, 1, "#1");
+                       CustomAttribute methodAttr = methodAttrs [0] as CustomAttribute;
+                       Assert.AreEqual (methodAttr.AttributeOne, "hello", "#2");
+                       Assert.AreEqual (methodAttr.AttributeTwo, "world", "#3");
+                       
+                       //check the validity of the attribute associated with Str feild
+
+                       object [] fieldAttrs = myType.GetField ("Str").GetCustomAttributes (true);
+                       Assert.AreEqual(fieldAttrs.Length, 1, "#4");
+                       CustomAttribute fieldAttr = fieldAttrs [0] as CustomAttribute;
+                       Assert.AreEqual(fieldAttr.AttributeOne, "one", "#5");
+                       Assert.AreEqual(fieldAttr.AttributeTwo, "two", "#6");
+               }
+
+               [Test]
+               public void CtorTwoTest ()
+               {
+                       //test for the constructor with signature--
+                       // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], FieldInfo[], Object[]) ;
+                       /*
+                        * WE build a imaginary type as follows
+                        * [CustomAttribute("Test","Type")]
+                        * public class TestType
+                        * {
+                        * 
+                        * }
+                        * We also set the "Feild" of class CustomAttribute and the value;
+                        * And then check for the validity of attributes in the test functions
+                        */
+                                                                       
+                       AssemblyName asmName = new AssemblyName ();
+                       asmName.Name = "TestAssembly.dll";
+
+                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
+                               asmName, AssemblyBuilderAccess.Run);
+                       
+                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
+                       
+                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
+                               TypeAttributes.Public);
+
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "Test","Type" },
+                               typeof(CustomAttribute).GetFields(),
+                               new object [] { "TestCase" }
+                               ); 
+                               
+                       typeBuilder.SetCustomAttribute (typeCABuilder);
+                       
+                       // create the type
+                       Type myType = typeBuilder.CreateType ();
+
+                       //Now check for the validity of the attributes.
+                       object testInstance = Activator.CreateInstance (myType);
+
+                       //check the validity of the attribute associated with Print method 
+                       object [] customAttrs = myType.GetCustomAttributes (false);
+                       Assert.AreEqual (customAttrs.Length, 1, "1");
+
+                       //Custom Attributes of TestType
+                       CustomAttribute attr = customAttrs [0] as CustomAttribute;
+                       Assert.AreEqual (attr.AttributeOne, "Test", "#2");
+                       Assert.AreEqual (attr.AttributeTwo, "Type", "#3");
+                       Assert.AreEqual (attr.Feild, "TestCase", "#4");
+
+               }
+
+               [Test]
+               public void CtorThreeTest ()
+               {
+                       //test for the constructor with signature--
+                       // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], PropertyInfo[], Object[]) ;
+                       /*
+                        * WE build a imaginary type as follows
+                        * [CustomAttribute()]
+                        * public class TestType
+                        * {
+                        * 
+                        * }
+                        * We also set the "AttributeOne" of class CustomAttribute by means of the constuctor
+                        * And then check for the validity of attribute state 
+                        */
+                       
+                       AssemblyName asmName = new AssemblyName ();
+                       asmName.Name = "TestAssembly.dll";
+
+                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
+                               asmName, AssemblyBuilderAccess.Run);
+                       
+                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
+                       
+                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
+                               TypeAttributes.Public);
+                                                               
+                       Type [] ctorParams = new Type [] { };
+
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase" }
+                               ); 
+                               
+                       typeBuilder.SetCustomAttribute (typeCABuilder);
+                       
+                       // create the type
+                       Type myType = typeBuilder.CreateType ();
+
+                       //Now check for the validity of the attributes.
+                       object testInstance = Activator.CreateInstance (myType);
+
+                       //check the validity of the attribute associated with Print method 
+                       object [] customAttrs = myType.GetCustomAttributes (false);
+                       Assert.AreEqual (customAttrs.Length , 1, "#1");
+
+                       //Custom Attributes of TestType
+                       CustomAttribute attr = customAttrs [0] as CustomAttribute;
+                       Assert.AreEqual(attr.AttributeOne, "TestCase", "#2");
+               }
+
+               [Test]
+               public void CtorFourTest ()
+               {
+                       //test for the constructor with signature--
+                       //public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);
+                       /*
+                        * WE build a imaginary type as follows
+                        * [CustomAttribute()]
+                        * public class TestType
+                        * {
+                        * 
+                        * }
+                        * We also set the "AttributeOne" property ,
+                        * and "Feild" of class CustomAttribute 
+                        * by means of the constuctor of CustomAttributeBuilder
+                        * And then check for the validity 
+                        */
+                                       
+                       AssemblyName asmName = new AssemblyName ();
+                       asmName.Name = "TestAssembly.dll";
+
+                       AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (
+                               asmName , AssemblyBuilderAccess.Run);
+                       
+                       ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");
+                       
+                       TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",
+                               TypeAttributes.Public);
+               
+                       Type [] ctorParams = new Type [] { };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder(
+                               classCtorInfo,
+                               new object [] { },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase" },
+                               typeof(CustomAttribute).GetFields (),
+                               new object [] { "FieldValue" }
+                               ); 
+                               
+                       typeBuilder.SetCustomAttribute (typeCABuilder);
+                       
+                       // create the type
+                       Type myType = typeBuilder.CreateType ();
+
+                       //Now check for the validity of the attributes.
+                       object testInstance = Activator.CreateInstance (myType);
+
+                       //check the validity of the attribute associated with Print method 
+                       object [] customAttrs = myType.GetCustomAttributes (false);
+                       Assert.AreEqual(customAttrs.Length , 1, "#1");
+
+                       //Custom Attributes of TestType
+                       CustomAttribute attr = customAttrs [0] as CustomAttribute;
+                       Assert.AreEqual (attr.AttributeOne, "TestCase", "#2");
+                       Assert.AreEqual (attr.Feild, "FieldValue", "#3");
+               }
+       
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_1 ()
+               {
+                       //here the constructor is static 
+                                       
+                       Type [] ctorParams = new Type [] { };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (BindingFlags.Static | BindingFlags.NonPublic,
+                                                null, ctorParams, null);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { },
+                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FieldValue" }
+                               );
+               }
+
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_2 ()
+               {
+                       //here the consturctor is private
+                                       
+                       Type [] ctorParams = new Type[] {typeof(string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (BindingFlags.Instance |
+                                                BindingFlags.NonPublic, null, ctorParams, null);
+
+                       Assert.IsNotNull (classCtorInfo);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "hello" },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FieldValue" }
+                               );
+               }
+
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_3 ()
+               {
+                       // The lengths of the namedProperties and 
+                       //propertyValues arrays are different. 
+                       
+                       Type [] ctorParams = new Type [] { };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { },
+                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase","extra arg" },//<--here is the error
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FieldValue" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_4()
+               {
+                       //The length of the namedFields and
+                       //namedValues are different 
+                       
+                       Type [] ctorParams = new Type [] { };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { },
+                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { }//<--here is the error
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_6 ()
+               {
+                       //The type of supplied argument does not
+                       //match the type of the parameter declared 
+                       //in the constructor.
+                       
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "1", 123 },//<--here is the error,(int instead of string)
+                               new PropertyInfo[]{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "TestCase" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FeildValue" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_7 ()
+               {
+                       //A property has no setter.(CustomAttribute.AttributeTwo)
+                                               
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "1","2" },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeTwo") },
+                               new object [] { "TestCase" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FeildValue" }
+                               ); 
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_8 ()
+               {
+                       //A property doesnot belong to same class
+                       
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "1","2" },
+                               new PropertyInfo [] { typeof (TempClass).GetProperty ("FieldProperty")}, //here is the error
+                               new object [] { "TestCase" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FeildValue" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_9 ()
+               {
+                       //A field doesnot belong to same class
+                       
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "1","2" },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] {"TestCase"},
+                               typeof (TempClass).GetFields (), //<-- fields of TempClass are passed
+                               new object [] { "FeildValue" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_10 ()
+               {
+                       //The types of the property values do 
+                       //not match the types of the named properties.
+                       
+                                       
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "1","2" },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { (long)1212121212 }, //<---type mismatch error(long for string)
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "FeildValue" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ArgumentExceptionTest_11 ()
+               {
+                       //The types of the field values do 
+                       //not match the types of the named properties.
+                       
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       Assert.IsNotNull (classCtorInfo);
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "1","2" },
+                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "One" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object []{ 12.1212 } //<---type mismatch error(double for string)
+                               ); 
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ArgumentNullException_1 ()
+               {
+                       //the ctor value array (2nd argument) is null
+                       Type [] ctorParams = new Type [] { typeof (string),typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       Assert.IsNotNull (classCtorInfo);
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               null, //<-- here is the error
+                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] { "One" },
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "feild" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ArgumentNullException_2 ()
+               {
+                       //the property value array (4th argument) is null
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       Assert.IsNotNull (classCtorInfo);
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "one","two" },
+                               new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               null, // <-- here is the error
+                               typeof (CustomAttribute).GetFields (),
+                               new object [] { "feild" }
+                               );
+               }
+
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ArgumentNullException_3 ()
+               {
+                       //the field value array (6th argument) is null
+                       Type [] ctorParams = new Type [] { typeof (string), typeof (string) };
+                       
+                       ConstructorInfo classCtorInfo = 
+                               typeof (CustomAttribute).GetConstructor (ctorParams);
+
+                       Assert.IsNotNull (classCtorInfo);
+                       CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (
+                               classCtorInfo,
+                               new object [] { "one","two" },
+                               new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },
+                               new object [] {"property"},
+                               typeof (CustomAttribute).GetFields (),
+                               null // <-- here is the error
+                               );
+               }
+
+               class C {
+                       public C (object i) {
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ObjectParam_UserDefinedClass ()
+               {
+                       var cab = new CustomAttributeBuilder(
+                                                typeof (C).GetConstructors ()[0],
+                                                new object[] { new C (1) });
+               }
+       }
+}
+