New tests.
[mono.git] / mcs / class / System.Xaml / Test / System.Xaml / XamlDirectiveTest.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.Reflection;
28 using System.Xaml;
29 using System.Xaml.Schema;
30 using NUnit.Framework;
31
32 using Category = NUnit.Framework.CategoryAttribute;
33
34 namespace MonoTests.System.Xaml
35 {
36         [TestFixture]
37         public class XamlDirectiveTest
38         {
39                 XamlSchemaContext sctx = new XamlSchemaContext (new XamlSchemaContextSettings ());
40
41                 [Test]
42                 public void ConstructorNameNull ()
43                 {
44                         // wow, it is allowed.
45                         var d = new XamlDirective (String.Empty, null);
46                         Assert.IsNull (d.Name, "#1");
47                 }
48
49                 [Test]
50                 [ExpectedException (typeof (ArgumentNullException))]
51                 public void ConstructorNamespaceNull ()
52                 {
53                         new XamlDirective (null, "Foo");
54                 }
55
56                 [Test]
57                 public void ConstructorNamespaceXamlNS ()
58                 {
59                         new XamlDirective (XamlLanguage.Xaml2006Namespace, "Foo");
60                 }
61
62                 [Test]
63                 [ExpectedException (typeof (ArgumentNullException))]
64                 public void ConstructorComplexParamsTypeNull ()
65                 {
66                         new XamlDirective (new string [] {"urn:foo"}, "Foo", null, null, AllowedMemberLocations.Any);
67                 }
68
69                 [Test]
70                 [ExpectedException (typeof (ArgumentNullException))]
71                 public void ConstructorComplexParamsNullNamespaces ()
72                 {
73                         var d = new XamlDirective (null, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
74                 }
75
76                 [Test]
77                 public void ConstructorComplexParamsEmptyNamespaces ()
78                 {
79                         var d = new XamlDirective (new string [0], "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
80                 }
81
82                 [Test]
83                 public void ConstructorComplexParams ()
84                 {
85                         var d = new XamlDirective (new string [] {"urn:foo"}, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
86                 }
87
88                 [Test]
89                 public void DefaultValuesWithName ()
90                 {
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");
119                 }
120
121                 [Test]
122                 public void DefaultValuesWithComplexParams ()
123                 {
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");
152                 }
153         }
154 }