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 [ExpectedException (typeof (ArgumentNullException))]
58 public void ConstructorComplexParamsTypeNull ()
60 new XamlDirective (new string [] {"urn:foo"}, "Foo", null, null, AllowedMemberLocations.Any);
64 [ExpectedException (typeof (ArgumentNullException))]
65 public void ConstructorComplexParamsNullNamespaces ()
67 var d = new XamlDirective (null, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
71 public void ConstructorComplexParamsEmptyNamespaces ()
73 var d = new XamlDirective (new string [0], "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
77 public void ConstructorComplexParams ()
79 var d = new XamlDirective (new string [] {"urn:foo"}, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
83 public void DefaultValuesWithName ()
85 var d = new XamlDirective ("urn:foo", "Foo");
86 Assert.AreEqual (AllowedMemberLocations.Any, d.AllowedLocation, "#1");
87 Assert.IsNull (d.DeclaringType, "#2");
88 Assert.IsNotNull (d.Invoker, "#3");
89 Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2");
90 Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3");
91 Assert.IsTrue (d.IsUnknown, "#4");
92 Assert.IsTrue (d.IsReadPublic, "#5");
93 Assert.IsTrue (d.IsWritePublic, "#6");
94 Assert.AreEqual ("Foo", d.Name, "#7");
95 Assert.IsTrue (d.IsNameValid, "#8");
96 Assert.AreEqual ("urn:foo", d.PreferredXamlNamespace, "#9");
97 Assert.IsNull (d.TargetType, "#10");
98 Assert.IsNotNull (d.Type, "#11");
99 Assert.AreEqual (typeof (object), d.Type.UnderlyingType, "#11-2");
100 Assert.IsNull (d.TypeConverter, "#12");
101 Assert.IsNull (d.ValueSerializer, "#13");
102 Assert.IsNull (d.DeferringLoader, "#14");
103 Assert.IsNull (d.UnderlyingMember, "#15");
104 Assert.IsFalse (d.IsReadOnly, "#16");
105 Assert.IsFalse (d.IsWriteOnly, "#17");
106 Assert.IsFalse (d.IsAttachable, "#18");
107 Assert.IsFalse (d.IsEvent, "#19");
108 Assert.IsTrue (d.IsDirective, "#20");
109 Assert.IsNotNull (d.DependsOn, "#21");
110 Assert.AreEqual (0, d.DependsOn.Count, "#21-2");
111 Assert.IsFalse (d.IsAmbient, "#22");
112 Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23");
116 public void DefaultValuesWithComplexParams ()
118 var d = new XamlDirective (new string [0], "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
119 Assert.AreEqual (AllowedMemberLocations.Any, d.AllowedLocation, "#1");
120 Assert.IsNull (d.DeclaringType, "#2");
121 Assert.IsNotNull (d.Invoker, "#3");
122 Assert.IsNull (d.Invoker.UnderlyingGetter, "#3-2");
123 Assert.IsNull (d.Invoker.UnderlyingSetter, "#3-3");
124 Assert.IsFalse (d.IsUnknown, "#4"); // different from another test
125 Assert.IsTrue (d.IsReadPublic, "#5");
126 Assert.IsTrue (d.IsWritePublic, "#6");
127 Assert.AreEqual ("Foo", d.Name, "#7");
128 Assert.IsTrue (d.IsNameValid, "#8");
129 Assert.AreEqual (null, d.PreferredXamlNamespace, "#9"); // different from another test (as we specified empty array above)
130 Assert.IsNull (d.TargetType, "#10");
131 Assert.IsNotNull (d.Type, "#11");
132 Assert.AreEqual (typeof (object), d.Type.UnderlyingType, "#11-2");
133 Assert.IsNull (d.TypeConverter, "#12");
134 Assert.IsNull (d.ValueSerializer, "#13");
135 Assert.IsNull (d.DeferringLoader, "#14");
136 Assert.IsNull (d.UnderlyingMember, "#15");
137 Assert.IsFalse (d.IsReadOnly, "#16");
138 Assert.IsFalse (d.IsWriteOnly, "#17");
139 Assert.IsFalse (d.IsAttachable, "#18");
140 Assert.IsFalse (d.IsEvent, "#19");
141 Assert.IsTrue (d.IsDirective, "#20");
142 Assert.IsNotNull (d.DependsOn, "#21");
143 Assert.AreEqual (0, d.DependsOn.Count, "#21-2");
144 Assert.IsFalse (d.IsAmbient, "#22");
145 Assert.AreEqual (DesignerSerializationVisibility.Visible, d.SerializationVisibility, "#23");