Finally got XData tests that make sense. Implemented IsXData.
[mono.git] / mcs / class / System.Xaml / Test / System.Xaml / ValueSerializerContextTest.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.IO;
28 using System.Linq;
29 using System.Reflection;
30 using System.Windows.Markup;
31 using System.Xaml;
32 using System.Xaml.Schema;
33 using System.Xml;
34 using NUnit.Framework;
35 using MonoTests.System.Xaml;
36
37 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
38
39 namespace MonoTests.System.Xaml
40 {
41         [TestFixture]
42         public class ValueSerializerContextTest
43         {
44                 public static IServiceProvider Provider;
45                 public static IValueSerializerContext Context {
46                         get { return (IValueSerializerContext) Provider; }
47                         set { Provider = value; }
48                 }
49
50                 [SetUp]
51                 public void Setup ()
52                 {
53                 }
54
55                 [Test]
56                 [Category ("NotWorking")]
57                 public void GetService ()
58                 {
59                         var obj = new TestValueSerialized ();
60                         var xr = new XamlObjectReader (obj);
61                         while (!xr.IsEof)
62                                 xr.Read ();
63                         Assert.IsNotNull (Context, "premise#1");
64                         GetServiceCoreReader ();
65
66                         Context = null;
67                         var ctx = new XamlSchemaContext ();
68                         var xw = new XamlObjectWriter (ctx);
69                         var xt = ctx.GetXamlType (obj.GetType ());
70                         xw.WriteStartObject (xt);
71                         xw.WriteStartMember (XamlLanguage.Initialization);
72                         xw.WriteValue ("v");
73                         xw.WriteEndMember ();
74                         xw.Close ();
75                         Assert.IsNotNull (Provider, "premise#2"); // cannot get Context, it does not give IValueSerializerContext in the test.
76                         GetServiceCoreWriter ();
77                 }
78                 
79                 void GetServiceCoreReader ()
80                 {
81                         //Assert.IsNull (Provider.GetService (typeof (IXamlNameResolver)), "#1");
82                         Assert.IsNotNull (Provider.GetService (typeof (IXamlNameProvider)), "#2");
83                         //Assert.IsNull (Provider.GetService (typeof (IXamlNamespaceResolver)), "#3");
84                         Assert.IsNotNull (Provider.GetService (typeof (INamespacePrefixLookup)), "#4");
85                         //Assert.IsNull (Provider.GetService (typeof (IXamlTypeResolver)), "#5");
86                         Assert.IsNotNull (Provider.GetService (typeof (IXamlSchemaContextProvider)), "#6");
87                         //Assert.IsNull (Provider.GetService (typeof (IAmbientProvider)), "#7");
88                         //Assert.IsNull (Provider.GetService (typeof (IAttachedPropertyStore)), "#8");
89                         //Assert.IsNull (Provider.GetService (typeof (IDestinationTypeProvider)), "#9");
90                         //Assert.IsNull (Provider.GetService (typeof (IXamlObjectWriterFactory)), "#10");
91                 }
92                 
93                 void GetServiceCoreWriter ()
94                 {
95                         Assert.IsNotNull (Provider.GetService (typeof (IXamlNameResolver)), "#1");
96                         //Assert.IsNull (Provider.GetService (typeof (IXamlNameProvider)), "#2");
97                         Assert.IsNotNull (Provider.GetService (typeof (IXamlNamespaceResolver)), "#3");
98                         //Assert.IsNull (Provider.GetService (typeof (INamespacePrefixLookup)), "#4");
99                         Assert.IsNotNull (Provider.GetService (typeof (IXamlTypeResolver)), "#5");
100                         Assert.IsNotNull (Provider.GetService (typeof (IXamlSchemaContextProvider)), "#6");
101                         Assert.IsNotNull (Provider.GetService (typeof (IAmbientProvider)), "#7");
102                         //Assert.IsNull (Provider.GetService (typeof (IAttachedPropertyStore)), "#8");
103                         Assert.IsNotNull (Provider.GetService (typeof (IDestinationTypeProvider)), "#9");
104                         //Assert.IsNull (Provider.GetService (typeof (IXamlObjectWriterFactory)), "#10"); -> call to this method causes some internal exception. Smells like a .NET bug.
105                 }
106
107                 [Test]
108                 [Category ("NotWorking")]
109                 public void NameResolver ()
110                 {
111                         var nr = (IXamlNameResolver) Provider.GetService (typeof (IXamlNameResolver));
112                         Assert.IsNull (nr.Resolve ("random"), "nr#1");
113                         //var ft = nr.GetFixupToken (new string [] {"random"}); -> causes internal error.
114                         //var ft = nr.GetFixupToken (new string [] {"random"}, true); -> causes internal error
115                         //var ft = nr.GetFixupToken (new string [0], false);
116                         //Assert.IsNotNull (ft, "nr#2");
117                 }
118         }
119 }