2010-04-08 Atsushi Enomoto <atsushi@ximian.com>
[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                 [ExpectedException (typeof (ArgumentNullException))]
58                 public void ConstructorComplexParamsTypeNull ()
59                 {
60                         new XamlDirective (new string [] {"urn:foo"}, "Foo", null, null, AllowedMemberLocations.Any);
61                 }
62
63                 [Test]
64                 [ExpectedException (typeof (ArgumentNullException))]
65                 public void ConstructorComplexParamsNullNamespaces ()
66                 {
67                         var d = new XamlDirective (null, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
68                 }
69
70                 [Test]
71                 public void ConstructorComplexParamsEmptyNamespaces ()
72                 {
73                         var d = new XamlDirective (new string [0], "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
74                 }
75
76                 [Test]
77                 public void ConstructorComplexParams ()
78                 {
79                         var d = new XamlDirective (new string [] {"urn:foo"}, "Foo", new XamlType (typeof (object), sctx), null, AllowedMemberLocations.Any);
80                 }
81
82                 [Test]
83                 public void DefaultValuesWithName ()
84                 {
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");
113                 }
114
115                 [Test]
116                 public void DefaultValuesWithComplexParams ()
117                 {
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");
146                 }
147         }
148 }