2e1e91355dca0c9794a440758af90da58e468e77
[mono.git] / mcs / class / System.Xaml / Test / System.Xaml / XamlTypeTest.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 NUnit.Framework;
33
34 using Category = NUnit.Framework.CategoryAttribute;
35
36 namespace MonoTests.System.Xaml
37 {
38         // FIXME: enable DeferringLoader tests.
39         [TestFixture]
40         public class XamlTypeTest
41         {
42                 XamlSchemaContext sctx = new XamlSchemaContext (null, null);
43
44                 [Test]
45                 [ExpectedException (typeof (ArgumentNullException))]
46                 public void ConstructorTypeNullType ()
47                 {
48                         new XamlType (null, sctx);
49                 }
50
51                 [Test]
52                 [ExpectedException (typeof (ArgumentNullException))]
53                 public void ConstructorTypeNullSchemaContext ()
54                 {
55                         new XamlType (typeof (int), null);
56                 }
57
58                 [Test]
59                 public void ConstructorSimpleType ()
60                 {
61                         var t = new XamlType (typeof (int), sctx);
62                         Assert.AreEqual ("Int32", t.Name, "#1");
63                         Assert.AreEqual (typeof (int), t.UnderlyingType, "#2");
64                         Assert.IsNotNull (t.BaseType, "#3-1");
65                         // So, it is type aware. It's weird that t.Name still returns full name just as it is passed to the .ctor.
66                         Assert.AreEqual ("ValueType", t.BaseType.Name, "#3-2");
67                         Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", t.BaseType.PreferredXamlNamespace, "#3-3");
68                         // It is likely only for primitive types such as int.
69                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.PreferredXamlNamespace, "#4");
70
71                         t = new XamlType (typeof (XamlXmlReader), sctx);
72                         Assert.AreEqual ("XamlXmlReader", t.Name, "#11");
73                         Assert.AreEqual (typeof (XamlXmlReader), t.UnderlyingType, "#12");
74                         Assert.IsNotNull (t.BaseType, "#13");
75                         Assert.AreEqual (typeof (XamlReader), t.BaseType.UnderlyingType, "#13-2");
76                         Assert.AreEqual ("clr-namespace:System.Xaml;assembly=System.Xaml", t.BaseType.PreferredXamlNamespace, "#13-3");
77                         Assert.AreEqual ("clr-namespace:System.Xaml;assembly=System.Xaml", t.PreferredXamlNamespace, "#14");
78                 }
79
80                 [Test]
81                 public void ConstructorNullTypeInvoker ()
82                 {
83                         // allowed.
84                         new XamlType (typeof (int), sctx, null);
85                 }
86
87                 [Test]
88                 [ExpectedException (typeof (ArgumentNullException))]
89                 public void ConstructorNamesNullName ()
90                 {
91                         new XamlType (String.Empty, null, null, sctx);
92                 }
93
94                 [Test]
95                 [ExpectedException (typeof (ArgumentNullException))]
96                 public void ConstructorNamesNullSchemaContext ()
97                 {
98                         new XamlType ("System", "Int32", null, null);
99                 }
100
101                 [Test]
102                 public void ConstructorNames ()
103                 {
104                         // null typeArguments is allowed.
105                         new XamlType ("System", "Int32", null, sctx);
106                 }
107
108                 [Test]
109                 [ExpectedException (typeof (ArgumentNullException))]
110                 public void ConstructorNameNullName ()
111                 {
112                         new MyXamlType (null, null, sctx);
113                 }
114
115                 [Test]
116                 [ExpectedException (typeof (ArgumentNullException))]
117                 public void ConstructorNameNullSchemaContext ()
118                 {
119                         new MyXamlType ("System.Int32", null, null);
120                 }
121
122                 [Test]
123                 public void ConstructorNameInvalid ()
124                 {
125                         // ... all allowed.
126                         new XamlType (String.Empty, ".", null, sctx);
127                         new XamlType (String.Empty, "<>", null, sctx);
128                         new XamlType (String.Empty, "", null, sctx);
129                 }
130
131                 [Test]
132                 public void ConstructorNameWithFullName ()
133                 {
134                         // null typeArguments is allowed.
135                         var t = new MyXamlType ("System.Int32", null, sctx);
136                         Assert.AreEqual ("System.Int32", t.Name, "#1");
137                         Assert.IsNull (t.UnderlyingType, "#2");
138                         Assert.IsNotNull (t.BaseType, "#3-1");
139                         // So, it is type aware. It's weird that t.Name still returns full name just as it is passed to the .ctor.
140                         Assert.AreEqual ("Object", t.BaseType.Name, "#3-2");
141                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.BaseType.PreferredXamlNamespace, "#3-3");
142                         Assert.IsNull (t.BaseType.BaseType, "#3-4");
143                         Assert.AreEqual (String.Empty, t.PreferredXamlNamespace, "#4");
144                         Assert.IsFalse (t.IsArray, "#5");
145                         Assert.IsFalse (t.IsGeneric, "#6");
146                         Assert.IsTrue (t.IsPublic, "#7");
147                 }
148
149                 [Test]
150                 public void NoSuchTypeByName ()
151                 {
152                         var t = new MyXamlType ("System.NoSuchType", null, sctx);
153                         Assert.AreEqual ("System.NoSuchType", t.Name, "#1");
154                         Assert.IsNull (t.UnderlyingType, "#2");
155                         Assert.IsNotNull (t.BaseType, "#3-1");
156                         // So, it is type aware. It's weird that t.Name still returns full name just as it is passed to the .ctor.
157                         Assert.AreEqual ("Object", t.BaseType.Name, "#3-2");
158                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.BaseType.PreferredXamlNamespace, "#3-3");
159                         Assert.AreEqual (String.Empty, t.PreferredXamlNamespace, "#4");
160                 }
161
162                 [Test]
163                 public void NoSuchTypeByNames ()
164                 {
165                         var t = new XamlType ("urn:foo", "System.NoSuchType", null, sctx);
166                         Assert.AreEqual ("System.NoSuchType", t.Name, "#1");
167                         Assert.IsNull (t.UnderlyingType, "#2");
168                         Assert.IsNotNull (t.BaseType, "#3-1");
169                         // So, it is type aware. It's weird that t.Name still returns full name just as it is passed to the .ctor.
170                         Assert.AreEqual ("Object", t.BaseType.Name, "#3-2");
171                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.BaseType.PreferredXamlNamespace, "#3-3");
172                         Assert.AreEqual ("urn:foo", t.PreferredXamlNamespace, "#4");
173                 }
174
175                 [Test]
176                 [Ignore ("It results in NRE on .NET 4.0 RTM")]
177                 public void EmptyTypeArguments ()
178                 {
179                         var t1 = new MyXamlType ("System.Int32", null, sctx);
180                         var t2 = new MyXamlType ("System.Int32", new XamlType [0], sctx);
181                         Assert.IsTrue (t1 == t2, "#1");
182                         Assert.IsTrue (t1.Equals (t2), "#2");
183                 }
184
185                 [Test]
186                 public void EmptyTypeArguments2 ()
187                 {
188                         var t1 = new XamlType ("System", "Int32", null, sctx);
189                         var t2 = new XamlType ("System", "Int32", new XamlType [0], sctx);
190                         Assert.IsNull (t1.TypeArguments, "#1");
191                         Assert.IsNull (t2.TypeArguments, "#2");
192                         Assert.IsTrue (t1 == t2, "#3");
193                         Assert.IsTrue (t1.Equals (t2), "#4");
194                 }
195
196                 [Test]
197                 public void EqualityAcrossConstructors ()
198                 {
199                         var t1 = new XamlType (typeof (int), sctx);
200                         var t2 = new XamlType (t1.PreferredXamlNamespace, t1.Name, null, sctx);
201                         // not sure if it always returns false for different .ctor comparisons...
202                         Assert.IsFalse (t1 == t2, "#3");
203                 }
204
205                 [Test]
206                 public void ArrayAndCollection ()
207                 {
208                         var t = new XamlType (typeof (int), sctx);
209                         Assert.IsFalse (t.IsArray, "#1.1");
210                         Assert.IsFalse (t.IsCollection, "#1.2");
211                         Assert.IsNull (t.ItemType, "#1.3");
212                         t = new XamlType (typeof (ArrayList), sctx);
213                         Assert.IsFalse (t.IsArray, "#2.1");
214                         Assert.IsTrue (t.IsCollection, "#2.2");
215                         Assert.IsNotNull (t.ItemType, "#2.3");
216                         Assert.AreEqual ("Object", t.ItemType.Name, "#2.4");
217                         t = new XamlType (typeof (int []), sctx);
218                         Assert.IsTrue (t.IsArray, "#3.1");
219                         // why?
220                         Assert.IsFalse (t.IsCollection, "#3.2");
221                         Assert.IsNotNull (t.ItemType, "#3.3");
222                         Assert.AreEqual (typeof (int), t.ItemType.UnderlyingType, "#3.4");
223                 }
224
225                 [Test]
226                 public void Dictionary ()
227                 {
228                         var t = new XamlType (typeof (int), sctx);
229                         Assert.IsFalse (t.IsDictionary, "#1.1");
230                         Assert.IsFalse (t.IsCollection, "#1.1-2");
231                         Assert.IsNull (t.KeyType, "#1.2");
232                         t = new XamlType (typeof (Hashtable), sctx);
233                         Assert.IsTrue (t.IsDictionary, "#2.1");
234                         Assert.IsFalse (t.IsCollection, "#2.1-2");
235                         Assert.IsNotNull (t.KeyType, "#2.2");
236                         Assert.AreEqual ("Object", t.KeyType.Name, "#2.3");
237                         t = new XamlType (typeof (Dictionary<int,string>), sctx);
238                         Assert.IsTrue (t.IsDictionary, "#3.1");
239                         Assert.IsFalse (t.IsCollection, "#3.1-2");
240                         Assert.IsNotNull (t.KeyType, "#3.2");
241                         Assert.AreEqual ("Int32", t.KeyType.Name, "#3.3");
242                 }
243
244                 public class TestClass1
245                 {
246                 }
247         
248                 class TestClass2
249                 {
250                         internal TestClass2 () {}
251                 }
252
253                 [Test]
254                 public void IsConstructible ()
255                 {
256                         // ... is it?
257                         Assert.IsTrue (new XamlType (typeof (int), sctx).IsConstructible, "#1");
258                         // ... is it?
259                         Assert.IsFalse (new XamlType (typeof (TestClass1), sctx).IsConstructible, "#2");
260                         Assert.IsFalse (new XamlType (typeof (TestClass2), sctx).IsConstructible, "#3");
261                         Assert.IsTrue (new XamlType (typeof (object), sctx).IsConstructible, "#4");
262                 }
263
264                 class AttachableClass
265                 {
266                         public event EventHandler<EventArgs> SimpleEvent;
267                         public void AddSimpleHandler (object o, EventHandler h)
268                         {
269                         }
270                 }
271
272                 // hmm, what can we use to verify this method?
273                 [Test]
274                 public void GetAllAttachableMembers ()
275                 {
276                         var xt = new XamlType (typeof (AttachableClass), sctx);
277                         var l = xt.GetAllAttachableMembers ();
278                         Assert.AreEqual (0, l.Count, "#1");
279                 }
280
281                 [Test]
282                 public void DefaultValuesType ()
283                 {
284                         var t = new XamlType (typeof (int), sctx);
285                         Assert.IsNotNull (t.Invoker, "#1");
286                         Assert.IsTrue (t.IsNameValid, "#2");
287                         Assert.IsFalse (t.IsUnknown, "#3");
288                         Assert.AreEqual ("Int32", t.Name, "#4");
289                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, t.PreferredXamlNamespace, "#5");
290                         Assert.IsNull (t.TypeArguments, "#6");
291                         Assert.AreEqual (typeof (int), t.UnderlyingType, "#7");
292                         Assert.IsFalse (t.ConstructionRequiresArguments, "#8");
293                         Assert.IsFalse (t.IsArray, "#9");
294                         Assert.IsFalse (t.IsCollection, "#10");
295                         Assert.IsTrue (t.IsConstructible, "#11");
296                         Assert.IsFalse (t.IsDictionary, "#12");
297                         Assert.IsFalse (t.IsGeneric, "#13");
298                         Assert.IsFalse (t.IsMarkupExtension, "#14");
299                         Assert.IsFalse (t.IsNameScope, "#15");
300                         Assert.IsFalse (t.IsNullable, "#16");
301                         Assert.IsTrue (t.IsPublic, "#17");
302                         Assert.IsFalse (t.IsUsableDuringInitialization, "#18");
303                         Assert.IsFalse (t.IsWhitespaceSignificantCollection, "#19");
304                         Assert.IsFalse (t.IsXData, "#20");
305                         Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
306                         Assert.IsFalse (t.IsAmbient, "#22");
307                         Assert.IsNull (t.AllowedContentTypes, "#23");
308                         Assert.IsNull (t.ContentWrappers, "#24");
309                         Assert.IsNotNull (t.TypeConverter, "#25");
310                         Assert.IsTrue (t.TypeConverter.ConverterInstance is Int32Converter, "#25-2");
311                         Assert.IsNull (t.ValueSerializer, "#26");
312                         Assert.IsNull (t.ContentProperty, "#27");
313                         //Assert.IsNull (t.DeferringLoader, "#28");
314                         Assert.IsNull (t.MarkupExtensionReturnType, "#29");
315                         Assert.AreEqual (sctx, t.SchemaContext, "#30");
316                 }
317
318                 [Test]
319                 public void DefaultValuesType2 ()
320                 {
321                         var t = new XamlType (typeof (Type), sctx);
322                         Assert.IsNotNull (t.Invoker, "#1");
323                         Assert.IsTrue (t.IsNameValid, "#2");
324                         Assert.IsFalse (t.IsUnknown, "#3");
325                         Assert.AreEqual ("Type", t.Name, "#4");
326                         // Note that Type is not a standard type. An instance of System.Type is usually represented as TypeExtension.
327                         Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", t.PreferredXamlNamespace, "#5");
328                         Assert.IsNull (t.TypeArguments, "#6");
329                         Assert.AreEqual (typeof (Type), t.UnderlyingType, "#7");
330                         Assert.IsTrue (t.ConstructionRequiresArguments, "#8"); // yes, true.
331                         Assert.IsFalse (t.IsArray, "#9");
332                         Assert.IsFalse (t.IsCollection, "#10");
333                         Assert.IsFalse (t.IsConstructible, "#11"); // yes, false.
334                         Assert.IsFalse (t.IsDictionary, "#12");
335                         Assert.IsFalse (t.IsGeneric, "#13");
336                         Assert.IsFalse (t.IsMarkupExtension, "#14");
337                         Assert.IsFalse (t.IsNameScope, "#15");
338                         Assert.IsTrue (t.IsNullable, "#16");
339                         Assert.IsTrue (t.IsPublic, "#17");
340                         Assert.IsFalse (t.IsUsableDuringInitialization, "#18");
341                         Assert.IsFalse (t.IsWhitespaceSignificantCollection, "#19");
342                         Assert.IsFalse (t.IsXData, "#20");
343                         Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
344                         Assert.IsFalse (t.IsAmbient, "#22");
345                         Assert.IsNull (t.AllowedContentTypes, "#23");
346                         Assert.IsNull (t.ContentWrappers, "#24");
347                         // FIXME: enable this when we fixed TypeConverter for Type.
348                         //Assert.IsNotNull (t.TypeConverter, "#25"); // TypeTypeConverter
349                         Assert.IsNull (t.ValueSerializer, "#26");
350                         Assert.IsNull (t.ContentProperty, "#27");
351                         //Assert.IsNull (t.DeferringLoader, "#28");
352                         Assert.IsNull (t.MarkupExtensionReturnType, "#29");
353                         Assert.AreEqual (sctx, t.SchemaContext, "#30");
354                 }
355
356                 [Test]
357                 public void DefaultValuesName ()
358                 {
359                         var t = new XamlType ("urn:foo", ".", null, sctx);
360
361                         Assert.IsNotNull (t.Invoker, "#1");
362                         Assert.IsFalse (t.IsNameValid, "#2");
363                         Assert.IsTrue (t.IsUnknown, "#3");
364                         Assert.AreEqual (".", t.Name, "#4");
365                         Assert.AreEqual ("urn:foo", t.PreferredXamlNamespace, "#5");
366                         Assert.IsNull (t.TypeArguments, "#6");
367                         Assert.IsNull (t.UnderlyingType, "#7");
368                         Assert.IsFalse (t.ConstructionRequiresArguments, "#8");
369                         Assert.IsFalse (t.IsArray, "#9");
370                         Assert.IsFalse (t.IsCollection, "#10");
371                         Assert.IsTrue (t.IsConstructible, "#11");
372                         Assert.IsFalse (t.IsDictionary, "#12");
373                         Assert.IsFalse (t.IsGeneric, "#13");
374                         Assert.IsFalse (t.IsMarkupExtension, "#14");
375                         Assert.IsFalse (t.IsNameScope, "#15");
376                         Assert.IsTrue (t.IsNullable, "#16"); // different from int
377                         Assert.IsTrue (t.IsPublic, "#17");
378                         Assert.IsFalse (t.IsUsableDuringInitialization, "#18");
379                         Assert.IsTrue (t.IsWhitespaceSignificantCollection, "#19"); // somehow true ...
380                         Assert.IsFalse (t.IsXData, "#20");
381                         Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
382                         Assert.IsFalse (t.IsAmbient, "#22");
383                         Assert.IsNull (t.AllowedContentTypes, "#23");
384                         Assert.IsNull (t.ContentWrappers, "#24");
385                         Assert.IsNull (t.TypeConverter, "#25");
386                         Assert.IsNull (t.ValueSerializer, "#26");
387                         Assert.IsNull (t.ContentProperty, "#27");
388                         //Assert.IsNull (t.DeferringLoader, "#28");
389                         Assert.IsNull (t.MarkupExtensionReturnType, "#29");
390                         Assert.AreEqual (sctx, t.SchemaContext, "#30");
391                 }
392
393                 [Test]
394                 public void DefaultValuesCustomType ()
395                 {
396                         var t = new MyXamlType ("System.Int32", null, sctx);
397
398                         Assert.IsNotNull (t.Invoker, "#1");
399                         Assert.IsFalse (t.IsNameValid, "#2");
400                         Assert.IsTrue (t.IsUnknown, "#3");
401                         Assert.AreEqual ("System.Int32", t.Name, "#4");
402                         Assert.AreEqual (String.Empty, t.PreferredXamlNamespace, "#5");
403                         Assert.IsNull (t.TypeArguments, "#6");
404                         Assert.IsNull (t.UnderlyingType, "#7");
405                         Assert.IsFalse (t.ConstructionRequiresArguments, "#8");
406                         Assert.IsFalse (t.IsArray, "#9");
407                         Assert.IsFalse (t.IsCollection, "#10");
408                         Assert.IsTrue (t.IsConstructible, "#11");
409                         Assert.IsFalse (t.IsDictionary, "#12");
410                         Assert.IsFalse (t.IsGeneric, "#13");
411                         Assert.IsFalse (t.IsMarkupExtension, "#14");
412                         Assert.IsFalse (t.IsNameScope, "#15");
413                         Assert.IsTrue (t.IsNullable, "#16"); // different from int
414                         Assert.IsTrue (t.IsPublic, "#17");
415                         Assert.IsFalse (t.IsUsableDuringInitialization, "#18");
416                         Assert.IsTrue (t.IsWhitespaceSignificantCollection, "#19"); // somehow true ...
417                         Assert.IsFalse (t.IsXData, "#20");
418                         Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
419                         Assert.IsFalse (t.IsAmbient, "#22");
420                         Assert.IsNull (t.AllowedContentTypes, "#23");
421                         Assert.IsNull (t.ContentWrappers, "#24");
422                         Assert.IsNull (t.TypeConverter, "#25");
423                         Assert.IsNull (t.ValueSerializer, "#26");
424                         Assert.IsNull (t.ContentProperty, "#27");
425                         //Assert.IsNull (t.DeferringLoader, "#28");
426                         Assert.IsNull (t.MarkupExtensionReturnType, "#29");
427                         Assert.AreEqual (sctx, t.SchemaContext, "#30");
428                 }
429
430                 [Ambient]
431                 [ContentProperty ("Name")]
432                 [WhitespaceSignificantCollection]
433                 [UsableDuringInitialization (true)]
434                 public class TestClass3
435                 {
436                         public TestClass3 (string name)
437                         {
438                                 Name = name;
439                         }
440                         
441                         public string Name { get; set; }
442                 }
443
444                 [Test]
445                 public void DefaultValuesSeverlyAttributed ()
446                 {
447                         var t = new XamlType (typeof (TestClass3), sctx);
448                         Assert.IsNotNull (t.Invoker, "#1");
449                         Assert.IsFalse (t.IsNameValid, "#2"); // see #4
450                         Assert.IsFalse (t.IsUnknown, "#3");
451                         Assert.AreEqual ("XamlTypeTest+TestClass3", t.Name, "#4");
452                         Assert.AreEqual ("clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name, t.PreferredXamlNamespace, "#5");
453                         Assert.IsNull (t.TypeArguments, "#6");
454                         Assert.AreEqual (typeof (TestClass3), t.UnderlyingType, "#7");
455                         Assert.IsTrue (t.ConstructionRequiresArguments, "#8");
456                         Assert.IsFalse (t.IsArray, "#9");
457                         Assert.IsFalse (t.IsCollection, "#10");
458                         Assert.IsFalse (t.IsConstructible, "#11");
459                         Assert.IsFalse (t.IsDictionary, "#12");
460                         Assert.IsFalse (t.IsGeneric, "#13");
461                         Assert.IsFalse (t.IsMarkupExtension, "#14");
462                         Assert.IsFalse (t.IsNameScope, "#15");
463                         Assert.IsTrue (t.IsNullable, "#16");
464                         Assert.IsTrue (t.IsPublic, "#17");
465                         Assert.IsTrue (t.IsUsableDuringInitialization, "#18");
466                         Assert.IsTrue (t.IsWhitespaceSignificantCollection, "#19");
467                         Assert.IsFalse (t.IsXData, "#20");
468                         Assert.IsFalse (t.TrimSurroundingWhitespace, "#21");
469                         Assert.IsTrue (t.IsAmbient, "#22");
470                         Assert.IsNull (t.AllowedContentTypes, "#23");
471                         Assert.IsNull (t.ContentWrappers, "#24");
472                         Assert.IsNull (t.TypeConverter, "#25");
473                         Assert.IsNull (t.ValueSerializer, "#26");
474                         Assert.IsNotNull (t.ContentProperty, "#27");
475                         Assert.AreEqual ("Name", t.ContentProperty.Name, "#27-2");
476                         // Assert.IsNull (t.DeferringLoader, "#28");
477                         Assert.IsNull (t.MarkupExtensionReturnType, "#29");
478                         Assert.AreEqual (sctx, t.SchemaContext, "#30");
479                 }
480
481                 [Test]
482                 public void TypeConverter ()
483                 {
484                         Assert.IsNull (new XamlType (typeof (List<object>), sctx).TypeConverter, "#1");
485                         Assert.IsNotNull (new XamlType (typeof (object), sctx).TypeConverter, "#2");
486                         Assert.IsTrue (new XamlType (typeof (Uri), sctx).TypeConverter.ConverterInstance is UriTypeConverter, "#3");
487                         Assert.IsTrue (new XamlType (typeof (TimeSpan), sctx).TypeConverter.ConverterInstance is TimeSpanConverter, "#4");
488                         Assert.IsNull (new XamlType (typeof (XamlType), sctx).TypeConverter, "#5");
489                         Assert.IsTrue (new XamlType (typeof (char), sctx).TypeConverter.ConverterInstance is CharConverter, "#6");
490                 }
491                 
492                 [Test]
493                 public void TypeConverter_Type ()
494                 {
495                         TypeConveter_TypeOrTypeExtension (typeof (Type));
496                 }
497                 
498                 [Test]
499                 public void TypeConverter_TypeExtension ()
500                 {
501                         TypeConveter_TypeOrTypeExtension (typeof (TypeExtension));
502                 }
503                 
504                 void TypeConveter_TypeOrTypeExtension (Type type)
505                 {
506                         var xtc = new XamlType (type, sctx).TypeConverter;
507                         Assert.IsNotNull (xtc, "#7");
508                         var tc = xtc.ConverterInstance;
509                         Assert.IsNotNull (tc, "#7-2");
510                         Assert.IsFalse (tc.CanConvertTo (typeof (Type)), "#7-3");
511                         Assert.IsFalse (tc.CanConvertTo (typeof (XamlType)), "#7-4");
512                         Assert.IsTrue (tc.CanConvertTo (typeof (string)), "#7-5");
513                         Assert.AreEqual ("{http://schemas.microsoft.com/winfx/2006/xaml}TypeExtension", tc.ConvertToString (XamlLanguage.Type), "#7-6");
514                         Assert.IsFalse (tc.CanConvertFrom (typeof (Type)), "#7-7");
515                         Assert.IsFalse (tc.CanConvertFrom (typeof (XamlType)), "#7-8");
516                         // .NET returns true for type == typeof(Type) case here, which does not make sense. Disabling it now.
517                         //Assert.IsFalse (tc.CanConvertFrom (typeof (string)), "#7-9");
518                         try {
519                                 tc.ConvertFromString ("{http://schemas.microsoft.com/winfx/2006/xaml}TypeExtension");
520                                 Assert.Fail ("failure");
521                         } catch (NotSupportedException) {
522                         }
523                 }
524
525                 [Test]
526                 [Category ("NotWorking")]
527                 public void GetXamlNamespaces ()
528                 {
529                         var xt = new XamlType (typeof (string), new XamlSchemaContext (null, null));
530                         var l = xt.GetXamlNamespaces ();
531                         Assert.AreEqual (2, l.Count, "#1");
532                         Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [0], "#2");
533                         Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", l [1], "#3");
534                 }
535                 
536                 [Test]
537                 public void GetAliasedProperty ()
538                 {
539                         XamlMember xm;
540                         var xt = new XamlType (typeof (SeverlyAliasedClass), new XamlSchemaContext (null, null));
541                         xm = xt.GetAliasedProperty (XamlLanguage.Key);
542                         Assert.IsNotNull (xm, "#1");
543                         xm = xt.GetAliasedProperty (XamlLanguage.Name);
544                         Assert.IsNotNull (xm, "#2");
545                         xm = xt.GetAliasedProperty (XamlLanguage.Uid);
546                         Assert.IsNotNull (xm, "#3");
547                         xm = xt.GetAliasedProperty (XamlLanguage.Lang);
548                         Assert.IsNotNull (xm, "#4");
549                 }
550
551                 [DictionaryKeyProperty ("Key")]
552                 [RuntimeNameProperty ("RuntimeTypeName")]
553                 [UidProperty ("UUID")]
554                 [XmlLangProperty ("XmlLang")]
555                 public class SeverlyAliasedClass
556                 {
557                         public string Key { get; set; }
558                         public string RuntimeTypeName { get; set; }
559                         public string UUID { get; set; }
560                         public string XmlLang { get; set; }
561                 }
562
563                 [Test]
564                 public void ToStringTest ()
565                 {
566                         Assert.AreEqual ("{http://schemas.microsoft.com/winfx/2006/xaml}String", XamlLanguage.String.ToString (), "#1");
567                         Assert.AreEqual ("{http://schemas.microsoft.com/winfx/2006/xaml}TypeExtension", XamlLanguage.Type.ToString (), "#2");
568                         Assert.AreEqual ("{http://schemas.microsoft.com/winfx/2006/xaml}ArrayExtension", XamlLanguage.Array.ToString (), "#3");
569                 }
570         }
571
572         class MyXamlType : XamlType
573         {
574                 public MyXamlType (string fullName, IList<XamlType> typeArguments, XamlSchemaContext context)
575                         : base (fullName, typeArguments, context)
576                 {
577                 }
578         }
579 }