Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeTypeReferenceTest.cs
1 //
2 // CodeTypeReferenceTest.cs - NUnit Test Cases for System.CodeDom.CodeTypeReference
3 //
4 // Authors:
5 //   Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 using System;
11 using System.CodeDom;
12 using System.Collections.Generic;
13
14 using NUnit.Framework;
15
16 namespace MonoTests.System.CodeDom
17 {
18         [TestFixture]
19         public class CodeTypeReferenceTest
20         {
21                 [Test]
22                 public void EmptyTypeName ()
23                 {
24                         CodeTypeReference reference = new CodeTypeReference (string.Empty);
25                         Assert.AreEqual (typeof (void).FullName, reference.BaseType);
26                         Assert.AreEqual (0, reference.ArrayRank);
27                         Assert.IsNull (reference.ArrayElementType);
28                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
29                         Assert.IsNotNull (reference.TypeArguments, "#5");
30                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
31                 }
32
33                 [Test]
34                 public void NullTypeName ()
35                 {
36                         CodeTypeReference reference = new CodeTypeReference ((string) null);
37                         Assert.AreEqual (typeof (void).FullName, reference.BaseType, "#1");
38                         Assert.AreEqual (0, reference.ArrayRank, "#2");
39                         Assert.IsNull (reference.ArrayElementType, "#3");
40                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
41                         Assert.IsNotNull (reference.TypeArguments, "#5");
42                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
43                 }
44
45                 [Test]
46                 [ExpectedException (typeof(ArgumentNullException))]
47                 public void NullType ()
48                 {
49                         new CodeTypeReference ((Type) null);
50                 }
51
52                 [Test]
53                 public void NullBaseType ()
54                 {
55                         CodeTypeReference reference = new CodeTypeReference ((string) null);
56                         Assert.AreEqual (typeof (void).FullName, reference.BaseType);
57                 }
58
59                 [Test]
60                 public void ZeroLengthBaseType ()
61                 {
62                         CodeTypeReference reference = new CodeTypeReference (string.Empty);
63                         Assert.AreEqual (typeof (void).FullName, reference.BaseType, "#1");
64                 }
65
66                 [Test]
67                 public void BaseTypeTest1 ()
68                 {
69                         CodeTypeReference reference = new CodeTypeReference ("A[B]");
70                         Assert.AreEqual ("A", reference.BaseType, "#1");
71                         Assert.AreEqual (0, reference.ArrayRank, "#2");
72                         Assert.IsNull (reference.ArrayElementType, "#3");
73                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
74                         Assert.IsNotNull (reference.TypeArguments, "#5");
75                         Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
76
77                         CodeTypeReference typeArgument = reference.TypeArguments[0];
78                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
79                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
80                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
81                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
82                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
83                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
84                 }
85
86                 [Test]
87                 public void BaseTypeTest2 ()
88                 {
89                         CodeTypeReference reference = new CodeTypeReference ("A[]");
90                         Assert.AreEqual ("A", reference.BaseType, "#1");
91                         Assert.AreEqual (1, reference.ArrayRank, "#2");
92                         Assert.IsNotNull (reference.ArrayElementType, "#3");
93                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
94                         Assert.IsNotNull (reference.TypeArguments, "#5");
95                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
96
97                         CodeTypeReference arrayElementType = reference.ArrayElementType;
98                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
99                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
100                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
101                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
102                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
103                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
104                 }
105
106                 [Test]
107                 public void BaseTypeTest3 ()
108                 {
109                         CodeTypeReference reference = new CodeTypeReference ("A[,]");
110                         Assert.AreEqual ("A", reference.BaseType, "#1");
111                         Assert.AreEqual (2, reference.ArrayRank, "#2");
112                         Assert.IsNotNull (reference.ArrayElementType, "#3");
113                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
114                         Assert.IsNotNull (reference.TypeArguments, "#5");
115                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
116
117                         CodeTypeReference arrayElementType = reference.ArrayElementType;
118                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
119                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
120                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
121                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
122                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
123                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
124                 }
125
126                 [Test]
127                 public void BaseTypeTest4 ()
128                 {
129                         CodeTypeReference reference = new CodeTypeReference ("A[,,]");
130                         Assert.AreEqual ("A", reference.BaseType, "#1");
131                         Assert.AreEqual (3, reference.ArrayRank, "#2");
132                         Assert.IsNotNull (reference.ArrayElementType, "#3");
133                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
134                         Assert.IsNotNull (reference.TypeArguments, "#5");
135                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
136
137                         CodeTypeReference arrayElementType = reference.ArrayElementType;
138                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
139                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
140                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
141                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
142                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
143                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
144                 }
145
146                 [Test]
147                 public void BaseTypeTest5 ()
148                 {
149                         CodeTypeReference reference = new CodeTypeReference ("A[B,C]");
150                         Assert.AreEqual ("A", reference.BaseType, "#1");
151                         Assert.AreEqual (0, reference.ArrayRank, "#2");
152                         Assert.IsNull (reference.ArrayElementType, "#3");
153                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
154                         Assert.IsNotNull (reference.TypeArguments, "#5");
155                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
156
157                         CodeTypeReference typeArgument = reference.TypeArguments[0];
158                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
159                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
160                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
161                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
162                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
163                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
164
165                         typeArgument = reference.TypeArguments[1];
166                         Assert.AreEqual ("C", typeArgument.BaseType, "#13");
167                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
168                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
169                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
170                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
171                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
172                 }
173
174                 [Test]
175                 public void BaseTypeTest6 ()
176                 {
177                         CodeTypeReference reference = new CodeTypeReference ("A[");
178                         Assert.AreEqual ("A[", reference.BaseType, "#1");
179                         Assert.AreEqual (0, reference.ArrayRank, "#2");
180                         Assert.IsNull (reference.ArrayElementType, "#3");
181                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
182                         Assert.IsNotNull (reference.TypeArguments, "#5");
183                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
184                 }
185
186                 [Test]
187                 public void BaseTypeTest7 ()
188                 {
189                         CodeTypeReference reference = new CodeTypeReference ("A[,B,,C]");
190                         Assert.AreEqual ("A", reference.BaseType, "#1");
191                         Assert.AreEqual (0, reference.ArrayRank, "#2");
192                         Assert.IsNull (reference.ArrayElementType, "#3");
193                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
194                         Assert.IsNotNull (reference.TypeArguments, "#5");
195                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
196
197                         CodeTypeReference typeArgument = reference.TypeArguments[0];
198                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
199                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
200                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
201                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
202                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
203                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
204
205                         typeArgument = reference.TypeArguments[1];
206                         Assert.AreEqual ("C", typeArgument.BaseType, "#13");
207                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
208                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
209                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
210                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
211                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
212                 }
213
214                 [Test]
215                 // CodeTypeReference should parse basetype from right to left in 2.0 
216                 // profile
217                 [Category ("NotWorking")]
218                 public void BaseTypeTest8 ()
219                 {
220                         CodeTypeReference reference = new CodeTypeReference ("A[,,][,]");
221                         Assert.AreEqual ("A", reference.BaseType, "#1");
222                         Assert.AreEqual (3, reference.ArrayRank, "#2");
223                         Assert.IsNotNull (reference.ArrayElementType, "#3");
224
225                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
226                         Assert.IsNotNull (reference.TypeArguments, "#5");
227                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
228
229                         CodeTypeReference arrayElementType = reference.ArrayElementType;
230                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
231                         Assert.AreEqual (2, arrayElementType.ArrayRank, "#8");
232                         Assert.IsNotNull (arrayElementType.ArrayElementType, "#9");
233                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
234                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
235                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
236
237                         arrayElementType = arrayElementType.ArrayElementType;
238                         Assert.AreEqual ("A", arrayElementType.BaseType, "#13");
239                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#14");
240                         Assert.IsNull (arrayElementType.ArrayElementType, "#15");
241                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#16");
242                         Assert.IsNotNull (arrayElementType.TypeArguments, "#17");
243                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#18");
244                 }
245
246                 [Test]
247                 // CodeTypeReference should parse basetype from right to left in 2.0 
248                 // profile
249                 [Category ("NotWorking")]
250                 public void BaseTypeTest9 ()
251                 {
252                         CodeTypeReference reference = new CodeTypeReference ("A[B,,D][,]");
253                         Assert.AreEqual ("A`2", reference.BaseType, "#1");
254                         Assert.AreEqual (2, reference.ArrayRank, "#2");
255                         Assert.IsNotNull (reference.ArrayElementType, "#3");
256
257                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
258                         Assert.IsNotNull (reference.TypeArguments, "#5");
259                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
260
261                         CodeTypeReference arrayElementType = reference.ArrayElementType;
262                         Assert.AreEqual ("A`2", arrayElementType.BaseType, "#7");
263                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
264                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
265                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
266                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
267                         Assert.AreEqual (2, arrayElementType.TypeArguments.Count, "#12");
268
269                         CodeTypeReference typeArgument = reference.TypeArguments[0];
270                         Assert.AreEqual ("B", typeArgument.BaseType, "#13");
271                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
272                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
273                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
274                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
275                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
276
277                         typeArgument = reference.TypeArguments[1];
278                         Assert.AreEqual ("D", typeArgument.BaseType, "#19");
279                         Assert.AreEqual (0, typeArgument.ArrayRank, "#20");
280                         Assert.IsNull (typeArgument.ArrayElementType, "#21");
281                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#22");
282                         Assert.IsNotNull (typeArgument.TypeArguments, "#23");
283                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#24");
284                 }
285
286                 [Test]
287                 public void Defaults ()
288                 {
289                         CodeTypeReference reference = new CodeTypeReference ();
290
291                         Assert.IsNull (reference.ArrayElementType, "#1");
292                         Assert.AreEqual (0, reference.ArrayRank, "#2");
293                         Assert.AreEqual (string.Empty, reference.BaseType, "#3");
294                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
295                         Assert.IsNotNull (reference.TypeArguments, "#5");
296                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
297                 }
298
299                 [Test]
300                 public void CodeTypeParameter1 ()
301                 {
302                         CodeTypeReference reference = new CodeTypeReference(
303                                 new CodeTypeParameter ("A"));
304                         Assert.AreEqual ("A", reference.BaseType, "#1");
305                         Assert.AreEqual (0, reference.ArrayRank, "#2");
306                         Assert.IsNull (reference.ArrayElementType, "#3");
307                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
308                         Assert.IsNotNull (reference.TypeArguments, "#5");
309                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
310                 }
311         
312                 [Test]
313                 public void CodeTypeParameter2 ()
314                 {
315                         CodeTypeReference reference = new CodeTypeReference (
316                                 new CodeTypeParameter ("A[B]"));
317                         Assert.AreEqual ("A", reference.BaseType, "#1");
318                         Assert.AreEqual (0, reference.ArrayRank, "#2");
319                         Assert.IsNull (reference.ArrayElementType, "#3");
320                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
321                         Assert.IsNotNull (reference.TypeArguments, "#5");
322                         Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
323
324                         CodeTypeReference typeArgument = reference.TypeArguments[0];
325                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
326                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
327                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
328                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
329                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
330                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
331                 }
332
333                 [Test]
334                 public void CodeTypeParameter3 ()
335                 {
336                         CodeTypeReference reference = new CodeTypeReference (
337                                 new CodeTypeParameter ("A[B, C]"));
338                         Assert.AreEqual ("A", reference.BaseType, "#1");
339                         Assert.AreEqual (0, reference.ArrayRank, "#2");
340                         Assert.IsNull (reference.ArrayElementType, "#3");
341                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
342                         Assert.IsNotNull (reference.TypeArguments, "#5");
343                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
344
345                         CodeTypeReference typeArgument = reference.TypeArguments[0];
346                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
347                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
348                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
349                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
350                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
351                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
352
353                         typeArgument = reference.TypeArguments[1];
354                         Assert.AreEqual (" C", typeArgument.BaseType, "#13");
355                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
356                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
357                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
358                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
359                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
360                 }
361
362                 [Test]
363                 public void CodeTypeParameter4 ()
364                 {
365                         CodeTypeReference reference = new CodeTypeReference (
366                                 new CodeTypeParameter ("A[]"));
367                         Assert.AreEqual ("A", reference.BaseType, "#1");
368                         Assert.AreEqual (1, reference.ArrayRank, "#2");
369                         Assert.IsNotNull (reference.ArrayElementType, "#3");
370                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
371                         Assert.IsNotNull (reference.TypeArguments, "#5");
372                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
373
374                         CodeTypeReference arrayElementType = reference.ArrayElementType;
375                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
376                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
377                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
378                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
379                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
380                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
381                 }
382
383                 [Test]
384                 public void CodeTypeParameter5 ()
385                 {
386                         CodeTypeReference reference = new CodeTypeReference (
387                                 new CodeTypeParameter ("A[,"));
388                         Assert.AreEqual ("A[,", reference.BaseType, "#1");
389                         Assert.AreEqual (0, reference.ArrayRank, "#2");
390                         Assert.IsNull (reference.ArrayElementType, "#3");
391                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
392                         Assert.IsNotNull (reference.TypeArguments, "#5");
393                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
394                 }
395
396                 [Test]
397                 public void GenericTypeTest1 () {
398                         CodeTypeReference reference = new CodeTypeReference (
399                                 typeof (Dictionary<int,string>));
400                         Assert.AreEqual ("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
401                         Assert.AreEqual (0, reference.ArrayRank, "#2");
402                         Assert.IsNull (reference.ArrayElementType, "#3");
403                         Assert.AreEqual (0, (int) reference.Options, "#4");
404                         Assert.IsNotNull (reference.TypeArguments, "#5");
405                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
406
407                         CodeTypeReference typeArgument = reference.TypeArguments[0];
408                         Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
409                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
410                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
411                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
412                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
413                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
414
415                         typeArgument = reference.TypeArguments[1];
416                         Assert.AreEqual ("System.String", typeArgument.BaseType, "#13");
417                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
418                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
419                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
420                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
421                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
422                 }
423
424                 [Test]
425                 public void GenericTypeTest2 () {
426                         CodeTypeReference reference = new CodeTypeReference (
427                                 typeof (Dictionary<List<int>, string>));
428                         Assert.AreEqual ("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
429                         Assert.AreEqual (0, reference.ArrayRank, "#2");
430                         Assert.IsNull (reference.ArrayElementType, "#3");
431                         Assert.AreEqual (0, (int) reference.Options, "#4");
432                         Assert.IsNotNull (reference.TypeArguments, "#5");
433                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
434
435                         CodeTypeReference typeArgument = reference.TypeArguments[0];
436                         Assert.AreEqual ("System.Collections.Generic.List`1", typeArgument.BaseType, "#7");
437                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
438                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
439                         Assert.AreEqual (0, (int) typeArgument.Options, "#10");
440                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
441                         Assert.AreEqual (1, typeArgument.TypeArguments.Count, "#12");
442
443                         CodeTypeReference nestedTypeArgument = typeArgument.TypeArguments[0];
444                         Assert.AreEqual ("System.Int32", nestedTypeArgument.BaseType, "#13");
445                         Assert.AreEqual (0, nestedTypeArgument.ArrayRank, "#14");
446                         Assert.IsNull (nestedTypeArgument.ArrayElementType, "#15");
447                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
448                         Assert.IsNotNull (nestedTypeArgument.TypeArguments, "#17");
449                         Assert.AreEqual (0, nestedTypeArgument.TypeArguments.Count, "#18");
450
451                         typeArgument = reference.TypeArguments[1];
452                         Assert.AreEqual ("System.String", typeArgument.BaseType, "#19");
453                         Assert.AreEqual (0, typeArgument.ArrayRank, "#20");
454                         Assert.IsNull (typeArgument.ArrayElementType, "#21");
455                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#22");
456                         Assert.IsNotNull (typeArgument.TypeArguments, "#23");
457                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#24");
458                 }
459
460                 [Test]
461                 public void GenericTypeTest3 () 
462                 {
463                         CodeTypeReference reference = new CodeTypeReference (
464                                 "System.Nullable", new CodeTypeReference (typeof (int)));
465                         Assert.AreEqual ("System.Nullable`1", reference.BaseType, "#1");
466                         Assert.AreEqual (0, reference.ArrayRank, "#2");
467                         Assert.IsNull (reference.ArrayElementType, "#3");
468                         Assert.AreEqual (0, (int) reference.Options, "#4");
469                         Assert.IsNotNull (reference.TypeArguments, "#5");
470                         Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
471
472                         CodeTypeReference typeArgument = reference.TypeArguments[0];
473                         Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
474                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
475                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
476                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
477                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
478                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
479                 }
480
481                 [Test]
482                 public void GenericTypeTest4 () 
483                 {
484                         CodeTypeReference reference = new CodeTypeReference (
485                                 "System.Nullable`1", new CodeTypeReference (typeof (int)));
486                         Assert.AreEqual ("System.Nullable`1", reference.BaseType, "#1");
487                         Assert.AreEqual (0, reference.ArrayRank, "#2");
488                         Assert.IsNull (reference.ArrayElementType, "#3");
489                         Assert.AreEqual (0, (int) reference.Options, "#4");
490                         Assert.IsNotNull (reference.TypeArguments, "#5");
491                         Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
492
493                         CodeTypeReference typeArgument = reference.TypeArguments[0];
494                         Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
495                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
496                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
497                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
498                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
499                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
500                 }
501
502                 [Test]
503                 public void GenericTypeTest5 () 
504                 {
505                         CodeTypeReference reference = new CodeTypeReference (
506                                 typeof (int?).GetGenericTypeDefinition ());
507                         Assert.AreEqual ("System.Nullable`1", reference.BaseType, "#1");
508                         Assert.AreEqual (0, reference.ArrayRank, "#2");
509                         Assert.IsNull (reference.ArrayElementType, "#3");
510                         Assert.AreEqual (0, (int) reference.Options, "#4");
511                         Assert.IsNotNull (reference.TypeArguments, "#5");
512                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
513                 }
514
515                 [Test (Description="Bug #523341")]
516                 public void GenericTypeTest6 ()
517                 {
518                         CodeTypeReference reference = new CodeTypeReference ("System.Collections.List<System.Globalization.CultureInfo[]>");
519                         Assert.AreEqual ("System.Collections.List<System.Globalization.CultureInfo[]>", reference.BaseType, "#1");
520                         Assert.AreEqual (0, reference.ArrayRank, "#2");
521                         Assert.IsNull (reference.ArrayElementType, "#3");
522                         Assert.AreEqual (0, (int) reference.Options, "#4");
523                         Assert.IsNotNull (reference.TypeArguments, "#5");
524                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
525                 }
526
527                 // bug #76535
528                 [Test]
529                 public void BaseType_ArrayElementType ()
530                 {
531                         CodeTypeReference ctr = new CodeTypeReference ("System.Int32");
532                         Assert.IsNull (ctr.ArrayElementType, "#1");
533                         Assert.AreEqual (0, ctr.ArrayRank, "#2");
534                         ctr.ArrayElementType = new CodeTypeReference ("System.String");
535                         Assert.IsNotNull (ctr.ArrayElementType, "#3");
536                         Assert.AreEqual (0, ctr.ArrayRank, "#4");
537                         Assert.AreEqual ("System.Int32", ctr.BaseType, "#4");
538                         ctr.ArrayRank = -1;
539                         Assert.AreEqual (-1, ctr.ArrayRank, "#5");
540                         Assert.AreEqual ("System.Int32", ctr.BaseType, "#6");
541                         ctr.ArrayRank = 1;
542                         Assert.AreEqual (1, ctr.ArrayRank, "#7");
543                         Assert.AreEqual ("System.String", ctr.BaseType, "#8");
544                 }
545
546                 [Test]
547                 public void Null_ArrayElementType ()
548                 {
549                         CodeTypeReference ctr = new CodeTypeReference ((string) null, 0);
550                         Assert.IsNotNull (ctr.ArrayElementType, "#1");
551                         Assert.AreEqual (typeof(void).FullName, ctr.ArrayElementType.BaseType, "#2");
552                         Assert.AreEqual (0, ctr.ArrayRank, "#3");
553                         Assert.AreEqual (string.Empty, ctr.BaseType, "#4");
554                         ctr.ArrayRank = 1;
555                         Assert.AreEqual (1, ctr.ArrayRank, "#5");
556                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#6");
557
558                         ctr = new CodeTypeReference ((string) null, 1);
559                         Assert.IsNotNull (ctr.ArrayElementType, "#7");
560                         Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#8");
561                         Assert.AreEqual (1, ctr.ArrayRank, "#9");
562                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#10");
563
564                         ctr = new CodeTypeReference ((CodeTypeReference) null, 0);
565                         Assert.IsNull (ctr.ArrayElementType, "#11");
566                         Assert.AreEqual (0, ctr.ArrayRank, "#12");
567                         Assert.AreEqual (string.Empty, ctr.BaseType, "#13");
568                         ctr.ArrayRank = 1;
569                         Assert.AreEqual (1, ctr.ArrayRank, "#14");
570                         Assert.AreEqual (string.Empty, ctr.BaseType, "#15");
571
572                         ctr = new CodeTypeReference ((CodeTypeReference) null, 1);
573                         Assert.IsNull (ctr.ArrayElementType, "#16");
574                         Assert.AreEqual (1, ctr.ArrayRank, "#17");
575                         Assert.AreEqual (string.Empty, ctr.BaseType, "#18");
576                 }
577
578                 [Test]
579                 public void Empty_ArrayElementType ()
580                 {
581                         CodeTypeReference ctr = new CodeTypeReference (string.Empty, 0);
582                         Assert.IsNotNull (ctr.ArrayElementType, "#1");
583                         Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#2");
584                         Assert.AreEqual (0, ctr.ArrayRank, "#3");
585                         Assert.AreEqual (string.Empty, ctr.BaseType, "#4");
586                         ctr.ArrayRank = 1;
587                         Assert.AreEqual (1, ctr.ArrayRank, "#5");
588                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#6");
589
590                         ctr = new CodeTypeReference (string.Empty, 1);
591                         Assert.IsNotNull (ctr.ArrayElementType, "#7");
592                         Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#8");
593                         Assert.AreEqual (1, ctr.ArrayRank, "#9");
594                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#10");
595                 }
596         }
597 }