Switch to compiler-tester
[mono.git] / mcs / class / corlib / Test / System.Reflection.Emit / CustomAttributeBuilderTest.cs
1 // CustomAttributeBuilderTest.cs\r
2 //\r
3 // Author: Vineeth N <nvineeth@yahoo.com>\r
4 //\r
5 // (C) 2004 Ximian, Inc. http://www.ximian.com\r
6 //\r
7 using System;\r
8 using System.Reflection;\r
9 using System.Reflection.Emit;\r
10 using System.Threading;\r
11 using NUnit.Framework;\r
12 \r
13 namespace MonoTests.System.Reflection.Emit\r
14 {\r
15         /// <summary>\r
16         /// TestFixture for CustomAttributeBuilderTest.\r
17         /// The members to be tested are as follows:\r
18         /// 4 constructors:\r
19         /// 1) public CustomAttributeBuilder(ConstructorInfo, object[]);\r
20         /// 2) public CustomAttributeBuilder(ConstructorInfo, object[], FieldInfo[], object[]);\r
21         /// 3) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[]);\r
22         /// 4) public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);\r
23         /// and the exceptions that are thrown.\r
24         /// In the implementation , it can be seen that the first\r
25         /// three type of  constructors call the 4th type of ctor, which takes 6 args\r
26         /// by filling args and substituting null as required.\r
27         /// For testing constructors we have use 4 different test functions,\r
28         /// Various exceptions have been checked for 4th type of consturctor.\r
29         /// </summary>\r
30 \r
31         [TestFixture]\r
32         public class CustomAttributeBuilderTest : Assertion\r
33         {\r
34                 \r
35                 // the CustomAttribute class is used for testing and it has to be public\r
36                 //since it will be associated with a class that belongs to another assembly \r
37 \r
38                 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Class)]\r
39                 public class CustomAttribute: Attribute\r
40                 {\r
41                         private string attr1;\r
42                         private string attr2;\r
43                         public string Feild; //used for testing the second type of constructor\r
44 \r
45                         public CustomAttribute () {}\r
46                         public CustomAttribute (String s1 , String s2)\r
47                         {\r
48                                 attr1 = s1;\r
49                                 attr2=s2;\r
50                         }\r
51 \r
52                         private CustomAttribute (String s1) {}\r
53                         static CustomAttribute () {}\r
54 \r
55                         public string AttributeOne\r
56                         {\r
57                                 get { return attr1; }\r
58                                 set { attr1 = value; }\r
59                         }\r
60                         \r
61                         public string AttributeTwo\r
62                         {\r
63                                 get { return attr2; }\r
64                                 //the set is skipped and is used later in testing\r
65                         }\r
66 \r
67                 }\r
68                 \r
69                 private class TempClass\r
70                 {\r
71                         //used for testing the ArgumentException\r
72                         public string Field;\r
73                         public string FieldProperty\r
74                         {\r
75                                 get { return Field; }\r
76                                 set { Field = value; }\r
77                         }\r
78                 }\r
79 \r
80                 \r
81 \r
82                 \r
83                 [Test]\r
84                 public void CtorOneTest ()\r
85                 {\r
86                         //test for the constructor with signature--\r
87                         // public CustomAttributeBuilder(ConstructorInfo, object[]);\r
88                         /*\r
89                          * WE build a imaginary type as follows\r
90                          * class TestType\r
91                          * {\r
92                          *      [CustomAttribute("one","two")]\r
93                          *      public string Str;\r
94                          * \r
95                          *      [CustomAttribute("hello","world")]\r
96                          *      public void Print()\r
97                          *      {Console.WriteLine("Hello World"); }\r
98                          * \r
99                          * }\r
100                          * And then check for the validity of attributes in the test functions\r
101                          */\r
102                         AssemblyName asmName = new AssemblyName ();\r
103                         asmName.Name = "TestAssembly.dll";\r
104 \r
105                         AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
106                                 asmName , AssemblyBuilderAccess.Run);\r
107                         \r
108                         ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
109                         \r
110                         TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
111                                 TypeAttributes.Public);\r
112 \r
113                         Type[] ctorParams = new Type[] { typeof (string),typeof (string) };\r
114                         \r
115                         ConstructorInfo classCtorInfo = \r
116                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
117 \r
118                         CustomAttributeBuilder feildCABuilder = new CustomAttributeBuilder (\r
119                                 classCtorInfo,\r
120                                 new object [] { "one","two" }\r
121                                 ),\r
122                                 methodCABuilder = new CustomAttributeBuilder (\r
123                                 classCtorInfo,\r
124                                 new object [] { "hello","world" }\r
125                                 );\r
126                         //now let's build a feild of type string and associate a attribute with it\r
127                         FieldBuilder fieldBuilder= typeBuilder.DefineField ("Str",\r
128                                 typeof (string), FieldAttributes.Public);\r
129                         fieldBuilder.SetCustomAttribute (feildCABuilder);\r
130                         //now build a method \r
131                         MethodBuilder methodBuilder= typeBuilder.DefineMethod ("Print",\r
132                                 MethodAttributes.Public, null, null);\r
133                         methodBuilder.SetCustomAttribute (methodCABuilder);\r
134                         ILGenerator methodIL = methodBuilder.GetILGenerator ();\r
135                         methodIL.EmitWriteLine ("Hello, world!");\r
136                         methodIL.Emit (OpCodes.Ret);\r
137                         \r
138                         // create the type\r
139                         Type myType = typeBuilder.CreateType ();\r
140 \r
141                         //Now check for the validity of the attributes.\r
142                         object testInstance = Activator.CreateInstance (myType);\r
143 \r
144                         //check the validity of the attribute associated with Print method \r
145                         \r
146                         object [] methodAttrs =  myType.GetMember ("Print") [0].GetCustomAttributes (true);\r
147                         AssertEquals ("#method Print has exactly one attribute", methodAttrs.Length, 1);\r
148                         CustomAttribute methodAttr = methodAttrs [0] as CustomAttribute;\r
149                         AssertEquals ("#AttributeOne", methodAttr.AttributeOne, "hello");\r
150                         AssertEquals ("#AttributeTwo", methodAttr.AttributeTwo, "world");\r
151                         \r
152                         //check the validity of the attribute associated with Str feild\r
153 \r
154                         object [] fieldAttrs = myType.GetField ("Str").GetCustomAttributes (true);\r
155                         AssertEquals("#feild Str has exactly one attribute", fieldAttrs.Length, 1);\r
156                         CustomAttribute fieldAttr = fieldAttrs [0] as CustomAttribute;\r
157                         AssertEquals("#AttributeOne", fieldAttr.AttributeOne, "one");\r
158                         AssertEquals("#AttributeTwo", fieldAttr.AttributeTwo, "two");\r
159                 }\r
160 \r
161                 [Test]\r
162                 public void CtorTwoTest ()\r
163                 {\r
164                         //test for the constructor with signature--\r
165                         // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], FieldInfo[], Object[]) ;\r
166                         /*\r
167                          * WE build a imaginary type as follows\r
168                          * [CustomAttribute("Test","Type")]\r
169                          * public class TestType\r
170                          * {\r
171                          * \r
172                          * }\r
173                          * We also set the "Feild" of class CustomAttribute and the value;\r
174                          * And then check for the validity of attributes in the test functions\r
175                          */\r
176                                                                         \r
177                         AssemblyName asmName = new AssemblyName ();\r
178                         asmName.Name = "TestAssembly.dll";\r
179 \r
180                         AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
181                                 asmName, AssemblyBuilderAccess.Run);\r
182                         \r
183                         ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
184                         \r
185                         TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
186                                 TypeAttributes.Public);\r
187 \r
188                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
189                         \r
190                         ConstructorInfo classCtorInfo = \r
191                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
192 \r
193                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
194                                 classCtorInfo,\r
195                                 new object [] { "Test","Type" },\r
196                                 typeof(CustomAttribute).GetFields(),\r
197                                 new object [] { "TestCase" }\r
198                                 ); \r
199                                 \r
200                         typeBuilder.SetCustomAttribute (typeCABuilder);\r
201                         \r
202                         // create the type\r
203                         Type myType = typeBuilder.CreateType ();\r
204 \r
205                         //Now check for the validity of the attributes.\r
206                         object testInstance = Activator.CreateInstance (myType);\r
207 \r
208                         //check the validity of the attribute associated with Print method \r
209                         object [] customAttrs = myType.GetCustomAttributes (false);\r
210                         AssertEquals ("#TestType has exactly one attribute", customAttrs.Length, 1);\r
211 \r
212                         //Custom Attributes of TestType\r
213                         CustomAttribute attr = customAttrs [0] as CustomAttribute;\r
214                         AssertEquals ("#AttributeOne", attr.AttributeOne, "Test");\r
215                         AssertEquals ("#AttributeTwo", attr.AttributeTwo, "Type");\r
216                         AssertEquals ("#CustomAttribute.Feild",attr.Feild, "TestCase");\r
217 \r
218                 }\r
219 \r
220                 [Test]\r
221                 public void CtorThreeTest ()\r
222                 {\r
223                         //test for the constructor with signature--\r
224                         // CustomAttributeBuilder Constructor (ConstructorInfo, Object[], PropertyInfo[], Object[]) ;\r
225                         /*\r
226                          * WE build a imaginary type as follows\r
227                          * [CustomAttribute()]\r
228                          * public class TestType\r
229                          * {\r
230                          * \r
231                          * }\r
232                          * We also set the "AttributeOne" of class CustomAttribute by means of the constuctor\r
233                          * And then check for the validity of attribute state \r
234                          */\r
235                         \r
236                         AssemblyName asmName = new AssemblyName ();\r
237                         asmName.Name = "TestAssembly.dll";\r
238 \r
239                         AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
240                                 asmName, AssemblyBuilderAccess.Run);\r
241                         \r
242                         ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
243                         \r
244                         TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
245                                 TypeAttributes.Public);\r
246                                                                 \r
247                         Type [] ctorParams = new Type [] { };\r
248 \r
249                         ConstructorInfo classCtorInfo = \r
250                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
251 \r
252                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
253                                 classCtorInfo,\r
254                                 new object [] { },\r
255                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
256                                 new object [] { "TestCase" }\r
257                                 ); \r
258                                 \r
259                         typeBuilder.SetCustomAttribute (typeCABuilder);\r
260                         \r
261                         // create the type\r
262                         Type myType = typeBuilder.CreateType ();\r
263 \r
264                         //Now check for the validity of the attributes.\r
265                         object testInstance = Activator.CreateInstance (myType);\r
266 \r
267                         //check the validity of the attribute associated with Print method \r
268                         object [] customAttrs = myType.GetCustomAttributes (false);\r
269                         AssertEquals ("#TestType has exactly one attribute", customAttrs.Length , 1);\r
270 \r
271                         //Custom Attributes of TestType\r
272                         CustomAttribute attr = customAttrs [0] as CustomAttribute;\r
273                         AssertEquals("#AttributeOne", attr.AttributeOne, "TestCase");\r
274                 }\r
275 \r
276                 [Test]\r
277                 public void CtorFourTest ()\r
278                 {\r
279                         //test for the constructor with signature--\r
280                         //public CustomAttributeBuilder(ConstructorInfo, object[], PropertyInfo[], object[], FieldInfo[], object[]);\r
281                         /*\r
282                          * WE build a imaginary type as follows\r
283                          * [CustomAttribute()]\r
284                          * public class TestType\r
285                          * {\r
286                          * \r
287                          * }\r
288                          * We also set the "AttributeOne" property ,\r
289                          * and "Feild" of class CustomAttribute \r
290                          * by means of the constuctor of CustomAttributeBuilder\r
291                          * And then check for the validity \r
292                          */\r
293                                         \r
294                         AssemblyName asmName = new AssemblyName ();\r
295                         asmName.Name = "TestAssembly.dll";\r
296 \r
297                         AssemblyBuilder asmBuilder = Thread.GetDomain ().DefineDynamicAssembly (\r
298                                 asmName , AssemblyBuilderAccess.Run);\r
299                         \r
300                         ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ("TestModule");\r
301                         \r
302                         TypeBuilder typeBuilder = modBuilder.DefineType ("TestType",\r
303                                 TypeAttributes.Public);\r
304                 \r
305                         Type [] ctorParams = new Type [] { };\r
306                         \r
307                         ConstructorInfo classCtorInfo = \r
308                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
309 \r
310                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder(\r
311                                 classCtorInfo,\r
312                                 new object [] { },\r
313                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
314                                 new object [] { "TestCase" },\r
315                                 typeof(CustomAttribute).GetFields (),\r
316                                 new object [] { "FieldValue" }\r
317                                 ); \r
318                                 \r
319                         typeBuilder.SetCustomAttribute (typeCABuilder);\r
320                         \r
321                         // create the type\r
322                         Type myType = typeBuilder.CreateType ();\r
323 \r
324                         //Now check for the validity of the attributes.\r
325                         object testInstance = Activator.CreateInstance (myType);\r
326 \r
327                         //check the validity of the attribute associated with Print method \r
328                         object [] customAttrs = myType.GetCustomAttributes (false);\r
329                         AssertEquals("#TestType has exactly one attribute",customAttrs.Length , 1);\r
330 \r
331                         //Custom Attributes of TestType\r
332                         CustomAttribute attr = customAttrs [0] as CustomAttribute;\r
333                         AssertEquals ("#AttributeOne", attr.AttributeOne, "TestCase");\r
334                         AssertEquals ("#Field ", attr.Feild, "FieldValue");\r
335                 }\r
336         \r
337                 \r
338                 [Test]\r
339                 [ExpectedException (typeof (ArgumentException))]\r
340                 public void ArgumentExceptionTest_1 ()\r
341                 {\r
342                         //here the constructor is static \r
343                                         \r
344                         Type [] ctorParams = new Type [] { };\r
345                         \r
346                         ConstructorInfo classCtorInfo = \r
347                                 typeof (CustomAttribute).GetConstructor (BindingFlags.Static | BindingFlags.NonPublic,\r
348                                                 null, ctorParams, null);\r
349 \r
350                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
351                                 classCtorInfo,\r
352                                 new object [] { },\r
353                                 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
354                                 new object [] { "TestCase" },\r
355                                 typeof (CustomAttribute).GetFields (),\r
356                                 new object [] { "FieldValue" }\r
357                                 );\r
358                 }\r
359 \r
360                 \r
361                 [Test]\r
362                 [ExpectedException (typeof (ArgumentException))]\r
363                 public void ArgumentExceptionTest_2 ()\r
364                 {\r
365                         //here the consturctor is private\r
366                                         \r
367                         Type [] ctorParams = new Type[] {typeof(string) };\r
368                         \r
369                         ConstructorInfo classCtorInfo = \r
370                                 typeof (CustomAttribute).GetConstructor (BindingFlags.Instance |\r
371                                                 BindingFlags.NonPublic, null, ctorParams, null);\r
372 \r
373                         Assert ("#Custom Attribute has private constuctor ", classCtorInfo != null);\r
374 \r
375                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
376                                 classCtorInfo,\r
377                                 new object [] { "hello" },\r
378                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
379                                 new object [] { "TestCase" },\r
380                                 typeof (CustomAttribute).GetFields (),\r
381                                 new object [] { "FieldValue" }\r
382                                 );\r
383                 }\r
384 \r
385                 \r
386                 [Test]\r
387                 [ExpectedException (typeof (ArgumentException))]\r
388                 public void ArgumentExceptionTest_3 ()\r
389                 {\r
390                         // The lengths of the namedProperties and \r
391                         //propertyValues arrays are different. \r
392                         \r
393                         Type [] ctorParams = new Type [] { };\r
394                         \r
395                         ConstructorInfo classCtorInfo = \r
396                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
397 \r
398                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
399                                 classCtorInfo,\r
400                                 new object [] { },\r
401                                 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
402                                 new object [] { "TestCase","extra arg" },//<--here is the error\r
403                                 typeof (CustomAttribute).GetFields (),\r
404                                 new object [] { "FieldValue" }\r
405                                 );\r
406                 }\r
407 \r
408 \r
409                 [Test]\r
410                 [ExpectedException (typeof (ArgumentException))]\r
411                 public void ArgumentExceptionTest_4()\r
412                 {\r
413                         //The length of the namedFields and\r
414                         //namedValues are different \r
415                         \r
416                         Type [] ctorParams = new Type [] { };\r
417                         \r
418                         ConstructorInfo classCtorInfo = \r
419                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
420 \r
421                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
422                                 classCtorInfo,\r
423                                 new object [] { },\r
424                                 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
425                                 new object [] { "TestCase" },\r
426                                 typeof (CustomAttribute).GetFields (),\r
427                                 new object [] { }//<--here is the error\r
428                                 );\r
429                 }\r
430 \r
431 \r
432                 [Test]\r
433                 [ExpectedException (typeof (ArgumentException))]\r
434                 public void ArgumentExceptionTest_6 ()\r
435                 {\r
436                         //The type of supplied argument does not\r
437                         //match the type of the parameter declared \r
438                         //in the constructor.\r
439                         \r
440                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
441                         \r
442                         ConstructorInfo classCtorInfo = \r
443                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
444 \r
445                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
446                                 classCtorInfo,\r
447                                 new object [] { "1", 123 },//<--here is the error,(int instead of string)\r
448                                 new PropertyInfo[]{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
449                                 new object [] { "TestCase" },\r
450                                 typeof (CustomAttribute).GetFields (),\r
451                                 new object [] { "FeildValue" }\r
452                                 );\r
453                 }\r
454 \r
455 \r
456                 [Test]\r
457                 [ExpectedException (typeof (ArgumentException))]\r
458                 public void ArgumentExceptionTest_7 ()\r
459                 {\r
460                         //A property has no setter.(CustomAttribute.AttributeTwo)\r
461                                                 \r
462                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
463                         \r
464                         ConstructorInfo classCtorInfo = \r
465                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
466 \r
467                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
468                                 classCtorInfo,\r
469                                 new object [] { "1","2" },\r
470                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeTwo") },\r
471                                 new object [] { "TestCase" },\r
472                                 typeof (CustomAttribute).GetFields (),\r
473                                 new object [] { "FeildValue" }\r
474                                 ); \r
475                 }\r
476 \r
477 \r
478                 [Test]\r
479                 [ExpectedException (typeof (ArgumentException))]\r
480                 public void ArgumentExceptionTest_8 ()\r
481                 {\r
482                         //A property doesnot belong to same class\r
483                         \r
484                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
485                         \r
486                         ConstructorInfo classCtorInfo = \r
487                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
488 \r
489                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
490                                 classCtorInfo,\r
491                                 new object [] { "1","2" },\r
492                                 new PropertyInfo [] { typeof (TempClass).GetProperty ("FieldProperty")}, //here is the error\r
493                                 new object [] { "TestCase" },\r
494                                 typeof (CustomAttribute).GetFields (),\r
495                                 new object [] { "FeildValue" }\r
496                                 );\r
497                 }\r
498 \r
499 \r
500                 [Test]\r
501                 [ExpectedException (typeof (ArgumentException))]\r
502                 public void ArgumentExceptionTest_9 ()\r
503                 {\r
504                         //A field doesnot belong to same class\r
505                         \r
506                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
507                         \r
508                         ConstructorInfo classCtorInfo = \r
509                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
510 \r
511                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
512                                 classCtorInfo,\r
513                                 new object [] { "1","2" },\r
514                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
515                                 new object [] {"TestCase"},\r
516                                 typeof (TempClass).GetFields (), //<-- fields of TempClass are passed\r
517                                 new object [] { "FeildValue" }\r
518                                 );\r
519                 }\r
520 \r
521 \r
522                 [Test]\r
523                 [ExpectedException (typeof (ArgumentException))]\r
524                 public void ArgumentExceptionTest_10 ()\r
525                 {\r
526                         //The types of the property values do \r
527                         //not match the types of the named properties.\r
528                         \r
529                                         \r
530                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
531                         \r
532                         ConstructorInfo classCtorInfo = \r
533                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
534 \r
535                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
536                                 classCtorInfo,\r
537                                 new object [] { "1","2" },\r
538                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
539                                 new object [] { (long)1212121212 }, //<---type mismatch error(long for string)\r
540                                 typeof (CustomAttribute).GetFields (),\r
541                                 new object [] { "FeildValue" }\r
542                                 );\r
543                 }\r
544 \r
545 \r
546                 [Test]\r
547                 [ExpectedException (typeof (ArgumentException))]\r
548                 public void ArgumentExceptionTest_11 ()\r
549                 {\r
550                         //The types of the field values do \r
551                         //not match the types of the named properties.\r
552                         \r
553                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
554                         \r
555                         ConstructorInfo classCtorInfo = \r
556                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
557 \r
558                         Assert ("#ctor not null", classCtorInfo != null);\r
559                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
560                                 classCtorInfo,\r
561                                 new object [] { "1","2" },\r
562                                 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
563                                 new object [] { "One" },\r
564                                 typeof (CustomAttribute).GetFields (),\r
565                                 new object []{ 12.1212 } //<---type mismatch error(double for string)\r
566                                 ); \r
567                 }\r
568 \r
569 \r
570                 [Test]\r
571                 [ExpectedException (typeof (ArgumentNullException))]\r
572                 public void ArgumentNullException_1 ()\r
573                 {\r
574                         //the ctor value array (2nd argument) is null\r
575                         Type [] ctorParams = new Type [] { typeof (string),typeof (string) };\r
576                         \r
577                         ConstructorInfo classCtorInfo = \r
578                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
579 \r
580                         Assert ("#ctor not null", classCtorInfo != null);\r
581                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
582                                 classCtorInfo,\r
583                                 null, //<-- here is the error\r
584                                 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
585                                 new object [] { "One" },\r
586                                 typeof (CustomAttribute).GetFields (),\r
587                                 new object [] { "feild" }\r
588                                 );\r
589                 }\r
590 \r
591 \r
592                 [Test]\r
593                 [ExpectedException (typeof (ArgumentNullException))]\r
594                 public void ArgumentNullException_2 ()\r
595                 {\r
596                         //the property value array (4th argument) is null\r
597                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
598                         \r
599                         ConstructorInfo classCtorInfo = \r
600                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
601 \r
602                         Assert ("#ctor not null", classCtorInfo != null);\r
603                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
604                                 classCtorInfo,\r
605                                 new object [] { "one","two" },\r
606                                 new PropertyInfo []{ typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
607                                 null, // <-- here is the error\r
608                                 typeof (CustomAttribute).GetFields (),\r
609                                 new object [] { "feild" }\r
610                                 );\r
611                 }\r
612 \r
613 \r
614                 [Test]\r
615                 [ExpectedException (typeof (ArgumentNullException))]\r
616                 public void ArgumentNullException_3 ()\r
617                 {\r
618                         //the field value array (6th argument) is null\r
619                         Type [] ctorParams = new Type [] { typeof (string), typeof (string) };\r
620                         \r
621                         ConstructorInfo classCtorInfo = \r
622                                 typeof (CustomAttribute).GetConstructor (ctorParams);\r
623 \r
624                         Assert ("#ctor not null", classCtorInfo != null);\r
625                         CustomAttributeBuilder typeCABuilder = new CustomAttributeBuilder (\r
626                                 classCtorInfo,\r
627                                 new object [] { "one","two" },\r
628                                 new PropertyInfo [] { typeof (CustomAttribute).GetProperty ("AttributeOne") },\r
629                                 new object [] {"property"},\r
630                                 typeof (CustomAttribute).GetFields (),\r
631                                 null // <-- here is the error\r
632                                 );\r
633                 }\r
634         }\r
635 }\r
636 \r