* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.Web.Atlas / Test / Microsoft.Web / InvokeMethodActionTest.cs
1 //
2 // Tests for Microsoft.Web.InvokeMethodAction
3 //
4 // Author:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32
33 using NUnit.Framework;
34 using System;
35 using System.Collections.Generic;
36 using System.IO;
37 using Microsoft.Web;
38
39 namespace MonoTests.Microsoft.Web
40 {
41         [TestFixture]
42         public class InvokeMethodActionTest
43         {
44                 [Test]
45                 public void Properties ()
46                 {
47                         InvokeMethodAction a = new InvokeMethodAction ();
48
49                         // default
50                         Assert.AreEqual ("", a.Method, "A1");
51                         Assert.AreEqual ("invokeMethod", a.TagName, "A2");
52
53                         // getter/setter
54                         a.Method = "method";
55                         Assert.AreEqual ("method", a.Method, "A3");
56
57                         // setting to null
58                         a.Method = null;
59                         Assert.AreEqual ("", a.Method, "A4");
60                 }
61
62                 [Test]
63                 public void Render ()
64                 {
65                         InvokeMethodAction a = new InvokeMethodAction ();
66                         StringWriter sw;
67                         ScriptTextWriter w;
68
69                         // test an empty action
70                         sw = new StringWriter();
71                         w = new ScriptTextWriter (sw);
72                         a.RenderAction (w);
73
74                         Assert.AreEqual ("<invokeMethod />", sw.ToString(), "A1");
75
76                         // test with a target
77                         a.Method = "method";
78
79                         sw = new StringWriter();
80                         w = new ScriptTextWriter (sw);
81                         a.RenderAction (w);
82
83                         Assert.AreEqual ("<invokeMethod method=\"method\" />", sw.ToString(), "A2");
84
85                         // test with a target and id
86                         a.ID = "invoke_id";
87                         a.Method = "method";
88
89                         sw = new StringWriter();
90                         w = new ScriptTextWriter (sw);
91                         a.RenderAction (w);
92
93                         Assert.AreEqual ("<invokeMethod id=\"invoke_id\" method=\"method\" />", sw.ToString(), "A3");
94                 }
95
96                 void DoEvent (ScriptEventDescriptor e, string eventName, bool supportsActions)
97                 {
98                         Assert.AreEqual (eventName, e.EventName, eventName + " EventName");
99                         Assert.AreEqual (eventName, e.MemberName, eventName + " MemberName");
100                         Assert.AreEqual (supportsActions, e.SupportsActions, eventName + " SupportsActions");
101                 }
102
103                 void DoProperty (ScriptPropertyDescriptor p, string propertyName, ScriptType type, bool readOnly, string serverPropertyName)
104                 {
105                         Assert.AreEqual (propertyName, p.PropertyName, propertyName + " PropertyName");
106                         Assert.AreEqual (propertyName, p.MemberName, propertyName + " MemberName");
107                         Assert.AreEqual (serverPropertyName, p.ServerPropertyName, propertyName + " ServerPropertyName");
108                         Assert.AreEqual (readOnly, p.ReadOnly, propertyName + " ReadOnly");
109                         Assert.AreEqual (type, p.Type, propertyName + " Type");
110                 }
111
112                 [Test]
113                 public void TypeDescriptor ()
114                 {
115                         InvokeMethodAction a = new InvokeMethodAction();
116                         ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor ();
117
118                         Assert.AreEqual (a, desc.ScriptObject, "A1");
119
120                         // events
121                         IEnumerable<ScriptEventDescriptor> events = desc.GetEvents();
122                         Assert.IsNotNull (events, "A2");
123
124                         IEnumerator<ScriptEventDescriptor> ee = events.GetEnumerator();
125                         Assert.IsTrue (ee.MoveNext());
126                         DoEvent (ee.Current, "propertyChanged", true);
127                         Assert.IsFalse (ee.MoveNext());
128
129                         // methods
130                         IEnumerable<ScriptMethodDescriptor> methods = desc.GetMethods();
131                         Assert.IsNotNull (methods, "A3");
132
133                         IEnumerator<ScriptMethodDescriptor> me = methods.GetEnumerator();
134                         Assert.IsFalse (me.MoveNext ());
135
136                         // properties
137                         IEnumerable<ScriptPropertyDescriptor> props = desc.GetProperties();
138                         Assert.IsNotNull (props, "A4");
139
140                         IEnumerator<ScriptPropertyDescriptor> pe = props.GetEnumerator();
141                         Assert.IsTrue (pe.MoveNext(), "A5");
142                         DoProperty (pe.Current, "bindings", ScriptType.Array, true, "Bindings");
143                         Assert.IsTrue (pe.MoveNext(), "A6");
144                         DoProperty (pe.Current, "dataContext", ScriptType.Object, false, "");
145                         Assert.IsTrue (pe.MoveNext(), "A7");
146                         DoProperty (pe.Current, "id", ScriptType.String, false, "ID");
147                         Assert.IsTrue (pe.MoveNext(), "A8");
148                         DoProperty (pe.Current, "eventArgs", ScriptType.Object, false, "");
149                         Assert.IsTrue (pe.MoveNext(), "A9");
150                         DoProperty (pe.Current, "result", ScriptType.Object, false, "");
151                         Assert.IsTrue (pe.MoveNext(), "A10");
152                         DoProperty (pe.Current, "sender", ScriptType.Object, false, "");
153                         Assert.IsTrue (pe.MoveNext(), "A11");
154                         DoProperty (pe.Current, "sequence", ScriptType.Enum, false, "Sequence");
155                         Assert.IsTrue (pe.MoveNext(), "A12");
156                         DoProperty (pe.Current, "target", ScriptType.Object, false, "Target");
157                         Assert.IsTrue (pe.MoveNext(), "A13");
158                         DoProperty (pe.Current, "method", ScriptType.String, false, "Method");
159                         Assert.IsFalse (pe.MoveNext(), "A14");
160                 }
161
162                 [Test]
163                 [ExpectedException (typeof (InvalidOperationException))]
164                 public void IsTypeDescriptorClosed ()
165                 {
166                         InvokeMethodAction a = new InvokeMethodAction();
167                         ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor ();
168
169                         desc.AddEvent (new ScriptEventDescriptor ("testEvent", true));
170                 }
171         }
172 }
173 #endif