* support-test-*.cs: Rename from test-*-p2.cs.
[mono.git] / mcs / class / Microsoft.Web.Atlas / Test / Microsoft.Web.UI / TextBoxTest.cs
1 //
2 // Tests for Microsoft.Web.UI.TextBox
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 using Microsoft.Web.UI;
39
40 namespace MonoTests.Microsoft.Web.UI
41 {
42         [TestFixture]
43         public class TextBoxTest : ScriptControlTest
44         {
45                 [Test]
46                 public void Properties ()
47                 {
48                         TextBox t = new TextBox ();
49
50                         // defaults
51                         Assert.AreEqual ("textBox", t.TagName, "A1");
52                         Assert.AreEqual (1000, t.AutoCompletionInterval, "A2");
53                         Assert.AreEqual (3, t.AutoCompletionMinimumPrefixLength, "A3");
54                         Assert.AreEqual (null, t.AutoCompletionServiceMethod, "A4");
55                         Assert.AreEqual (null, t.AutoCompletionServiceUrl, "A5");
56                         Assert.AreEqual (10, t.AutoCompletionSetCount, "A6");
57                         Assert.AreEqual (0, t.Size, "A7");
58                         Assert.AreEqual ("", t.Text, "A8");
59
60                         // get/set
61                         t.AutoCompletionInterval = 5;
62                         Assert.AreEqual (5, t.AutoCompletionInterval, "A9");
63                         t.AutoCompletionMinimumPrefixLength = 50;
64                         Assert.AreEqual (50, t.AutoCompletionMinimumPrefixLength, "A10");
65                         t.AutoCompletionServiceMethod = "foo";
66                         Assert.AreEqual ("foo", t.AutoCompletionServiceMethod, "A11");
67                         t.AutoCompletionServiceUrl = "bar";
68                         Assert.AreEqual ("bar", t.AutoCompletionServiceUrl, "A12");
69                         t.AutoCompletionSetCount = 25;
70                         Assert.AreEqual (25, t.AutoCompletionSetCount, "A13");
71                         t.Size = 50;
72                         Assert.AreEqual (50, t.Size, "A14");
73                         t.Text = "hi";
74                         Assert.AreEqual ("hi", t.Text, "A15");
75
76                         // null set
77                         t.AutoCompletionServiceMethod = null;
78                         Assert.AreEqual (null, t.AutoCompletionServiceMethod, "A16");
79                         t.AutoCompletionServiceUrl = null;
80                         Assert.AreEqual (null, t.AutoCompletionServiceUrl, "A17");
81                         t.Text = null;
82                         Assert.AreEqual ("", t.Text, "A18");
83                 }
84
85                 [Test]
86                 public void TypeDescriptor ()
87                 {
88                         TextBox t = new TextBox();
89
90                         ScriptTypeDescriptor desc = ((IScriptObject)t).GetTypeDescriptor ();
91
92                         Assert.AreEqual (t, desc.ScriptObject, "A1");
93
94                         // events
95                         IEnumerable<ScriptEventDescriptor> events = desc.GetEvents();
96                         Assert.IsNotNull (events, "A2");
97
98                         IEnumerator<ScriptEventDescriptor> ee = events.GetEnumerator();
99                         Assert.IsTrue (ee.MoveNext(), "A3");
100                         DoEvent (ee.Current, "propertyChanged", true);
101                         Assert.IsFalse (ee.MoveNext(), "A4");
102
103                         // methods
104                         string[] args;
105                         IEnumerable<ScriptMethodDescriptor> methods = desc.GetMethods();
106                         Assert.IsNotNull (methods, "A5");
107
108                         IEnumerator<ScriptMethodDescriptor> me = methods.GetEnumerator();
109                         Assert.IsTrue (me.MoveNext(), "A6");
110                         args = new string[1];
111                         args[0] = "className";
112                         DoMethod (me.Current, "addCssClass", args);
113                         Assert.IsTrue (me.MoveNext(), "A7");
114                         DoMethod (me.Current, "focus", new string[0]);
115                         Assert.IsTrue (me.MoveNext(), "A8");
116                         DoMethod (me.Current, "scrollIntoView", new string[0]);
117                         Assert.IsTrue (me.MoveNext(), "A9");
118                         args = new string[1];
119                         args[0] = "className";
120                         DoMethod (me.Current, "removeCssClass", args);
121                         Assert.IsTrue (me.MoveNext(), "A10");
122                         args = new string[1];
123                         args[0] = "className";
124                         DoMethod (me.Current, "toggleCssClass", args);
125                         Assert.IsFalse (me.MoveNext (), "A10");
126
127                         // properties
128                         IEnumerable<ScriptPropertyDescriptor> props = desc.GetProperties();
129                         Assert.IsNotNull (props, "A11");
130
131                         IEnumerator<ScriptPropertyDescriptor> pe = props.GetEnumerator();
132                         Assert.IsTrue (pe.MoveNext(), "A12");
133                         DoProperty (pe.Current, "bindings", ScriptType.Array, true, "Bindings");
134                         Assert.IsTrue (pe.MoveNext(), "A13");
135                         DoProperty (pe.Current, "dataContext", ScriptType.Object, false, "");
136                         Assert.IsTrue (pe.MoveNext(), "A14");
137                         DoProperty (pe.Current, "id", ScriptType.String, false, "ID");
138                         Assert.IsTrue (pe.MoveNext(), "A15");
139                         DoProperty (pe.Current, "associatedElement", ScriptType.Object, true, "");
140                         Assert.IsTrue (pe.MoveNext(), "A16");
141                         DoProperty (pe.Current, "behaviors", ScriptType.Array, true, "Behaviors");
142                         Assert.IsTrue (pe.MoveNext(), "A17");
143                         DoProperty (pe.Current, "cssClass", ScriptType.String, false, "CssClass");
144                         Assert.IsTrue (pe.MoveNext(), "A18");
145                         DoProperty (pe.Current, "enabled", ScriptType.Boolean, false, "Enabled");
146                         Assert.IsTrue (pe.MoveNext(), "A19");
147                         DoProperty (pe.Current, "style", ScriptType.Object, true, "");
148                         Assert.IsTrue (pe.MoveNext(), "A20");
149                         DoProperty (pe.Current, "visible", ScriptType.Boolean, false, "Visible");
150                         Assert.IsTrue (pe.MoveNext(), "A21");
151                         DoProperty (pe.Current, "visibilityMode", ScriptType.Enum, false, "VisibilityMode");
152                         Assert.IsTrue (pe.MoveNext(), "A21");
153                         DoProperty (pe.Current, "validators", ScriptType.Array, true, "Validators");
154                         Assert.IsTrue (pe.MoveNext(), "A22");
155                         DoProperty (pe.Current, "text", ScriptType.String, false, "Text");
156                         Assert.IsFalse (pe.MoveNext(), "A23");
157                 }
158
159                 [Test]
160                 [ExpectedException (typeof (InvalidOperationException))]
161                 public void IsTypeDescriptorClosed ()
162                 {
163                         TextBox t = new TextBox ();
164                         ScriptTypeDescriptor desc = ((IScriptObject)t).GetTypeDescriptor ();
165
166                         desc.AddEvent (new ScriptEventDescriptor ("testEvent", true));
167                 }
168         }
169 }
170 #endif