73eea4275282dbee9d7aa1ef5e6c42aa97a077f8
[mono.git] / mcs / class / System / Test / Microsoft.VisualBasic / CodeGeneratorFromTypeTest.cs
1 //
2 // Microsoft.VisualBasic.* Test Cases
3 //
4 // Authors:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (c) Novell
8 //
9 using System;
10 using System.Globalization;
11 using System.Text;
12 using System.CodeDom;
13 using System.CodeDom.Compiler;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.Microsoft.VisualBasic
18 {
19         ///
20         /// <summary>
21         ///     Test ICodeGenerator's GenerateCodeFromType, along with a 
22         ///     minimal set CodeDom components.
23         /// </summary>
24         ///
25         [TestFixture]
26         public class CodeGeneratorFromTypeTest : CodeGeneratorTestBase
27         {
28                 CodeTypeDeclaration type = null;
29
30                 [SetUp]
31                 public void Init ()
32                 {
33                         InitBase ();
34                         type = new CodeTypeDeclaration ();
35                 }
36                 
37                 protected override void Generate ()
38                 {
39                         generator.GenerateCodeFromType (type, writer, options);
40                         writer.Close ();
41                 }
42                 
43                 [Test]
44                 public void DefaultTypeTest ()
45                 {
46                         Generate ();
47                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
48                                 "Public Class {0}End Class{0}", writer.NewLine), Code);
49                 }
50
51                 [Test]
52                 [ExpectedException (typeof (NullReferenceException))]
53                 public void NullTypeTest ()
54                 {
55                         type = null;
56                         Generate ();
57                 }
58
59                 [Test]
60                 public void SimpleTypeTest ()
61                 {
62                         type.Name = "Test1";
63                         Generate ();
64                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
65                                 "Public Class Test1{0}End Class{0}", writer.NewLine), Code);
66                 }
67
68                 [Test]
69                 public void AttributesAndTypeTest ()
70                 {
71                         type.Name = "Test1";
72
73                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
74                         attrDec.Name = "A";
75                         type.CustomAttributes.Add (attrDec);
76
77                         attrDec = new CodeAttributeDeclaration ();
78                         attrDec.Name = "B";
79                         type.CustomAttributes.Add (attrDec);
80
81                         Generate ();
82                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
83                                 "<A(),  _{0} B()>  _{0}Public Class Test1{0}End Class{0}", 
84                                 writer.NewLine), Code);
85                 }
86
87                 [Test]
88                 public void EventMembersTypeTest1 ()
89                 {
90                         type.Name = "Test1";
91
92                         CodeMemberEvent evt = new CodeMemberEvent ();
93
94                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
95                         attrDec.Name = "A";
96                         evt.CustomAttributes.Add (attrDec);
97
98                         attrDec = new CodeAttributeDeclaration ();
99                         attrDec.Name = "B";
100                         evt.CustomAttributes.Add (attrDec);
101
102                         type.Members.Add (evt);
103
104                         Generate ();
105                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
106                                 "Public Class Test1{0}    {0}    <A(),  _{0}     B()>  _{0}    "
107                                 + "Private Event  As System.Void{0}End Class{0}", writer.NewLine), Code);
108                 }
109
110                 [Test]
111                 public void EventMembersTypeTest2 ()
112                 {
113                         type.Name = "Test1";
114
115                         CodeMemberEvent evt = new CodeMemberEvent ();
116                         evt.Name = "OnClick";
117                         evt.Attributes = MemberAttributes.Public;
118                         evt.Type = new CodeTypeReference(typeof (int));
119                         type.Members.Add (evt);
120
121                         Generate ();
122                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
123                                 "Public Class Test1{0}    {0}    "
124                                 + "Public Event OnClick As Integer{0}"
125                                 + "End Class{0}", writer.NewLine), Code);
126                 }
127
128                 [Test]
129                 public void FieldMembersTypeTest1 ()
130                 {
131                         type.Name = "Test1";
132
133                         CodeMemberField fld = new CodeMemberField ();
134
135                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
136                         attrDec.Name = "A";
137                         fld.CustomAttributes.Add (attrDec);
138
139                         attrDec = new CodeAttributeDeclaration ();
140                         attrDec.Name = "B";
141                         fld.CustomAttributes.Add (attrDec);
142
143                         type.Members.Add (fld);
144
145                         Generate ();
146                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
147                                 "Public Class Test1{0}    {0}    <A(),  _{0}     B()>  _{0}    "
148                                 + "Private  As System.Void{0}End Class{0}", writer.NewLine), Code);
149                 }
150
151                 [Test]
152                 public void FieldMembersTypeTest2 ()
153                 {
154                         type.Name = "Test1";
155
156                         CodeMemberField fld = new CodeMemberField ();
157                         fld.Name = "Name";
158                         fld.Attributes = MemberAttributes.Public;
159                         fld.Type = new CodeTypeReference (typeof (int));
160                         type.Members.Add (fld);
161
162                         Generate ();
163                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
164                                 "Public Class Test1{0}    {0}    "
165                                 + "Public Name As Integer{0}"
166                                 + "End Class{0}", writer.NewLine), Code);
167                 }
168
169                 [Test]
170                 public void PropertyMembersTypeTest1 ()
171                 {
172                         type.Name = "Test1";
173
174                         CodeMemberProperty property = new CodeMemberProperty ();
175
176                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
177                         attrDec.Name = "A";
178                         property.CustomAttributes.Add (attrDec);
179
180                         attrDec = new CodeAttributeDeclaration ();
181                         attrDec.Name = "B";
182                         property.CustomAttributes.Add (attrDec);
183
184                         type.Members.Add (property);
185
186                         Generate ();
187                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
188                                 "Public Class Test1{0}"
189                                 + "    {0}"
190                                 + "    <A(),  _{0}"
191                                 + "     B()>  _{0}"
192 #if NET_2_0
193                                 + "    Private Property () As System.Void{0}"
194 #else
195                                 + "    Private Property  As System.Void{0}"
196 #endif
197                                 + "    End Property{0}"
198                                 + "End Class{0}", writer.NewLine), Code);
199                 }
200
201                 [Test]
202                 public void PropertyMembersTypeTest2 ()
203                 {
204                         type.Name = "Test1";
205
206                         CodeMemberProperty property = new CodeMemberProperty ();
207                         property.Name = "Name";
208                         property.Attributes = MemberAttributes.Public;
209                         property.Type = new CodeTypeReference (typeof (int));
210                         type.Members.Add (property);
211
212                         Generate ();
213                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
214                                 "Public Class Test1{0}"
215                                 + "    {0}"
216 #if NET_2_0
217                                 + "    Public Overridable Property Name() As Integer{0}"
218 #else
219                                 + "    Public Overridable Property Name As Integer{0}"
220 #endif
221                                 + "    End Property{0}"
222                                 + "End Class{0}", writer.NewLine), Code);
223                 }
224
225                 [Test]
226                 public void PropertyMembersTypeGetOnly ()
227                 {
228                         type.Name = "Test1";
229
230                         CodeMemberProperty property = new CodeMemberProperty ();
231                         property.Name = "Name";
232                         property.Attributes = MemberAttributes.Family;
233                         property.HasGet = true;
234                         property.Type = new CodeTypeReference (typeof (int));
235                         type.Members.Add (property);
236
237                         Generate ();
238                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
239                                 "Public Class Test1{0}"
240                                 + "    {0}"
241 #if NET_2_0
242                                 + "    Protected Overridable ReadOnly Property Name() As Integer{0}"
243 #else
244                                 + "    Protected Overridable ReadOnly Property Name As Integer{0}"
245 #endif
246                                 + "        Get{0}"
247                                 + "        End Get{0}"
248                                 + "    End Property{0}"
249                                 + "End Class{0}", writer.NewLine), Code);
250                 }
251
252                 [Test]
253                 public void PropertyMembersTypeSetOnly ()
254                 {
255                         type.Name = "Test1";
256
257                         CodeMemberProperty property = new CodeMemberProperty ();
258                         property.Name = "Name";
259                         property.Attributes = MemberAttributes.FamilyAndAssembly;
260                         property.HasSet = true;
261                         property.Type = new CodeTypeReference (typeof (int));
262                         type.Members.Add (property);
263
264                         Generate ();
265                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
266                                 "Public Class Test1{0}"
267                                 + "    {0}"
268 #if NET_2_0
269                                 + "    Friend WriteOnly Property Name() As Integer{0}"
270 #else
271                                 + "    Friend WriteOnly Property Name As Integer{0}"
272 #endif
273                                 + "        Set{0}"
274                                 + "        End Set{0}"
275                                 + "    End Property{0}"
276                                 + "End Class{0}", writer.NewLine), Code);
277                 }
278
279                 [Test]
280                 public void PropertyMembersTypeGetSet ()
281                 {
282                         type.Name = "Test1";
283
284                         CodeMemberProperty property = new CodeMemberProperty ();
285                         property.Name = "Name";
286                         property.Attributes = MemberAttributes.Family;
287                         property.HasGet = true;
288                         property.HasSet = true;
289                         property.Type = new CodeTypeReference (typeof (int));
290                         type.Members.Add (property);
291
292                         Generate ();
293                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
294                                 "Public Class Test1{0}"
295                                 + "    {0}"
296 #if NET_2_0
297                                 + "    Protected Overridable Property Name() As Integer{0}"
298 #else
299                                 + "    Protected Overridable Property Name As Integer{0}"
300 #endif
301                                 + "        Get{0}"
302                                 + "        End Get{0}"
303                                 + "        Set{0}"
304                                 + "        End Set{0}"
305                                 + "    End Property{0}"
306                                 + "End Class{0}", writer.NewLine), Code);
307                 }
308
309 #if !NET_2_0
310                 // A bug in MS.NET 1.x causes MemberAttributes.FamilyOrAssembly to be 
311                 // generated as Protected
312                 [Category("NotDotNet")]
313 #endif
314                 [Test]
315                 public void PropertyMembersTypeFamilyOrAssembly ()
316                 {
317                         type.Name = "Test1";
318
319                         CodeMemberProperty property = new CodeMemberProperty ();
320                         property.Name = "Name";
321                         property.Attributes = MemberAttributes.FamilyOrAssembly;
322                         property.Type = new CodeTypeReference (typeof (int));
323
324                         type.Members.Add (property);
325
326                         Generate ();
327                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
328                                 "Public Class Test1{0}"
329                                 + "    {0}"
330 #if NET_2_0
331                                 + "    Protected Friend Property Name() As Integer{0}"
332 #else
333                                 + "    Protected Friend Property Name As Integer{0}"
334 #endif
335                                 + "    End Property{0}"
336                                 + "End Class{0}", writer.NewLine), Code);
337                 }
338
339 #if !NET_2_0
340                 // A bug in MS.NET 1.x causes MemberAttributes.Assembly to be generated
341                 // as Protected
342                 [Category ("NotDotNet")]
343 #endif
344                 [Test]
345                 public void PropertyMembersTypeAssembly ()
346                 {
347                         type.Name = "Test1";
348
349                         CodeMemberProperty property = new CodeMemberProperty ();
350                         property.Name = "Name";
351                         property.Attributes = MemberAttributes.Assembly;
352                         property.Type = new CodeTypeReference (typeof (int));
353
354                         type.Members.Add (property);
355
356                         Generate ();
357                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
358                                 "Public Class Test1{0}"
359                                 + "    {0}"
360 #if NET_2_0
361                                 + "    Friend Overridable Property Name() As Integer{0}"
362 #else
363                                 + "    Friend Property Name As Integer{0}"
364 #endif
365                                 + "    End Property{0}"
366                                 + "End Class{0}", writer.NewLine), Code);
367                 }
368
369                 /// <summary>
370                 /// Apparently VB.NET CodeDOM also allows properties that aren't indexers
371                 /// to have parameters.
372                 /// </summary>
373                 [Test]
374                 public void PropertyParametersTest ()
375                 {
376                         type.Name = "Test1";
377
378                         CodeMemberProperty property = new CodeMemberProperty ();
379                         property.Name = "Name";
380                         property.Attributes = MemberAttributes.Public;
381                         property.Type = new CodeTypeReference (typeof (int));
382
383                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
384                                 typeof (object), "value1");
385                         property.Parameters.Add (param);
386
387                         param = new CodeParameterDeclarationExpression (
388                                 typeof (int), "value2");
389                         param.Direction = FieldDirection.Ref;
390                         property.Parameters.Add (param);
391
392                         type.Members.Add (property);
393
394                         Generate ();
395                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
396                                 "Public Class Test1{0}"
397                                 + "    {0}"
398                                 + "    Public Overridable Property Name(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}"
399                                 + "    End Property{0}"
400                                 + "End Class{0}", writer.NewLine), Code);
401                 }
402
403                 [Test]
404                 public void PropertyIndexerTest1 ()
405                 {
406                         type.Name = "Test1";
407
408                         CodeMemberProperty property = new CodeMemberProperty ();
409                         // ensure case-insensitive comparison is done on name of property
410                         property.Name = "iTem";
411                         property.Attributes = MemberAttributes.Public;
412                         property.Type = new CodeTypeReference (typeof (int));
413
414                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
415                                 typeof (object), "value1");
416                         property.Parameters.Add (param);
417
418                         param = new CodeParameterDeclarationExpression (
419                                 typeof (int), "value2");
420                         param.Direction = FieldDirection.Ref;
421                         property.Parameters.Add (param);
422
423                         type.Members.Add (property);
424
425                         Generate ();
426                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
427                                 "Public Class Test1{0}"
428                                 + "    {0}"
429                                 + "    Public Overridable Default Property iTem(ByVal value1 As Object, ByRef value2 As Integer) As Integer{0}"
430                                 + "    End Property{0}"
431                                 + "End Class{0}", writer.NewLine), Code);
432                 }
433
434                 /// <summary>
435                 /// Ensures Default keyword is only output if property is named "Item"
436                 /// (case-insensitive comparison) AND parameters are defined.
437                 /// </summary>
438                 [Test]
439                 public void PropertyIndexerTest2 ()
440                 {
441                         type.Name = "Test1";
442
443                         CodeMemberProperty property = new CodeMemberProperty ();
444                         // ensure case-insensitive comparison is done on name of property
445                         property.Name = "iTem";
446                         property.Attributes = MemberAttributes.Public;
447                         property.Type = new CodeTypeReference (typeof (int));
448                         type.Members.Add (property);
449
450                         Generate ();
451                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
452                                 "Public Class Test1{0}"
453                                 + "    {0}"
454 #if NET_2_0
455                                 + "    Public Overridable Property iTem() As Integer{0}"
456 #else
457                                 + "    Public Overridable Property iTem As Integer{0}"
458 #endif
459                                 + "    End Property{0}"
460                                 + "End Class{0}", writer.NewLine), Code);
461                 }
462
463                 [Test]
464                 public void MethodMembersTypeTest1 ()
465                 {
466                         type.Name = "Test1";
467
468                         CodeMemberMethod method = new CodeMemberMethod ();
469
470                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
471                         attrDec.Name = "A";
472                         method.CustomAttributes.Add (attrDec);
473
474                         attrDec = new CodeAttributeDeclaration ();
475                         attrDec.Name = "B";
476                         method.CustomAttributes.Add (attrDec);
477
478                         type.Members.Add (method);
479
480                         Generate ();
481                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
482                                 "Public Class Test1{0}" 
483                                 + "    {0}"
484                                 + "    <A(),  _{0}" 
485                                 + "     B()>  _{0}"
486                                 + "    Private Sub (){0}"
487                                 + "    End Sub{0}"
488                                 + "End Class{0}", writer.NewLine), Code);
489                 }
490
491                 [Test]
492                 public void MethodMembersTypeTest2 ()
493                 {
494                         type.Name = "Test1";
495
496                         CodeMemberMethod method = new CodeMemberMethod ();
497                         method.Name = "Something";
498                         method.Attributes = MemberAttributes.Public;
499                         method.ReturnType = new CodeTypeReference (typeof (int));
500
501                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
502                                 typeof(object), "value1");
503                         method.Parameters.Add (param);
504
505                         param = new CodeParameterDeclarationExpression (
506                                 typeof (object), "value2");
507                         param.Direction = FieldDirection.In;
508                         method.Parameters.Add (param);
509
510                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
511                         param.Direction = FieldDirection.Out;
512                         method.Parameters.Add (param);
513
514                         param = new CodeParameterDeclarationExpression (typeof (int), "count");
515                         param.Direction = FieldDirection.Ref;
516                         method.Parameters.Add (param);
517
518                         type.Members.Add (method);
519
520                         Generate ();
521                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
522                                 "Public Class Test1{0}"
523                                 + "    {0}"
524                                 + "    Public Overridable Function Something(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer) As Integer{0}"
525                                 + "    End Function{0}"
526                                 + "End Class{0}", writer.NewLine), Code);
527                 }
528
529                 [Test]
530                 public void MethodMembersTypeTest3 ()
531                 {
532                         type.Name = "Test1";
533
534                         CodeMemberMethod method = new CodeMemberMethod ();
535                         method.Name = "Something";
536                         method.Attributes = MemberAttributes.Public;
537                         method.ReturnType = new CodeTypeReference (typeof (int));
538
539                         // first parameter
540                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
541                                 typeof (object), "value");
542                         method.Parameters.Add (param);
543
544                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
545                         attrDec.Name = "A";
546                         param.CustomAttributes.Add (attrDec);
547
548                         attrDec = new CodeAttributeDeclaration ();
549                         attrDec.Name = "B";
550                         param.CustomAttributes.Add (attrDec);
551
552
553                         // second parameter
554                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
555                         param.Direction = FieldDirection.Out;
556                         method.Parameters.Add (param);
557
558                         attrDec = new CodeAttributeDeclaration ();
559                         attrDec.Name = "C";
560                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
561                                 new CodePrimitiveExpression (false)));
562                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
563                                 new CodePrimitiveExpression (true)));
564                         param.CustomAttributes.Add (attrDec);
565
566                         attrDec = new CodeAttributeDeclaration ();
567                         attrDec.Name = "D";
568                         param.CustomAttributes.Add (attrDec);
569
570                         type.Members.Add (method);
571
572                         Generate ();
573                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
574                                 "Public Class Test1{0}"
575                                 + "    {0}"
576                                 + "    Public Overridable Function Something(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer) As Integer{0}"
577                                 + "    End Function{0}"
578                                 + "End Class{0}", writer.NewLine), Code);
579                 }
580
581                 [Test]
582                 public void ConstructorAttributesTest ()
583                 {
584                         type.Name = "Test1";
585
586                         CodeConstructor ctor = new CodeConstructor ();
587
588                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
589                         attrDec.Name = "A";
590                         ctor.CustomAttributes.Add (attrDec);
591
592                         attrDec = new CodeAttributeDeclaration ();
593                         attrDec.Name = "B";
594                         ctor.CustomAttributes.Add (attrDec);
595
596                         type.Members.Add (ctor);
597
598                         Generate ();
599                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
600                                 "Public Class Test1{0}"
601                                 + "    {0}"
602                                 + "    <A(),  _{0}"
603                                 + "     B()>  _{0}"
604                                 + "    Private Sub New(){0}"
605                                 + "        MyBase.New{0}"
606                                 + "    End Sub{0}"
607                                 + "End Class{0}", writer.NewLine), Code);
608                 }
609
610                 [Test]
611                 public void ConstructorParametersTest ()
612                 {
613                         type.Name = "Test1";
614
615                         CodeConstructor ctor = new CodeConstructor ();
616                         ctor.Name = "Whatever";
617                         ctor.Attributes = MemberAttributes.Public;
618
619                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
620                                 typeof (object), "value1");
621                         ctor.Parameters.Add (param);
622
623                         param = new CodeParameterDeclarationExpression (
624                                 typeof (object), "value2");
625                         param.Direction = FieldDirection.In;
626                         ctor.Parameters.Add (param);
627
628                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
629                         param.Direction = FieldDirection.Out;
630                         ctor.Parameters.Add (param);
631
632                         param = new CodeParameterDeclarationExpression (typeof (int), "count");
633                         param.Direction = FieldDirection.Ref;
634                         ctor.Parameters.Add (param);
635
636                         type.Members.Add (ctor);
637
638                         Generate ();
639                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
640                                 "Public Class Test1{0}"
641                                 + "    {0}"
642                                 + "    Public Sub New(ByVal value1 As Object, ByVal value2 As Object, ByRef index As Integer, ByRef count As Integer){0}"
643                                 + "        MyBase.New{0}"
644                                 + "    End Sub{0}"
645                                 + "End Class{0}", writer.NewLine), Code);
646                 }
647
648                 [Test]
649                 public void ConstructorParameterAttributesTest ()
650                 {
651                         type.Name = "Test1";
652
653                         CodeConstructor ctor = new CodeConstructor ();
654                         ctor.Name = "Something";
655                         ctor.Attributes = MemberAttributes.Public;
656
657                         // first parameter
658                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
659                                 typeof (object), "value");
660                         ctor.Parameters.Add (param);
661
662                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
663                         attrDec.Name = "A";
664                         param.CustomAttributes.Add (attrDec);
665
666                         attrDec = new CodeAttributeDeclaration ();
667                         attrDec.Name = "B";
668                         param.CustomAttributes.Add (attrDec);
669
670                         // second parameter
671                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
672                         param.Direction = FieldDirection.Out;
673                         ctor.Parameters.Add (param);
674
675                         attrDec = new CodeAttributeDeclaration ();
676                         attrDec.Name = "C";
677                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
678                                 new CodePrimitiveExpression (false)));
679                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
680                                 new CodePrimitiveExpression (true)));
681                         param.CustomAttributes.Add (attrDec);
682
683                         attrDec = new CodeAttributeDeclaration ();
684                         attrDec.Name = "D";
685                         param.CustomAttributes.Add (attrDec);
686
687                         type.Members.Add (ctor);
688
689                         Generate ();
690                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
691                                 "Public Class Test1{0}"
692                                 + "    {0}"
693                                 + "    Public Sub New(<A(), B()> ByVal value As Object, <C(A1:=false, A2:=true), D()> ByRef index As Integer){0}"
694                                 + "        MyBase.New{0}"
695                                 + "    End Sub{0}"
696                                 + "End Class{0}", writer.NewLine), Code);
697                 }
698
699                 [Test]
700                 public void BaseConstructorSingleArg ()
701                 {
702                         type.Name = "Test1";
703
704                         CodeConstructor ctor = new CodeConstructor ();
705                         ctor.Name = "Something";
706                         ctor.Attributes = MemberAttributes.Public;
707
708                         // first parameter
709                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
710                                 typeof (object), "value1");
711                         ctor.Parameters.Add (param);
712
713                         // second parameter
714                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
715                         param.Direction = FieldDirection.Out;
716                         ctor.Parameters.Add (param);
717
718                         // base ctor args
719                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
720
721                         type.Members.Add (ctor);
722
723                         Generate ();
724                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
725                                 "Public Class Test1{0}"
726                                 + "    {0}"
727                                 + "    Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}"
728                                 + "        MyBase.New(value1){0}"
729                                 + "    End Sub{0}"
730                                 + "End Class{0}", writer.NewLine), Code);
731                 }
732
733                 [Test]
734                 public void BaseConstructorMultipleArgs ()
735                 {
736                         type.Name = "Test1";
737
738                         CodeConstructor ctor = new CodeConstructor ();
739                         ctor.Name = "Something";
740                         ctor.Attributes = MemberAttributes.Public;
741
742                         // first parameter
743                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
744                                 typeof (object), "value1");
745                         ctor.Parameters.Add (param);
746
747                         // second parameter
748                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
749                         param.Direction = FieldDirection.Out;
750                         ctor.Parameters.Add (param);
751
752                         // base ctor args
753                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
754                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
755
756                         type.Members.Add (ctor);
757
758                         Generate ();
759                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
760                                 "Public Class Test1{0}"
761                                 + "    {0}"
762                                 + "    Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}"
763                                 + "        MyBase.New(value1, value2){0}"
764                                 + "    End Sub{0}"
765                                 + "End Class{0}", writer.NewLine), Code);
766                 }
767
768                 [Test]
769                 public void ChainedConstructorSingleArg ()
770                 {
771                         type.Name = "Test1";
772
773                         CodeConstructor ctor = new CodeConstructor ();
774                         ctor.Name = "Something";
775                         ctor.Attributes = MemberAttributes.Public;
776
777                         // first parameter
778                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
779                                 typeof (object), "value1");
780                         ctor.Parameters.Add (param);
781
782                         // second parameter
783                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
784                         param.Direction = FieldDirection.Out;
785                         ctor.Parameters.Add (param);
786
787                         // chained ctor args
788                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
789
790                         // should be ignored as chained ctor args should take precedence over base 
791                         // ctor args
792                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value3"));
793
794                         type.Members.Add (ctor);
795
796                         Generate ();
797                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
798                                 "Public Class Test1{0}"
799                                 + "    {0}"
800                                 + "    Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}"
801                                 + "        Me.New(value1){0}"
802                                 + "    End Sub{0}"
803                                 + "End Class{0}", writer.NewLine), Code);
804                 }
805
806                 [Test]
807                 public void ChainedConstructorMultipleArgs ()
808                 {
809                         type.Name = "Test1";
810
811                         CodeConstructor ctor = new CodeConstructor ();
812                         ctor.Name = "Something";
813                         ctor.Attributes = MemberAttributes.Public;
814
815                         // first parameter
816                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
817                                 typeof (object), "value1");
818                         ctor.Parameters.Add (param);
819
820                         // second parameter
821                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
822                         param.Direction = FieldDirection.Out;
823                         ctor.Parameters.Add (param);
824
825                         // chained ctor args
826                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
827                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
828
829                         // should be ignored as chained ctor args should take precedence over base 
830                         // ctor args
831                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value3"));
832
833                         type.Members.Add (ctor);
834
835                         Generate ();
836                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
837                                 "Public Class Test1{0}"
838                                 + "    {0}"
839                                 + "    Public Sub New(ByVal value1 As Object, ByRef value2 As Integer){0}"
840                                 + "        Me.New(value1, value2){0}"
841                                 + "    End Sub{0}"
842                                 + "End Class{0}", writer.NewLine), Code);
843                 }
844         }
845 }