2 // Tests for Microsoft.Web.InvokeMethodAction
5 // Chris Toshok (toshok@ximian.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using NUnit.Framework;
35 using System.Collections.Generic;
39 namespace MonoTests.Microsoft.Web
42 public class InvokeMethodActionTest
45 public void Properties ()
47 InvokeMethodAction a = new InvokeMethodAction ();
50 Assert.AreEqual ("", a.Method, "A1");
51 Assert.AreEqual ("invokeMethod", a.TagName, "A2");
55 Assert.AreEqual ("method", a.Method, "A3");
59 Assert.AreEqual ("", a.Method, "A4");
65 InvokeMethodAction a = new InvokeMethodAction ();
69 // test an empty action
70 sw = new StringWriter();
71 w = new ScriptTextWriter (sw);
74 Assert.AreEqual ("<invokeMethod />", sw.ToString(), "A1");
79 sw = new StringWriter();
80 w = new ScriptTextWriter (sw);
83 Assert.AreEqual ("<invokeMethod method=\"method\" />", sw.ToString(), "A2");
85 // test with a target and id
89 sw = new StringWriter();
90 w = new ScriptTextWriter (sw);
93 Assert.AreEqual ("<invokeMethod id=\"invoke_id\" method=\"method\" />", sw.ToString(), "A3");
96 void DoEvent (ScriptEventDescriptor e, string eventName, bool supportsActions)
98 Assert.AreEqual (eventName, e.EventName, eventName + " EventName");
99 Assert.AreEqual (eventName, e.MemberName, eventName + " MemberName");
100 Assert.AreEqual (supportsActions, e.SupportsActions, eventName + " SupportsActions");
103 void DoProperty (ScriptPropertyDescriptor p, string propertyName, ScriptType type, bool readOnly, string serverPropertyName)
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");
113 public void TypeDescriptor ()
115 InvokeMethodAction a = new InvokeMethodAction();
116 ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor ();
118 Assert.AreEqual (a, desc.ScriptObject, "A1");
121 IEnumerable<ScriptEventDescriptor> events = desc.GetEvents();
122 Assert.IsNotNull (events, "A2");
124 IEnumerator<ScriptEventDescriptor> ee = events.GetEnumerator();
125 Assert.IsTrue (ee.MoveNext());
126 DoEvent (ee.Current, "propertyChanged", true);
127 Assert.IsFalse (ee.MoveNext());
130 IEnumerable<ScriptMethodDescriptor> methods = desc.GetMethods();
131 Assert.IsNotNull (methods, "A3");
133 IEnumerator<ScriptMethodDescriptor> me = methods.GetEnumerator();
134 Assert.IsFalse (me.MoveNext ());
137 IEnumerable<ScriptPropertyDescriptor> props = desc.GetProperties();
138 Assert.IsNotNull (props, "A4");
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");
163 [ExpectedException (typeof (InvalidOperationException))]
164 public void IsTypeDescriptorClosed ()
166 InvokeMethodAction a = new InvokeMethodAction();
167 ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor ();
169 desc.AddEvent (new ScriptEventDescriptor ("testEvent", true));