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;
27 using System.Reflection;
29 using System.Xaml.Schema;
30 using NUnit.Framework;
32 using Category = NUnit.Framework.CategoryAttribute;
34 namespace MonoTests.System.Xaml
37 public class XamlDirectiveTest
39 XamlSchemaContext sctx = new XamlSchemaContext (new XamlSchemaContextSettings ());
42 public void ConstructorNameNull ()
44 // wow, it is allowed.
45 var d = new XamlDirective (String.Empty, null);
46 Assert.IsNull (d.Name, "#1");
50 [ExpectedException (typeof (ArgumentNullException))]
51 public void ConstructorNamespaceNull ()
53 new XamlDirective (null, "Foo");
57 public void ConstructorNamespaceXamlNS ()
59 new XamlDirective (XamlLanguage.Xaml2006Namespace, "Foo");
63 [ExpectedException (typeof (ArgumentNullException))]
64 public void ConstructorComplexParamsTypeNull ()
66 new XamlDirective (new string [] {"urn:foo"}, "Foo", null, null, AllowedMemberLocations.Any);
70 [ExpectedException (typeof (ArgumentNullException))]
71 public void ConstructorComplexParamsNullNamespaces ()
73 var d = new XamlDirective (null, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
77 public void ConstructorComplexParamsEmptyNamespaces ()
79 var d = new XamlDirective (new string [0], "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
83 public void ConstructorComplexParams ()
85 var d = new XamlDirective (new string [] {"urn:foo"}, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
89 public void DefaultValuesWithName ()
91 var d = new XamlDirective ("urn:foo", "Foo");
92 Assert.AreEqual (AllowedMemberLocations.Any, d.AllowedLocation, "#1");
93 Assert.IsNull (d.DeclaringType, "#2");
94 Assert.IsNotNull (d.Invoker, "#3");
95 Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2");
96 Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3");
97 Assert.IsTrue (d.IsUnknown, "#4");
98 Assert.IsTrue (d.IsReadPublic, "#5");
99 Assert.IsTrue (d.IsWritePublic, "#6");
100 Assert.AreEqual ("Foo", d.Name, "#7");
101 Assert.IsTrue (d.IsNameValid, "#8");
102 Assert.AreEqual ("urn:foo", d.PreferredXamlNamespace, "#9");
103 Assert.IsNull (d.TargetType, "#10");
104 Assert.IsNotNull (d.Type, "#11");
105 Assert.AreEqual (typeof (object), d.Type.UnderlyingType, "#11-2");
106 Assert.IsNull (d.TypeConverter, "#12");
107 Assert.IsNull (d.ValueSerializer, "#13");
108 Assert.IsNull (d.DeferringLoader, "#14");
109 Assert.IsNull (d.UnderlyingMember, "#15");
110 Assert.IsFalse (d.IsReadOnly, "#16");
111 Assert.IsFalse (d.IsWriteOnly, "#17");
112 Assert.IsFalse (d.IsAttachable, "#18");
113 Assert.IsFalse (d.IsEvent, "#19");
114 Assert.IsTrue (d.IsDirective, "#20");
115 Assert.IsNotNull (d.DependsOn, "#21");
116 Assert.AreEqual (0, d.DependsOn.Count, "#21-2");
117 Assert.IsFalse (d.IsAmbient, "#22");
118 Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23");
122 public void DefaultValuesWithComplexParams ()
124 var d = new XamlDirective (new string [0], "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
125 Assert.AreEqual (AllowedMemberLocations.Any, d.AllowedLocation, "#1");
126 Assert.IsNull (d.DeclaringType, "#2");
127 Assert.IsNotNull (d.Invoker, "#3");
128 Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2");
129 Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3");
130 Assert.IsFalse (d.IsUnknown, "#4"); // different from another test
131 Assert.IsTrue (d.IsReadPublic, "#5");
132 Assert.IsTrue (d.IsWritePublic, "#6");
133 Assert.AreEqual ("Foo", d.Name, "#7");
134 Assert.IsTrue (d.IsNameValid, "#8");
135 Assert.AreEqual (null, d.PreferredXamlNamespace, "#9"); // different from another test (as we specified empty array above)
136 Assert.IsNull (d.TargetType, "#10");
137 Assert.IsNotNull (d.Type, "#11");
138 Assert.AreEqual (typeof (object), d.Type.UnderlyingType, "#11-2");
139 Assert.IsNull (d.TypeConverter, "#12");
140 Assert.IsNull (d.ValueSerializer, "#13");
141 Assert.IsNull (d.DeferringLoader, "#14");
142 Assert.IsNull (d.UnderlyingMember, "#15");
143 Assert.IsFalse (d.IsReadOnly, "#16");
144 Assert.IsFalse (d.IsWriteOnly, "#17");
145 Assert.IsFalse (d.IsAttachable, "#18");
146 Assert.IsFalse (d.IsEvent, "#19");
147 Assert.IsTrue (d.IsDirective, "#20");
148 Assert.IsNotNull (d.DependsOn, "#21");
149 Assert.AreEqual (0, d.DependsOn.Count, "#21-2");
150 Assert.IsFalse (d.IsAmbient, "#22");
151 Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23");