2 // Copyright (C) 2010 Novell Inc. http://novell.com
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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.
24 using System.Collections;
25 using System.Collections.Generic;
26 using System.ComponentModel;
29 using System.Reflection;
30 using System.Windows.Markup;
32 using System.Xaml.Schema;
34 using NUnit.Framework;
35 using MonoTests.System.Xaml;
37 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
39 namespace MonoTests.System.Xaml
42 public class ValueSerializerContextTest
44 public static IServiceProvider Provider;
45 public static IValueSerializerContext Context {
46 get { return (IValueSerializerContext) Provider; }
47 set { Provider = value; }
56 [Category ("NotWorking")]
57 public void GetService ()
59 var obj = new TestValueSerialized ();
60 var xr = new XamlObjectReader (obj);
63 Assert.IsNotNull (Context, "premise#1");
64 GetServiceCoreReader ();
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);
75 Assert.IsNotNull (Provider, "premise#2"); // cannot get Context, it does not give IValueSerializerContext in the test.
76 GetServiceCoreWriter ();
79 void GetServiceCoreReader ()
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");
93 void GetServiceCoreWriter ()
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.
108 [Category ("NotWorking")]
109 public void NameResolver ()
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");