Merge pull request #273 from joncham/bug-getpid
[mono.git] / mcs / class / System.Xaml / Test / System.Xaml / XamlLanguageTest.cs
1 //
2 // Copyright (C) 2010 Novell Inc. http://novell.com
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 using System;
24 using System.Collections;
25 using System.Collections.Generic;
26 using System.ComponentModel;
27 using System.Linq;
28 using System.Reflection;
29 using System.Windows.Markup;
30 using System.Xaml;
31 using System.Xaml.Schema;
32 using System.Xml;
33 using NUnit.Framework;
34
35 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
36
37 namespace MonoTests.System.Xaml
38 {
39         [TestFixture]
40         public class XamlLanguageTest
41         {
42                 [Test]
43                 public void XamlNamepaces ()
44                 {
45                         var l = XamlLanguage.XamlNamespaces;
46                         Assert.AreEqual (1, l.Count, "#1");
47                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [0], "#2");
48                 }
49
50                 [Test]
51                 public void XmlNamepaces ()
52                 {
53                         var l = XamlLanguage.XmlNamespaces;
54                         Assert.AreEqual (1, l.Count, "#1");
55                         Assert.AreEqual (XamlLanguage.Xml1998Namespace, l [0], "#2");
56                 }
57
58                 [Test]
59                 public void AllDirectives ()
60                 {
61                         var l = XamlLanguage.AllDirectives;
62                         Assert.AreEqual (24, l.Count, "count");
63                         Assert.IsTrue (l.Contains (XamlLanguage.Arguments), "#0");
64                         Assert.IsTrue (l.Contains (XamlLanguage.AsyncRecords), "#1");
65                         Assert.IsTrue (l.Contains (XamlLanguage.Base), "#2");
66                         Assert.IsTrue (l.Contains (XamlLanguage.Class), "#3");
67                         Assert.IsTrue (l.Contains (XamlLanguage.ClassAttributes), "#4");
68                         Assert.IsTrue (l.Contains (XamlLanguage.ClassModifier), "#5");
69                         Assert.IsTrue (l.Contains (XamlLanguage.Code), "#6");
70                         Assert.IsTrue (l.Contains (XamlLanguage.ConnectionId), "#7");
71                         Assert.IsTrue (l.Contains (XamlLanguage.FactoryMethod), "#8");
72                         Assert.IsTrue (l.Contains (XamlLanguage.FieldModifier), "#9");
73                         Assert.IsTrue (l.Contains (XamlLanguage.Initialization), "#10");
74                         Assert.IsTrue (l.Contains (XamlLanguage.Items), "#11");
75                         Assert.IsTrue (l.Contains (XamlLanguage.Key), "#12");
76                         Assert.IsTrue (l.Contains (XamlLanguage.Lang), "#13");
77                         Assert.IsTrue (l.Contains (XamlLanguage.Members), "#14");
78                         Assert.IsTrue (l.Contains (XamlLanguage.Name), "#15");
79                         Assert.IsTrue (l.Contains (XamlLanguage.PositionalParameters), "#16");
80                         Assert.IsTrue (l.Contains (XamlLanguage.Space), "#17");
81                         Assert.IsTrue (l.Contains (XamlLanguage.Subclass), "#18");
82                         Assert.IsTrue (l.Contains (XamlLanguage.SynchronousMode), "#19");
83                         Assert.IsTrue (l.Contains (XamlLanguage.Shared), "#20");
84                         Assert.IsTrue (l.Contains (XamlLanguage.TypeArguments), "#21");
85                         Assert.IsTrue (l.Contains (XamlLanguage.Uid), "#22");
86                         Assert.IsTrue (l.Contains (XamlLanguage.UnknownContent), "#23");
87                 }
88
89                 [Test]
90                 public void AllTypes ()
91                 {
92                         var l = XamlLanguage.AllTypes;
93                         Assert.AreEqual (21, l.Count, "count");
94                         Assert.IsTrue (l.Contains (XamlLanguage.Array), "#0");
95                         Assert.IsTrue (l.Contains (XamlLanguage.Boolean), "#1");
96                         Assert.IsTrue (l.Contains (XamlLanguage.Byte), "#2");
97                         Assert.IsTrue (l.Contains (XamlLanguage.Char), "#3");
98                         Assert.IsTrue (l.Contains (XamlLanguage.Decimal), "#4");
99                         Assert.IsTrue (l.Contains (XamlLanguage.Double), "#5");
100                         Assert.IsTrue (l.Contains (XamlLanguage.Int16), "#6");
101                         Assert.IsTrue (l.Contains (XamlLanguage.Int32), "#7");
102                         Assert.IsTrue (l.Contains (XamlLanguage.Int64), "#8");
103                         Assert.IsTrue (l.Contains (XamlLanguage.Member), "#9");
104                         Assert.IsTrue (l.Contains (XamlLanguage.Null), "#10");
105                         Assert.IsTrue (l.Contains (XamlLanguage.Object), "#11");
106                         Assert.IsTrue (l.Contains (XamlLanguage.Property), "#12");
107                         Assert.IsTrue (l.Contains (XamlLanguage.Reference), "#13");
108                         Assert.IsTrue (l.Contains (XamlLanguage.Single), "#14");
109                         Assert.IsTrue (l.Contains (XamlLanguage.Static), "#15");
110                         Assert.IsTrue (l.Contains (XamlLanguage.String), "#16");
111                         Assert.IsTrue (l.Contains (XamlLanguage.TimeSpan), "#17");
112                         Assert.IsTrue (l.Contains (XamlLanguage.Type), "#18");
113                         Assert.IsTrue (l.Contains (XamlLanguage.Uri), "#19");
114                         Assert.IsTrue (l.Contains (XamlLanguage.XData), "#20");
115                 }
116
117                 // directive property details
118
119                 [Test]
120                 public void Arguments ()
121                 {
122                         var d = XamlLanguage.Arguments;
123                         TestXamlDirectiveCommon (d, "Arguments", AllowedMemberLocations.Any, typeof (List<object>));
124                 }
125
126                 [Test]
127                 public void AsyncRecords ()
128                 {
129                         var d = XamlLanguage.AsyncRecords;
130                         TestXamlDirectiveCommon (d, "AsyncRecords", AllowedMemberLocations.Attribute, typeof (string));
131                 }
132
133                 [Test]
134                 public void Base ()
135                 {
136                         var d = XamlLanguage.Base;
137                         TestXamlDirectiveCommon (d, "base", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string));
138                 }
139
140                 [Test]
141                 public void Class ()
142                 {
143                         var d = XamlLanguage.Class;
144                         TestXamlDirectiveCommon (d, "Class", AllowedMemberLocations.Attribute, typeof (string));
145                 }
146
147                 [Test]
148                 public void ClassAttributes ()
149                 {
150                         var d = XamlLanguage.ClassAttributes;
151                         TestXamlDirectiveCommon (d, "ClassAttributes", AllowedMemberLocations.MemberElement, typeof (List<Attribute>));
152                 }
153
154                 [Test]
155                 public void ClassModifier ()
156                 {
157                         var d = XamlLanguage.ClassModifier;
158                         TestXamlDirectiveCommon (d, "ClassModifier", AllowedMemberLocations.Attribute, typeof (string));
159                 }
160
161                 [Test]
162                 public void Code ()
163                 {
164                         var d = XamlLanguage.Code;
165                         TestXamlDirectiveCommon (d, "Code", AllowedMemberLocations.Attribute, typeof (string));
166                 }
167
168                 [Test]
169                 public void ConnectionId ()
170                 {
171                         var d = XamlLanguage.ConnectionId;
172                         TestXamlDirectiveCommon (d, "ConnectionId", AllowedMemberLocations.Any, typeof (string));
173                 }
174
175                 [Test]
176                 public void FactoryMethod ()
177                 {
178                         var d = XamlLanguage.FactoryMethod;
179                         TestXamlDirectiveCommon (d, "FactoryMethod", AllowedMemberLocations.Any, typeof (string));
180                 }
181
182                 [Test]
183                 public void FieldModifier ()
184                 {
185                         var d = XamlLanguage.FieldModifier;
186                         TestXamlDirectiveCommon (d, "FieldModifier", AllowedMemberLocations.Attribute, typeof (string));
187                 }
188
189                 [Test]
190                 public void Initialization ()
191                 {
192                         var d = XamlLanguage.Initialization;
193                         // weird name
194                         TestXamlDirectiveCommon (d, "_Initialization", AllowedMemberLocations.Any, typeof (object));
195                 }
196                 
197                 [Test]
198                 [ExpectedException (typeof (NotSupportedException))]
199                 public void InitializationGetValue ()
200                 {
201                         XamlLanguage.Initialization.Invoker.GetValue ("foo");
202                 }
203
204                 [Test]
205                 public void Items ()
206                 {
207                         var d = XamlLanguage.Items;
208                         // weird name
209                         TestXamlDirectiveCommon (d, "_Items", AllowedMemberLocations.Any, typeof (List<object>));
210                 }
211
212                 [Test]
213                 public void Key ()
214                 {
215                         var d = XamlLanguage.Key;
216                         TestXamlDirectiveCommon (d, "Key", AllowedMemberLocations.Any, typeof (object));
217                 }
218
219                 [Test]
220                 public void Lang ()
221                 {
222                         var d = XamlLanguage.Lang;
223                         TestXamlDirectiveCommon (d, "lang", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string));
224                 }
225
226                 [Test]
227                 public void Members ()
228                 {
229                         var d = XamlLanguage.Members;
230                         TestXamlDirectiveCommon (d, "Members", AllowedMemberLocations.MemberElement, typeof (List<MemberDefinition>));
231                 }
232
233                 [Test]
234                 public void Name ()
235                 {
236                         var d = XamlLanguage.Name;
237                         TestXamlDirectiveCommon (d, "Name", AllowedMemberLocations.Attribute, typeof (string));
238                 }
239
240                 [Test]
241                 public void PositionalParameters ()
242                 {
243                         var d = XamlLanguage.PositionalParameters;
244                         // weird name
245                         TestXamlDirectiveCommon (d, "_PositionalParameters", AllowedMemberLocations.Any, typeof (List<object>));
246                         // LAMESPEC: In [MS-XAML-2009] AllowedLocations is None, unlike this Any value.
247                 }
248
249                 [Test]
250                 public void Subclass ()
251                 {
252                         var d = XamlLanguage.Subclass;
253                         TestXamlDirectiveCommon (d, "Subclass", AllowedMemberLocations.Attribute, typeof (string));
254                 }
255
256                 [Test]
257                 public void SynchronousMode ()
258                 {
259                         var d = XamlLanguage.SynchronousMode;
260                         TestXamlDirectiveCommon (d, "SynchronousMode", AllowedMemberLocations.Attribute, typeof (string));
261                 }
262
263                 [Test]
264                 public void Shared ()
265                 {
266                         var d = XamlLanguage.Shared;
267                         TestXamlDirectiveCommon (d, "Shared", AllowedMemberLocations.Attribute, typeof (string));
268                 }
269
270                 [Test]
271                 public void Space ()
272                 {
273                         var d = XamlLanguage.Space;
274                         TestXamlDirectiveCommon (d, "space", XamlLanguage.Xml1998Namespace, AllowedMemberLocations.Attribute, typeof (string));
275                 }
276
277                 [Test]
278                 public void TypeArguments ()
279                 {
280                         var d = XamlLanguage.TypeArguments;
281                         TestXamlDirectiveCommon (d, "TypeArguments", AllowedMemberLocations.Attribute, typeof (string));
282                 }
283
284                 [Test]
285                 public void Uid ()
286                 {
287                         var d = XamlLanguage.Uid;
288                         TestXamlDirectiveCommon (d, "Uid", AllowedMemberLocations.Attribute, typeof (string));
289                 }
290
291                 [Test]
292                 public void UnknownContent ()
293                 {
294                         var d = XamlLanguage.UnknownContent;
295                         // weird name
296                         TestXamlDirectiveCommon (d, "_UnknownContent", XamlLanguage.Xaml2006Namespace, AllowedMemberLocations.MemberElement, typeof (object), true);
297                 }
298
299                 void TestXamlDirectiveCommon (XamlDirective d, string name, AllowedMemberLocations allowedLocation, Type type)
300                 {
301                         TestXamlDirectiveCommon (d, name, XamlLanguage.Xaml2006Namespace, allowedLocation, type);
302                 }
303
304                 void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMemberLocations allowedLocation, Type type)
305                 {
306                         TestXamlDirectiveCommon (d, name, ns, allowedLocation, type, false);
307                 }
308
309                 void TestXamlDirectiveCommon (XamlDirective d, string name, string ns, AllowedMemberLocations allowedLocation, Type type, bool isUnknown)
310                 {
311                         Assert.AreEqual (allowedLocation, d.AllowedLocation, "#1");
312                         Assert.IsNull (d.DeclaringType, "#2");
313                         Assert.IsNotNull (d.Invoker, "#3");
314                         Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2");
315                         Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3");
316                         Assert.AreEqual (isUnknown, d.IsUnknown, "#4");
317                         Assert.IsTrue (d.IsReadPublic, "#5");
318                         Assert.IsTrue (d.IsWritePublic, "#6");
319                         Assert.AreEqual (name, d.Name, "#7");
320                         Assert.IsTrue (d.IsNameValid, "#8");
321                         Assert.AreEqual (ns, d.PreferredXamlNamespace, "#9");
322                         Assert.IsNull (d.TargetType, "#10");
323                         Assert.IsNotNull (d.Type, "#11");
324                         Assert.AreEqual (type, d.Type.UnderlyingType, "#11-2");
325
326                         // .NET returns StringConverter, but it should not premise that key must be string (it is object)
327                         if (name == "Key")
328                                 ;//Assert.IsNull (d.TypeConverter, "#12")
329                         else if (type.IsGenericType || name == "_Initialization" || name == "_UnknownContent")
330                                 Assert.IsNull (d.TypeConverter, "#12");
331                         else
332                                 Assert.IsNotNull (d.TypeConverter, "#12");
333                         Assert.IsNull (d.ValueSerializer, "#13");
334                         Assert.IsNull (d.DeferringLoader, "#14");
335                         Assert.IsNull (d.UnderlyingMember, "#15");
336                         Assert.IsFalse (d.IsReadOnly, "#16");
337                         Assert.IsFalse (d.IsWriteOnly, "#17");
338                         Assert.IsFalse (d.IsAttachable, "#18");
339                         Assert.IsFalse (d.IsEvent, "#19");
340                         Assert.IsTrue (d.IsDirective, "#20");
341                         Assert.IsNotNull (d.DependsOn, "#21");
342                         Assert.AreEqual (0, d.DependsOn.Count, "#21-2");
343                         Assert.IsFalse (d.IsAmbient, "#22");
344                         Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23");
345                 }
346
347                 // type property details
348
349                 // extension types
350                 [Test]
351                 public void Array ()
352                 {
353                         var t = XamlLanguage.Array;
354                         TestXamlTypeExtension (t, "ArrayExtension", typeof (ArrayExtension), typeof (Array), true);
355                         Assert.IsNotNull (t.ContentProperty, "#27");
356                         Assert.AreEqual ("Items", t.ContentProperty.Name, "#27-2");
357
358                         var l = t.GetAllMembers ().ToArray ();
359                         Assert.AreEqual (2, l.Length, "#31");
360                         var items = l.First (m => m.Name == "Items");
361                         Assert.IsFalse (items == XamlLanguage.Items, "#31-2");
362                         l.First (m => m.Name == "Type");
363
364                         l = t.GetAllAttachableMembers ().ToArray ();
365                         Assert.AreEqual (0, l.Length, "#32");
366                 }
367
368                 [Test]
369                 public void Array_Items ()
370                 {
371                         var m = XamlLanguage.Array.GetMember ("Items");
372                         TestMemberCommon (m, "Items", typeof (IList), typeof (ArrayExtension), false);
373                 }
374
375                 [Test]
376                 public void Array_Type ()
377                 {
378                         var m = XamlLanguage.Array.GetMember ("Type");
379                         TestMemberCommon (m, "Type", typeof (Type), typeof (ArrayExtension), true);
380                 }
381
382                 [Test]
383                 public void Null ()
384                 {
385                         var t = XamlLanguage.Null;
386                         TestXamlTypeExtension (t, "NullExtension", typeof (NullExtension), typeof (object), true);
387                         Assert.IsNull (t.ContentProperty, "#27");
388
389                         var l = t.GetAllMembers ().ToArray ();
390                         Assert.AreEqual (0, l.Length, "#31");
391
392                         l = t.GetAllAttachableMembers ().ToArray ();
393                         Assert.AreEqual (0, l.Length, "#32");
394                 }
395
396                 [Test]
397                 public void Static ()
398                 {
399                         var t = XamlLanguage.Static;
400                         TestXamlTypeExtension (t, "StaticExtension", typeof (StaticExtension), typeof (object), false);
401                         var tc = t.TypeConverter.ConverterInstance;
402                         Assert.IsNotNull (tc, "#25-2");
403                         Assert.IsFalse (tc.CanConvertFrom (typeof (string)), "#25-3");
404                         Assert.IsTrue (tc.CanConvertTo (typeof (string)), "#25-4");
405                         Assert.IsNull (t.ContentProperty, "#27");
406
407                         var l = t.GetAllMembers ().ToArray ();
408                         Assert.AreEqual (2, l.Length, "#31");
409                         l.First (m => m.Name == "Member");
410                         l.First (m => m.Name == "MemberType");
411
412                         l = t.GetAllAttachableMembers ().ToArray ();
413                         Assert.AreEqual (0, l.Length, "#32");
414                 }
415
416                 [Test]
417                 public void Static_Member ()
418                 {
419                         var m = XamlLanguage.Static.GetMember ("Member");
420                         TestMemberCommon (m, "Member", typeof (string), typeof (StaticExtension), true);
421                 }
422
423                 [Test]
424                 public void Static_MemberType ()
425                 {
426                         var m = XamlLanguage.Static.GetMember ("MemberType");
427                         TestMemberCommon (m, "MemberType", typeof (Type), typeof (StaticExtension), true);
428                 }
429
430                 [Test]
431                 public void Type ()
432                 {
433                         var t = XamlLanguage.Type;
434                         TestXamlTypeExtension (t, "TypeExtension", typeof (TypeExtension), typeof (Type), false);
435                         Assert.IsNotNull (t.TypeConverter.ConverterInstance, "#25-2");
436                         Assert.IsNull (t.ContentProperty, "#27");
437
438                         var l = t.GetAllMembers ().ToArray ();
439                         Assert.AreEqual (2, l.Length, "#31");
440                         l.First (m => m.Name == "TypeName");
441                         l.First (m => m.Name == "Type");
442
443                         l = t.GetAllAttachableMembers ().ToArray ();
444                         Assert.AreEqual (0, l.Length, "#32");
445                 }
446
447                 [Test]
448                 public void Type_TypeName ()
449                 {
450                         var m = XamlLanguage.Type.GetMember ("TypeName");
451                         TestMemberCommon (m, "TypeName", typeof (string), typeof (TypeExtension), true);
452                 }
453
454                 [Test]
455                 public void Type_Type ()
456                 {
457                         var m = XamlLanguage.Type.GetMember ("Type");
458                         TestMemberCommon (m, "Type", typeof (Type), typeof (TypeExtension), true);
459                         Assert.AreNotEqual (XamlLanguage.Type, m.Type, "#1");
460                 }
461
462                 // primitive types
463
464                 [Test]
465                 public void Byte ()
466                 {
467                         var t = XamlLanguage.Byte;
468                         TestXamlTypePrimitive (t, "Byte", typeof (byte), false, false);
469
470                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
471                         var l = t.GetAllAttachableMembers ().ToArray ();
472                         Assert.AreEqual (1, l.Length, "#32");
473                         */
474                 }
475
476                 [Test]
477                 public void Char ()
478                 {
479                         var t = XamlLanguage.Char;
480                         TestXamlTypePrimitive (t, "Char", typeof (char), false, false);
481
482                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
483                         var l = t.GetAllAttachableMembers ().ToArray ();
484                         Assert.AreEqual (3, l.Length, "#32");
485                         l.First (m => m.Name == "UnicodeCategory");
486                         l.First (m => m.Name == "NumericValue");
487                         l.First (m => m.Name == "HashCodeOfPtr");
488                         */
489                 }
490
491                 [Test]
492                 public void Decimal ()
493                 {
494                         var t = XamlLanguage.Decimal;
495                         TestXamlTypePrimitive (t, "Decimal", typeof (decimal), false, false);
496
497                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
498                         var l = t.GetAllAttachableMembers ().ToArray ();
499                         Assert.AreEqual (2, l.Length, "#32");
500                         l.First (m => m.Name == "Bits");
501                         l.First (m => m.Name == "HashCodeOfPtr");
502                         */
503                 }
504
505                 [Test]
506                 public void Double ()
507                 {
508                         var t = XamlLanguage.Double;
509                         TestXamlTypePrimitive (t, "Double", typeof (double), false, false);
510
511                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
512                         var l = t.GetAllAttachableMembers ().ToArray ();
513                         Assert.AreEqual (1, l.Length, "#32");
514                         l.First (m => m.Name == "HashCodeOfPtr");
515                         */
516                 }
517
518                 [Test]
519                 public void Int16 ()
520                 {
521                         var t = XamlLanguage.Int16;
522                         TestXamlTypePrimitive (t, "Int16", typeof (short), false, false);
523
524                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
525                         var l = t.GetAllAttachableMembers ().ToArray ();
526                         Assert.AreEqual (1, l.Length, "#32");
527                         l.First (m => m.Name == "HashCodeOfPtr");
528                         */
529                 }
530
531                 [Test]
532                 public void Int32 ()
533                 {
534                         var t = XamlLanguage.Int32;
535                         TestXamlTypePrimitive (t, "Int32", typeof (int), false, false);
536
537                         try {
538                                 t.Invoker.CreateInstance (new object [] {1});
539                                 Assert.Fail ("Should expect .ctor() and fail");
540                         } catch (MissingMethodException) {
541                         }
542
543                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
544                         var l = t.GetAllAttachableMembers ().ToArray ();
545                         Assert.AreEqual (1, l.Length, "#32");
546                         l.First (m => m.Name == "HashCodeOfPtr");
547                         */
548                 }
549
550                 [Test]
551                 public void Int64 ()
552                 {
553                         var t = XamlLanguage.Int64;
554                         TestXamlTypePrimitive (t, "Int64", typeof (long), false, false);
555
556                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
557                         var l = t.GetAllAttachableMembers ().ToArray ();
558                         Assert.AreEqual (1, l.Length, "#32");
559                         l.First (m => m.Name == "HashCodeOfPtr");
560                         */
561                 }
562
563                 [Test]
564                 public void Object ()
565                 {
566                         var t = XamlLanguage.Object;
567                         TestXamlTypePrimitive (t, "Object", typeof (object), true, false);
568                         Assert.IsNull (t.BaseType, "#x1");
569
570                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
571                         var l = t.GetAllAttachableMembers ().ToArray ();
572                         Assert.AreEqual (0, l.Length, "#32");
573                         */
574                 }
575
576                 [Test]
577                 public void Single ()
578                 {
579                         var t = XamlLanguage.Single;
580                         TestXamlTypePrimitive (t, "Single", typeof (float), false, false);
581
582                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
583                         var l = t.GetAllAttachableMembers ().ToArray ();
584                         Assert.AreEqual (1, l.Length, "#32");
585                         l.First (m => m.Name == "HashCodeOfPtr");
586                         */
587                 }
588
589                 [Test]
590                 public void String ()
591                 {
592                         var t = XamlLanguage.String;
593                         TestXamlTypePrimitive (t, "String", typeof (string), true, true);
594                         Assert.IsNotNull (XamlLanguage.AllTypes.First (tt => tt.Name == "String").ValueSerializer, "#x");
595                         Assert.IsNotNull (XamlLanguage.String.ValueSerializer, "#y");
596
597                         try {
598                                 t.Invoker.CreateInstance (new object [] {"foo"});
599                                 Assert.Fail ("Should expect .ctor() and fail");
600                         } catch (MissingMethodException) {
601                         }
602
603                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
604                         var l = t.GetAllAttachableMembers ().ToArray ();
605                         Assert.AreEqual (0, l.Length, "#32");
606                         */
607                 }
608
609                 [Test]
610                 public void TimeSpan ()
611                 {
612                         var t = XamlLanguage.TimeSpan;
613                         TestXamlTypePrimitive (t, "TimeSpan", typeof (TimeSpan), false, false);
614
615                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
616                         var l = t.GetAllAttachableMembers ().ToArray ();
617                         Assert.AreEqual (1, l.Length, "#32");
618                         l.First (m => m.Name == "HashCodeOfPtr");
619                         */
620                 }
621
622                 [Test]
623                 public void Uri ()
624                 {
625                         var t = XamlLanguage.Uri;
626                         TestXamlTypePrimitive (t, "Uri", typeof (Uri), true, true);
627
628                         /* Those properties are pointless regarding practical use. Those "members" does not participate in serialization.
629                         var l = t.GetAllAttachableMembers ().ToArray ();
630                         Assert.AreEqual (0, l.Length, "#32");
631                         */
632                 }
633
634                 // miscellaneous
635
636                 [Test]
637                 public void Member ()
638                 {
639                         var t = XamlLanguage.Member;
640                         TestXamlTypeCommon (t, "Member", typeof (MemberDefinition), true, true, false);
641                         Assert.IsNull (t.TypeConverter, "#25");
642                         // FIXME: test remaining members
643
644                         var l = t.GetAllMembers ().ToArray ();
645                         Assert.AreEqual (1, l.Length, "#31");
646                         l.First (m => m.Name == "Name");
647                 }
648
649                 [Test]
650                 public void Member_Name ()
651                 {
652                         var m = XamlLanguage.Member.GetMember ("Name");
653                         TestMemberCommon (m, "Name", typeof (string), typeof (MemberDefinition), true);
654                 }
655
656                 [Test]
657                 public void Property ()
658                 {
659                         var t = XamlLanguage.Property;
660                         TestXamlTypeCommon (t, "Property", typeof (PropertyDefinition), true);
661                         Assert.IsNull (t.TypeConverter, "#25");
662                         // FIXME: test remaining members
663
664                         var l = t.GetAllMembers ().ToArray ();
665                         Assert.AreEqual (4, l.Length, "#31");
666                         l.First (m => m.Name == "Name");
667                         l.First (m => m.Name == "Type");
668                         l.First (m => m.Name == "Modifier");
669                         l.First (m => m.Name == "Attributes");
670                 }
671
672                 [Test]
673                 public void Property_Name ()
674                 {
675                         var m = XamlLanguage.Property.GetMember ("Name");
676                         TestMemberCommon (m, "Name", typeof (string), typeof (PropertyDefinition), true);
677                 }
678
679                 [Test]
680                 public void Property_Type ()
681                 {
682                         var m = XamlLanguage.Property.GetMember ("Type");
683                         TestMemberCommon (m, "Type", typeof (XamlType), typeof (PropertyDefinition), true);
684                         Assert.IsNotNull (m.TypeConverter, "#1");
685                         Assert.IsNull (m.ValueSerializer, "#2");
686                 }
687
688                 [Test]
689                 public void Property_Modifier ()
690                 {
691                         var m = XamlLanguage.Property.GetMember ("Modifier");
692                         TestMemberCommon (m, "Modifier", typeof (string), typeof (PropertyDefinition), true);
693                 }
694
695                 [Test]
696                 public void Property_Attributes ()
697                 {
698                         var m = XamlLanguage.Property.GetMember ("Attributes");
699                         TestMemberCommon (m, "Attributes", typeof (IList<Attribute>), typeof (PropertyDefinition), false);
700                 }
701
702                 [Test]
703                 public void Reference ()
704                 {
705                         var t = XamlLanguage.Reference;
706                         TestXamlTypeCommon (t, "Reference", typeof (Reference), true);
707                         Assert.IsNull (t.TypeConverter, "#25");
708                         // FIXME: test remaining members
709
710                         var l = t.GetAllMembers ().ToArray ();
711                         Assert.AreEqual (1, l.Length, "#31");
712                         l.First (m => m.Name == "Name");
713                         Assert.AreEqual (l [0], t.ContentProperty, "#32");
714                 }
715
716                 [Test]
717                 public void Reference_Name ()
718                 {
719                         var m = XamlLanguage.Reference.GetMember ("Name");
720                         TestMemberCommon (m, "Name", typeof (string), typeof (Reference), true);
721                 }
722
723                 [Test]
724                 public void XData ()
725                 {
726                         var t = XamlLanguage.XData;
727                         TestXamlTypeCommon (t, "XData", typeof (XData), true);
728                         Assert.IsNull (t.TypeConverter, "#25");
729                         // FIXME: test remaining members
730
731                         var l = t.GetAllMembers ().ToArray ();
732                         Assert.AreEqual (2, l.Length, "#31");
733                         l.First (m => m.Name == "Text");
734                         l.First (m => m.Name == "XmlReader");
735                 }
736
737                 [Test]
738                 public void XData_Text ()
739                 {
740                         var m = XamlLanguage.XData.GetMember ("Text");
741                         TestMemberCommon (m, "Text", typeof (string), typeof (XData), true);
742                 }
743
744                 [Test]
745                 public void XData_XmlReader ()
746                 {
747                         var m = XamlLanguage.XData.GetMember ("XmlReader");
748                         // it does not use XmlReader type ...
749                         TestMemberCommon (m, "XmlReader", typeof (object), typeof (XData), true);
750                 }
751
752                 // common test methods
753
754                 void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable)
755                 {
756                         TestXamlTypeCommon (t, name, underlyingType, nullable, false);
757                 }
758
759                 void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable, bool constructionRequiresArguments)
760                 {
761                         TestXamlTypeCommon (t, name, underlyingType, nullable, constructionRequiresArguments, true);
762                 }
763
764                 void TestXamlTypeCommon (XamlType t, string name, Type underlyingType, bool nullable, bool constructionRequiresArguments, bool isConstructible)
765                 {
766                         Assert.IsNotNull (t.Invoker, "#1");
767                         Assert.IsTrue (t.IsNameValid, "#2");
768                         Assert.IsFalse (t.IsUnknown, "#3");
769                         // FIXME: test names (some extension types have wrong name.
770                         //Assert.AreEqual (name, t.Name, "#4");
771                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.PreferredXamlNamespace, "#5");
772                         Assert.IsNull (t.TypeArguments, "#6");
773                         Assert.AreEqual (underlyingType, t.UnderlyingType, "#7");
774                         Assert.AreEqual (constructionRequiresArguments, t.ConstructionRequiresArguments, "#8");
775                         Assert.IsFalse (t.IsArray, "#9");
776                         Assert.IsFalse (t.IsCollection, "#10");
777                         // FIXME: test here (very inconsistent with the spec)
778                         Assert.AreEqual (isConstructible, t.IsConstructible, "#11");
779                         Assert.IsFalse (t.IsDictionary, "#12");
780                         Assert.IsFalse (t.IsGeneric, "#13");
781                         Assert.IsFalse (t.IsNameScope, "#15");
782                         Assert.AreEqual (nullable, t.IsNullable, "#16");
783                         Assert.IsTrue (t.IsPublic, "#17");
784                         Assert.IsFalse (t.IsUsableDuringInitialization, "#18");
785                         Assert.IsFalse (t.IsWhitespaceSignificantCollection, "#19");
786                         Assert.IsFalse (t.IsXData, "#20");
787                         Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
788                         Assert.IsFalse (t.IsAmbient, "#22");
789                         Assert.IsNull (t.AllowedContentTypes, "#23");
790                         Assert.IsNull (t.ContentWrappers, "#24");
791                         // string is a special case.
792                         if (t == XamlLanguage.String)
793                                 Assert.IsNotNull (t.ValueSerializer, "#26");
794                         else
795                                 Assert.IsNull (t.ValueSerializer, "#26");
796                         //Assert.IsNull (t.DeferringLoader, "#28");
797                 }
798
799                 void TestXamlTypePrimitive (XamlType t, string name, Type underlyingType, bool nullable, bool constructorRequiresArguments)
800                 {
801                         TestXamlTypeCommon (t, name, underlyingType, nullable, constructorRequiresArguments);
802                         Assert.IsFalse (t.IsMarkupExtension, "#14");
803                         Assert.IsNotNull (t.TypeConverter, "#25");
804                         Assert.IsNull (t.ContentProperty, "#27");
805                         Assert.IsNull (t.MarkupExtensionReturnType, "#29");
806
807                         var l = t.GetAllMembers ().ToArray ();
808                         Assert.AreEqual (0, l.Length, "#31");
809                 }
810
811                 void TestXamlTypeExtension (XamlType t, string name, Type underlyingType, Type extReturnType, bool noTypeConverter)
812                 {
813                         TestXamlTypeCommon (t, name, underlyingType, true, false);
814                         Assert.IsTrue (t.IsMarkupExtension, "#14");
815                         if (noTypeConverter)
816                                 Assert.IsNull (t.TypeConverter, "#25");
817                         else
818                                 Assert.IsNotNull (t.TypeConverter, "#25");
819                         Assert.IsNotNull (t.MarkupExtensionReturnType, "#29");
820                         Assert.AreEqual (extReturnType, t.MarkupExtensionReturnType.UnderlyingType, "#29-2");
821                         Assert.IsNull (t.Invoker.SetMarkupExtensionHandler, "#31"); // orly?
822                 }
823
824                 void TestMemberCommon (XamlMember m, string name, Type type, Type declType, bool hasSetter)
825                 {
826                         Assert.IsNotNull (m, "#1");
827                         Assert.IsNotNull (m.DeclaringType, "#2");
828                         Assert.AreEqual (declType, m.DeclaringType.UnderlyingType, "#2-2");
829                         Assert.IsNotNull (m.Invoker, "#3");
830                         Assert.IsNotNull (m.Invoker.UnderlyingGetter, "#3-2");
831                         if (hasSetter)
832                                 Assert.IsNotNull (m.Invoker.UnderlyingSetter, "#3-3");
833                         else
834                                 Assert.IsNull (m.Invoker.UnderlyingSetter, "#3-3");
835                         Assert.IsFalse (m.IsUnknown, "#4");
836                         Assert.IsTrue (m.IsReadPublic, "#5");
837                         Assert.AreEqual (hasSetter, m.IsWritePublic, "#6");
838                         Assert.AreEqual (name, m.Name, "#7");
839                         Assert.IsTrue (m.IsNameValid, "#8");
840                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, m.PreferredXamlNamespace, "#9");
841                         // use declType here (mostly identical to targetType)
842                         Assert.AreEqual (new XamlType (declType, m.TargetType.SchemaContext), m.TargetType, "#10");
843                         Assert.IsNotNull (m.Type, "#11");
844                         Assert.AreEqual (type, m.Type.UnderlyingType, "#11-2");
845                         // Property.Type is a special case here.
846                         if (name == "Type" && m.DeclaringType != XamlLanguage.Property)
847                                 Assert.AreEqual (m.Type.TypeConverter, m.TypeConverter, "#12");
848                         // String type is a special case here.
849                         if (type == typeof (string))
850                                 Assert.AreEqual (m.Type.ValueSerializer, m.ValueSerializer, "#13a");
851                         else
852                                 Assert.IsNull (m.ValueSerializer, "#13b");
853                         Assert.IsNull (m.DeferringLoader, "#14");
854                         Assert.IsNotNull (m.UnderlyingMember, "#15");
855                         Assert.AreEqual (!hasSetter, m.IsReadOnly, "#16");
856                         Assert.IsFalse (m.IsWriteOnly, "#17");
857                         Assert.IsFalse (m.IsAttachable, "#18");
858                         Assert.IsFalse (m.IsEvent, "#19");
859                         Assert.IsFalse (m.IsDirective, "#20");
860                         Assert.IsNotNull (m.DependsOn, "#21");
861                         Assert.AreEqual (0, m.DependsOn.Count, "#21-2");
862                         Assert.IsFalse (m.IsAmbient, "#22");
863                 }
864         }
865 }