error messages review
[mono.git] / mcs / class / System / Test / Microsoft.CSharp / CodeGeneratorFromTypeTest.cs
1 //
2 // Microsoft.CSharp.* Test Cases
3 //
4 // Authors:
5 //      Erik LeBel (eriklebel@yahoo.ca)
6 //
7 // (c) 2003 Erik LeBel
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.CSharp
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                         Assertion.AssertEquals ("public class  {\n}\n", Code);
48                 }
49
50                 [Test]
51                 [ExpectedException (typeof (NullReferenceException))]
52                 public void NullTypeTest ()
53                 {
54                         type = null;
55                         Generate ();
56                 }
57
58                 [Test]
59                 public void SimpleTypeTest ()
60                 {
61                         type.Name = "Test1";
62                         Generate ();
63                         Assertion.AssertEquals (string.Format (CultureInfo.InvariantCulture,
64                                 "public class Test1 {{{0}}}{0}", writer.NewLine), Code);
65                 }
66
67                 [Test]
68                 public void AttributesAndTypeTest ()
69                 {
70                         type.Name = "Test1";
71
72                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
73                         attrDec.Name = "A";
74                         type.CustomAttributes.Add (attrDec);
75
76                         attrDec = new CodeAttributeDeclaration ();
77                         attrDec.Name = "B";
78                         type.CustomAttributes.Add (attrDec);
79
80                         Generate ();
81                         Assertion.AssertEquals (string.Format (CultureInfo.InvariantCulture,
82                                 "[A()]{0}"
83                                 + "[B()]{0}"
84                                 + "public class Test1 {{{0}"
85                                 + "}}{0}", writer.NewLine), Code);
86                 }
87
88                 [Test]
89                 public void EventMembersTypeTest1 ()
90                 {
91                         type.Name = "Test1";
92
93                         CodeMemberEvent evt = new CodeMemberEvent ();
94
95                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
96                         attrDec.Name = "A";
97                         evt.CustomAttributes.Add (attrDec);
98
99                         attrDec = new CodeAttributeDeclaration ();
100                         attrDec.Name = "B";
101                         evt.CustomAttributes.Add (attrDec);
102
103                         type.Members.Add (evt);
104
105                         Generate ();
106                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
107                                 "public class Test1 {{{0}"
108                                 + "    {0}"
109                                 + "    [A()]{0}"
110                                 + "    [B()]{0}"
111                                 + "    private event void ;{0}"
112                                 + "}}{0}", writer.NewLine), Code);
113                 }
114
115                 [Test]
116                 public void EventMembersTypeTest2 ()
117                 {
118                         type.Name = "Test1";
119
120                         CodeMemberEvent evt = new CodeMemberEvent ();
121                         evt.Name = "OnClick";
122                         evt.Attributes = MemberAttributes.Public;
123                         evt.Type = new CodeTypeReference (typeof (int));
124                         type.Members.Add (evt);
125
126                         Generate ();
127                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
128                                 "public class Test1 {{{0}"
129                                 + "    {0}"
130                                 + "    public event int OnClick;{0}"
131                                 + "}}{0}", writer.NewLine), Code);
132                 }
133
134                 [Test]
135                 public void FieldMembersTypeTest1 ()
136                 {
137                         type.Name = "Test1";
138
139                         CodeMemberField fld = new CodeMemberField ();
140
141                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
142                         attrDec.Name = "A";
143                         fld.CustomAttributes.Add (attrDec);
144
145                         attrDec = new CodeAttributeDeclaration ();
146                         attrDec.Name = "B";
147                         fld.CustomAttributes.Add (attrDec);
148
149                         type.Members.Add (fld);
150
151                         Generate ();
152                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
153                                 "public class Test1 {{{0}"
154                                 + "    {0}"
155                                 + "    [A()]{0}"
156                                 + "    [B()]{0}"
157                                 + "    private void ;{0}"
158                                 + "}}{0}", writer.NewLine), Code);
159                 }
160
161                 [Test]
162                 public void FieldMembersTypeTest2 ()
163                 {
164                         type.Name = "Test1";
165
166                         CodeMemberField fld = new CodeMemberField ();
167                         fld.Name = "Name";
168                         fld.Attributes = MemberAttributes.Public;
169                         fld.Type = new CodeTypeReference (typeof (int));
170                         type.Members.Add (fld);
171
172                         Generate ();
173                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
174                                 "public class Test1 {{{0}"
175                                 + "    {0}"
176                                 + "    public int Name;{0}"
177                                 + "}}{0}", writer.NewLine), Code);
178                 }
179
180                 [Test]
181                 public void PropertyMembersTypeTest1 ()
182                 {
183                         type.Name = "Test1";
184
185                         CodeMemberProperty property = new CodeMemberProperty ();
186
187                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
188                         attrDec.Name = "A";
189                         property.CustomAttributes.Add (attrDec);
190
191                         attrDec = new CodeAttributeDeclaration ();
192                         attrDec.Name = "B";
193                         property.CustomAttributes.Add (attrDec);
194
195                         type.Members.Add (property);
196
197                         Generate ();
198                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
199                                 "public class Test1 {{{0}"
200                                 + "    {0}"
201                                 + "    [A()]{0}"
202                                 + "    [B()]{0}"
203                                 + "    private void  {{{0}"
204                                 + "    }}{0}"
205                                 + "}}{0}", writer.NewLine), Code);
206                 }
207
208                 [Test]
209                 public void PropertyMembersTypeTest2 ()
210                 {
211                         type.Name = "Test1";
212
213                         CodeMemberProperty property = new CodeMemberProperty ();
214                         property.Name = "Name";
215                         property.Attributes = MemberAttributes.Public;
216                         property.Type = new CodeTypeReference (typeof (int));
217                         type.Members.Add (property);
218
219                         Generate ();
220                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
221                                 "public class Test1 {{{0}"
222                                 + "    {0}"
223                                 + "    public virtual int Name {{{0}"
224                                 + "    }}{0}"
225                                 + "}}{0}", writer.NewLine), Code);
226                 }
227
228                 [Test]
229                 public void PropertyMembersTypeGetOnly ()
230                 {
231                         type.Name = "Test1";
232
233                         CodeMemberProperty property = new CodeMemberProperty ();
234                         property.Name = "Name";
235                         property.Attributes = MemberAttributes.Family;
236                         property.HasGet = true;
237                         property.Type = new CodeTypeReference (typeof (int));
238                         type.Members.Add (property);
239
240                         Generate ();
241                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
242                                 "public class Test1 {{{0}"
243                                 + "    {0}"
244                                 + "    protected virtual int Name {{{0}"
245                                 + "        get {{{0}"
246                                 + "        }}{0}"
247                                 + "    }}{0}"
248                                 + "}}{0}", writer.NewLine), Code);
249                 }
250
251                 [Test]
252                 public void PropertyMembersTypeSetOnly ()
253                 {
254                         type.Name = "Test1";
255
256                         CodeMemberProperty property = new CodeMemberProperty ();
257                         property.Name = "Name";
258                         property.Attributes = MemberAttributes.FamilyOrAssembly;
259                         property.HasSet = true;
260                         property.Type = new CodeTypeReference (typeof (int));
261                         type.Members.Add (property);
262
263                         Generate ();
264                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
265                                 "public class Test1 {{{0}"
266                                 + "    {0}"
267                                 + "    protected internal int Name {{{0}"
268                                 + "        set {{{0}"
269                                 + "        }}{0}"
270                                 + "    }}{0}"
271                                 + "}}{0}", writer.NewLine), Code);
272                 }
273
274                 [Test]
275                 public void PropertyMembersTypeGetSet ()
276                 {
277                         type.Name = "Test1";
278
279                         CodeMemberProperty property = new CodeMemberProperty ();
280                         property.Name = "Name";
281                         property.Attributes = MemberAttributes.Assembly;
282                         property.HasGet = true;
283                         property.HasSet = true;
284                         property.Type = new CodeTypeReference (typeof (int));
285                         type.Members.Add (property);
286
287                         Generate ();
288                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
289                                 "public class Test1 {{{0}"
290                                 + "    {0}"
291 #if NET_2_0
292                                 + "    internal virtual int Name {{{0}"
293 #else
294                                 + "    internal int Name {{{0}"
295 #endif
296                                 + "        get {{{0}"
297                                 + "        }}{0}"
298                                 + "        set {{{0}"
299                                 + "        }}{0}"
300                                 + "    }}{0}"
301                                 + "}}{0}", writer.NewLine), Code);
302                 }
303
304                 [Test]
305                 public void PropertyMembersTypeFamilyAndAssembly ()
306                 {
307                         type.Name = "Test1";
308
309                         CodeMemberProperty property = new CodeMemberProperty ();
310                         property.Name = "Name";
311                         property.Attributes = MemberAttributes.FamilyAndAssembly;
312                         property.Type = new CodeTypeReference (typeof (int));
313
314                         type.Members.Add (property);
315
316                         Generate ();
317                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
318                                 "public class Test1 {{{0}"
319                                 + "    {0}"
320 #if NET_2_0
321                                 + "    internal int Name {{{0}"
322 #else
323                                 + "    /*FamANDAssem*/ internal int Name {{{0}"
324 #endif
325                                 + "    }}{0}"
326                                 + "}}{0}", writer.NewLine), Code);
327                 }
328
329                 [Test]
330                 public void MethodMembersTypeTest1 ()
331                 {
332                         type.Name = "Test1";
333
334                         CodeMemberMethod method = new CodeMemberMethod ();
335
336                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
337                         attrDec.Name = "A";
338                         method.CustomAttributes.Add (attrDec);
339
340                         attrDec = new CodeAttributeDeclaration ();
341                         attrDec.Name = "B";
342                         method.CustomAttributes.Add (attrDec);
343
344                         type.Members.Add (method);
345
346                         Generate ();
347                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
348                                 "public class Test1 {{{0}"
349                                 + "    {0}"
350                                 + "    [A()]{0}"
351                                 + "    [B()]{0}"
352                                 + "    private void () {{{0}"
353                                 + "    }}{0}"
354                                 + "}}{0}", writer.NewLine), Code);
355                 }
356
357                 [Test]
358                 public void MethodMembersTypeTest2 ()
359                 {
360                         type.Name = "Test1";
361
362                         CodeMemberMethod method = new CodeMemberMethod ();
363                         method.Name = "Something";
364                         method.Attributes = MemberAttributes.Public;
365                         method.ReturnType = new CodeTypeReference (typeof (int));
366
367                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
368                                 typeof (object), "value1");
369                         method.Parameters.Add (param);
370
371                         param = new CodeParameterDeclarationExpression (
372                                 typeof (object), "value2");
373                         param.Direction = FieldDirection.In;
374                         method.Parameters.Add (param);
375
376                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
377                         param.Direction = FieldDirection.Out;
378                         method.Parameters.Add (param);
379
380                         param = new CodeParameterDeclarationExpression (typeof (int), "count");
381                         param.Direction = FieldDirection.Ref;
382                         method.Parameters.Add (param);
383
384                         type.Members.Add (method);
385
386                         Generate ();
387                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
388                                 "public class Test1 {{{0}"
389                                 + "    {0}"
390                                 + "    public virtual int Something(object value1, object value2, out int index, ref int count) {{{0}"
391                                 + "    }}{0}"
392                                 + "}}{0}", writer.NewLine), Code);
393                 }
394
395                 [Test]
396                 public void MethodMembersTypeTest3 ()
397                 {
398                         type.Name = "Test1";
399
400                         CodeMemberMethod method = new CodeMemberMethod ();
401                         method.Name = "Something";
402                         method.Attributes = MemberAttributes.Public;
403                         method.ReturnType = new CodeTypeReference (typeof (int));
404
405                         // first parameter
406                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
407                                 typeof (object), "value");
408                         method.Parameters.Add (param);
409
410                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
411                         attrDec.Name = "A";
412                         param.CustomAttributes.Add (attrDec);
413
414                         attrDec = new CodeAttributeDeclaration ();
415                         attrDec.Name = "B";
416                         param.CustomAttributes.Add (attrDec);
417
418                         // second parameter
419                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
420                         param.Direction = FieldDirection.Out;
421                         method.Parameters.Add (param);
422
423                         attrDec = new CodeAttributeDeclaration ();
424                         attrDec.Name = "C";
425                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
426                                 new CodePrimitiveExpression (false)));
427                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
428                                 new CodePrimitiveExpression (true)));
429                         param.CustomAttributes.Add (attrDec);
430
431                         attrDec = new CodeAttributeDeclaration ();
432                         attrDec.Name = "D";
433                         param.CustomAttributes.Add (attrDec);
434
435                         type.Members.Add (method);
436
437                         Generate ();
438                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
439                                 "public class Test1 {{{0}"
440                                 + "    {0}"
441                                 + "    public virtual int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int index) {{{0}"
442                                 + "    }}{0}"
443                                 + "}}{0}", writer.NewLine), Code);
444                 }
445
446                 [Test]
447                 public void ConstructorAttributesTest ()
448                 {
449                         type.Name = "Test1";
450
451                         CodeConstructor ctor = new CodeConstructor ();
452
453                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
454                         attrDec.Name = "A";
455                         ctor.CustomAttributes.Add (attrDec);
456
457                         attrDec = new CodeAttributeDeclaration ();
458                         attrDec.Name = "B";
459                         ctor.CustomAttributes.Add (attrDec);
460
461                         type.Members.Add (ctor);
462
463                         Generate ();
464                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
465                                 "public class Test1 {{{0}"
466                                 + "    {0}"
467                                 + "    [A()]{0}"
468                                 + "    [B()]{0}"
469                                 + "    private Test1() {{{0}"
470                                 + "    }}{0}"
471                                 + "}}{0}", writer.NewLine), Code);
472                 }
473
474                 [Test]
475                 public void ConstructorParametersTest ()
476                 {
477                         type.Name = "Test1";
478
479                         CodeConstructor ctor = new CodeConstructor ();
480                         ctor.Name = "Whatever";
481                         ctor.Attributes = MemberAttributes.Public;
482
483                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
484                                 typeof (object), "value1");
485                         ctor.Parameters.Add (param);
486
487                         param = new CodeParameterDeclarationExpression (
488                                 typeof (object), "value2");
489                         param.Direction = FieldDirection.In;
490                         ctor.Parameters.Add (param);
491
492                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
493                         param.Direction = FieldDirection.Out;
494                         ctor.Parameters.Add (param);
495
496                         param = new CodeParameterDeclarationExpression (typeof (int), "count");
497                         param.Direction = FieldDirection.Ref;
498                         ctor.Parameters.Add (param);
499
500                         type.Members.Add (ctor);
501
502                         Generate ();
503                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
504                                 "public class Test1 {{{0}"
505                                 + "    {0}"
506                                 + "    public Test1(object value1, object value2, out int index, ref int count) {{{0}"
507                                 + "    }}{0}"
508                                 + "}}{0}", writer.NewLine), Code);
509                 }
510
511                 [Test]
512                 public void ConstructorParameterAttributesTest ()
513                 {
514                         type.Name = "Test1";
515
516                         CodeConstructor ctor = new CodeConstructor ();
517                         ctor.Name = "Something";
518                         ctor.Attributes = MemberAttributes.Public;
519
520                         // first parameter
521                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
522                                 typeof (object), "value");
523                         ctor.Parameters.Add (param);
524
525                         CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
526                         attrDec.Name = "A";
527                         param.CustomAttributes.Add (attrDec);
528
529                         attrDec = new CodeAttributeDeclaration ();
530                         attrDec.Name = "B";
531                         param.CustomAttributes.Add (attrDec);
532
533                         // second parameter
534                         param = new CodeParameterDeclarationExpression (typeof (int), "index");
535                         param.Direction = FieldDirection.Out;
536                         ctor.Parameters.Add (param);
537
538                         attrDec = new CodeAttributeDeclaration ();
539                         attrDec.Name = "C";
540                         attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
541                                 new CodePrimitiveExpression (false)));
542                         attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
543                                 new CodePrimitiveExpression (true)));
544                         param.CustomAttributes.Add (attrDec);
545
546                         attrDec = new CodeAttributeDeclaration ();
547                         attrDec.Name = "D";
548                         param.CustomAttributes.Add (attrDec);
549
550                         type.Members.Add (ctor);
551
552                         Generate ();
553                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
554                                 "public class Test1 {{{0}"
555                                 + "    {0}"
556                                 + "    public Test1([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int index) {{{0}"
557                                 + "    }}{0}"
558                                 + "}}{0}", writer.NewLine), Code);
559                 }
560
561                 [Test]
562                 public void BaseConstructorSingleArg ()
563                 {
564                         type.Name = "Test1";
565
566                         CodeConstructor ctor = new CodeConstructor ();
567                         ctor.Name = "Something";
568                         ctor.Attributes = MemberAttributes.Public;
569
570                         // first parameter
571                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
572                                 typeof (object), "value1");
573                         ctor.Parameters.Add (param);
574
575                         // second parameter
576                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
577                         param.Direction = FieldDirection.Out;
578                         ctor.Parameters.Add (param);
579
580                         // base ctor args
581                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
582
583                         type.Members.Add (ctor);
584
585                         Generate ();
586                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
587                                 "public class Test1 {{{0}"
588                                 + "    {0}"
589                                 + "    public Test1(object value1, out int value2) : {0}"
590                                 + "            base(value1) {{{0}"
591                                 + "    }}{0}"
592                                 + "}}{0}", writer.NewLine), Code);
593                 }
594
595                 [Test]
596                 public void BaseConstructorMultipleArgs ()
597                 {
598                         type.Name = "Test1";
599
600                         CodeConstructor ctor = new CodeConstructor ();
601                         ctor.Name = "Something";
602                         ctor.Attributes = MemberAttributes.Public;
603
604                         // first parameter
605                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
606                                 typeof (object), "value1");
607                         ctor.Parameters.Add (param);
608
609                         // second parameter
610                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
611                         param.Direction = FieldDirection.Out;
612                         ctor.Parameters.Add (param);
613
614                         // base ctor args
615                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
616                         ctor.BaseConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
617
618                         type.Members.Add (ctor);
619
620                         Generate ();
621                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
622                                 "public class Test1 {{{0}"
623                                 + "    {0}"
624                                 + "    public Test1(object value1, out int value2) : {0}"
625                                 + "            base(value1, value2) {{{0}"
626                                 + "    }}{0}"
627                                 + "}}{0}", writer.NewLine), Code);
628                 }
629
630                 [Test]
631                 public void ChainedConstructorSingleArg ()
632                 {
633                         type.Name = "Test1";
634
635                         CodeConstructor ctor = new CodeConstructor ();
636                         ctor.Name = "Something";
637                         ctor.Attributes = MemberAttributes.Public;
638
639                         // first parameter
640                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
641                                 typeof (object), "value1");
642                         ctor.Parameters.Add (param);
643
644                         // second parameter
645                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
646                         param.Direction = FieldDirection.Out;
647                         ctor.Parameters.Add (param);
648
649                         // chained ctor args
650                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
651
652                         type.Members.Add (ctor);
653
654                         Generate ();
655                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
656                                 "public class Test1 {{{0}"
657                                 + "    {0}"
658                                 + "    public Test1(object value1, out int value2) : {0}"
659                                 + "            this(value1) {{{0}"
660                                 + "    }}{0}"
661                                 + "}}{0}", writer.NewLine), Code);
662                 }
663
664                 [Test]
665                 public void ChainedConstructorMultipleArgs ()
666                 {
667                         type.Name = "Test1";
668
669                         CodeConstructor ctor = new CodeConstructor ();
670                         ctor.Name = "Something";
671                         ctor.Attributes = MemberAttributes.Public;
672
673                         // first parameter
674                         CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
675                                 typeof (object), "value1");
676                         ctor.Parameters.Add (param);
677
678                         // second parameter
679                         param = new CodeParameterDeclarationExpression (typeof (int), "value2");
680                         param.Direction = FieldDirection.Out;
681                         ctor.Parameters.Add (param);
682
683                         // chained ctor args
684                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
685                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
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 Test1(object value1, out int value2) : {0}"
694                                 + "            this(value1, value2) {{{0}"
695                                 + "    }}{0}"
696                                 + "}}{0}", writer.NewLine), Code);
697                 }
698
699                 [Test]
700                 public void BaseAndChainedConstructorArg ()
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                         // chained ctor args
722                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value1"));
723                         ctor.ChainedConstructorArgs.Add (new CodeVariableReferenceExpression ("value2"));
724
725                         type.Members.Add (ctor);
726
727                         Generate ();
728                         Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
729                                 "public class Test1 {{{0}"
730                                 + "    {0}"
731                                 + "    public Test1(object value1, out int value2) : {0}"
732                                 + "            base(value1) : {0}"
733                                 + "            this(value1, value2) {{{0}"
734                                 + "    }}{0}"
735                                 + "}}{0}", writer.NewLine), Code);
736                 }
737
738                 /*
739                 [Test]
740                 public void ReferencedTest ()
741                 {
742                         codeUnit.ReferencedAssemblies.Add ("System.dll");
743                         Generate ();
744                         Assertion.AssertEquals ("", Code);
745                 }
746                 */
747         }
748 }