2 // Tests for System.Web.UI.WebControls.EditCommandColumn.cs
5 // Peter Dennis Bartok (pbartok@novell.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.
31 using NUnit.Framework;
33 using System.Collections;
36 using System.Globalization;
40 using System.Web.UI.WebControls;
42 namespace MonoTests.System.Web.UI.WebControls
48 public class EditCommandColumnTest {
50 private class DataGridTest : DataGrid {
51 public ArrayList CreateColumns (PagedDataSource data_source, bool use_data_source) {
52 return CreateColumnSet (data_source, use_data_source);
55 public void CreateControls (bool use_data_source) {
56 CreateControlHierarchy (use_data_source);
61 public void Defaults ()
65 e = new EditCommandColumn();
67 Assert.AreEqual(ButtonColumnType.LinkButton, e.ButtonType, "D1");
68 Assert.AreEqual(string.Empty, e.CancelText, "D2");
69 Assert.AreEqual(string.Empty, e.EditText, "D3");
70 Assert.AreEqual(string.Empty, e.UpdateText, "D4");
74 public void Properties () {
77 e = new EditCommandColumn();
79 e.ButtonType = ButtonColumnType.PushButton;
80 Assert.AreEqual(ButtonColumnType.PushButton, e.ButtonType, "P1");
82 e.CancelText = "Cancel this!";
83 Assert.AreEqual("Cancel this!", e.CancelText, "D2");
85 e.EditText = "Edit me good";
86 Assert.AreEqual("Edit me good", e.EditText, "D3");
88 e.UpdateText = "Update? What update?";
89 Assert.AreEqual("Update? What update?", e.UpdateText, "D4");
92 private string ControlMarkup(Control c) {
93 StringWriter sw = new StringWriter ();
94 HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
97 return sw.ToString ();
100 private void ShowControlsRecursive (Control c, int depth) {
101 StringWriter sw = new StringWriter ();
102 HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
104 c.RenderControl (tw);
105 Console.WriteLine (sw.ToString ());
107 Console.WriteLine (c);
109 foreach (Control child in c.Controls)
110 ShowControlsRecursive (child, depth + 5);
114 [Category ("NotDotNet")]
115 public void InitializeCell () {
116 DataGridTest p = new DataGridTest ();
117 DataTable table = new DataTable ();
121 e = new EditCommandColumn();
122 e.ButtonType = ButtonColumnType.LinkButton;
123 e.CancelText = "Cancel";
125 e.UpdateText = "Update";
127 table.Columns.Add (new DataColumn ("one", typeof (string)));
128 table.Columns.Add (new DataColumn ("two", typeof (string)));
129 table.Columns.Add (new DataColumn ("three", typeof (string)));
130 table.Rows.Add (new object [] { "1", "2", "3" });
132 p.DataSource = new DataView (table);
135 e = new EditCommandColumn();
136 e.ButtonType = ButtonColumnType.PushButton;
137 e.CancelText = "Abbrechen";
138 e.EditText = "Bearbeiten";
139 e.UpdateText = "Refresh";
142 // This will trigger EditCommandColumn.InitializeCell, without any EditItem set, tests the EditText render
143 p.CreateControls (true);
146 Assert.AreEqual (2, p.Columns.Count, "I1");
147 markup = ControlMarkup(p.Controls[0]);
148 markup = markup.Replace("\t", "");
149 markup = markup.Replace ("\r", "");
150 markup = markup.Replace ("\n", "");
154 "<table border=\"0\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
155 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker$ctl02$ctl00\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
156 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
157 "</tr></table>", markup, "I2");
160 "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
161 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker:_ctl1:_ctl0\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
162 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
163 "</tr></table>", markup, "I2");
165 //ShowControlsRecursive (p.Controls [0], 1);
169 [Category ("NotDotNet")]
170 public void ThisIsADGTest () {
171 DataGridTest p = new DataGridTest ();
172 DataTable table = new DataTable ();
176 e = new EditCommandColumn();
177 e.ButtonType = ButtonColumnType.LinkButton;
178 e.CancelText = "Cancel";
180 e.UpdateText = "Update";
182 table.Columns.Add (new DataColumn ("one", typeof (string)));
183 table.Columns.Add (new DataColumn ("two", typeof (string)));
184 table.Columns.Add (new DataColumn ("three", typeof (string)));
185 table.Rows.Add (new object [] { "1", "2", "3" });
187 p.DataSource = new DataView (table);
190 e = new EditCommandColumn();
191 e.ButtonType = ButtonColumnType.PushButton;
192 e.CancelText = "Abbrechen";
193 e.EditText = "Bearbeiten";
194 e.UpdateText = "Refresh";
197 p.CreateControls (true);
198 // This is the test we want to run: setting the ID of the table created by
199 // the datagrid overrides the using the ID of the datagrid itself and uses
200 // the table ClientID instead.
202 p.Controls [0].ID = "tbl";
204 Assert.AreEqual (2, p.Columns.Count, "I1");
205 markup = ControlMarkup(p.Controls[0]);
206 markup = markup.Replace("\t", "");
207 markup = markup.Replace ("\r", "");
208 markup = markup.Replace ("\n", "");
212 "<table border=\"0\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
213 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker_tbl$ctl02$ctl00\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
214 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
215 "</tr></table>", markup, "I2");
218 "<table border=\"0\" id=\"sucker_tbl\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
219 "</tr><tr><td><a>Edit</a></td><td><input name=\"sucker:_ctl1:_ctl0\" type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
220 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
221 "</tr></table>", markup, "I2");
225 static void GetHierarchy (ControlCollection coll, int level, StringBuilder sb)
227 foreach (Control c in coll) {
228 sb.AppendFormat ("{0}{1}\n", new string (' ', 2 * level), c.GetType ());
229 GetHierarchy (c.Controls, level + 1, sb);
234 [Category ("NotDotNet")]
235 public void InitializeEditCell () {
236 DataGridTest p = new DataGridTest ();
237 DataTable table = new DataTable ();
241 e = new EditCommandColumn();
242 e.ButtonType = ButtonColumnType.LinkButton;
243 e.CancelText = "Cancel";
245 e.UpdateText = "Update";
247 table.Columns.Add (new DataColumn ("one", typeof (string)));
248 table.Columns.Add (new DataColumn ("two", typeof (string)));
249 table.Columns.Add (new DataColumn ("three", typeof (string)));
250 table.Rows.Add (new object [] { "1", "2", "3" });
252 p.DataSource = new DataView (table);
255 e = new EditCommandColumn();
256 e.ButtonType = ButtonColumnType.PushButton;
257 e.CancelText = "Abbrechen";
258 e.EditText = "Bearbeiten";
259 e.UpdateText = "Refresh";
262 // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
265 // This will trigger EditCommandColumn.InitializeCell
266 p.CreateControls (true);
269 StringBuilder sb = new StringBuilder ();
270 GetHierarchy (p.Controls, 0, sb);
271 string h = sb.ToString ();
272 int x = h.IndexOf (".TextBox");
273 // These are from the BoundColumns
274 Assert.IsTrue (x != -1, "textbox1");
275 x = h.IndexOf (".TextBox", x + 1);
276 Assert.IsTrue (x != -1, "textbox2");
277 x = h.IndexOf (".TextBox", x + 1);
278 Assert.IsTrue (x != -1, "textbox3");
279 x = h.IndexOf (".TextBox", x + 1);
280 Assert.IsTrue (x == -1, "textbox-end");
282 markup = ControlMarkup (p.Controls[0]);
283 markup = markup.Replace ("\t", "");
284 markup = markup.Replace ("\r", "");
285 markup = markup.Replace ("\n", "");
287 //Console.WriteLine("Markup:>{0}<", markup);
288 Assert.AreEqual (2, p.Columns.Count, "I1");
292 "<table border=\"0\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
293 "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name=\"sucker$ctl02$ctl00\" type=\"submit\" value=\"Refresh\" /> " +
294 "<input name=\"sucker$ctl02$ctl01\" type=\"submit\" value=\"Abbrechen\" /></td>" +
295 "<td><input name=\"sucker$ctl02$ctl02\" type=\"text\" value=\"1\" /></td>" +
296 "<td><input name=\"sucker$ctl02$ctl03\" type=\"text\" value=\"2\" /></td>" +
297 "<td><input name=\"sucker$ctl02$ctl04\" type=\"text\" value=\"3\" /></td>" +
298 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
299 "</tr></table>", markup, "I2");
302 "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
303 "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name=\"sucker:_ctl1:_ctl0\" type=\"submit\" value=\"Refresh\" /> " +
304 "<input name=\"sucker:_ctl1:_ctl1\" type=\"submit\" value=\"Abbrechen\" /></td>" +
305 "<td><input name=\"sucker:_ctl1:_ctl2\" type=\"text\" value=\"1\" /></td>" +
306 "<td><input name=\"sucker:_ctl1:_ctl3\" type=\"text\" value=\"2\" /></td>" +
307 "<td><input name=\"sucker:_ctl1:_ctl4\" type=\"text\" value=\"3\" /></td>" +
308 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
309 "</tr></table>", markup, "I2");
314 [Ignore("Unfinished")]
315 public void InitializeReadOnlyEditCell ()
317 DataGridTest p = new DataGridTest ();
318 DataTable table = new DataTable ();
322 e = new EditCommandColumn ();
323 e.ButtonType = ButtonColumnType.LinkButton;
324 e.CancelText = "Cancel";
326 e.UpdateText = "Update";
328 table.Columns.Add (new DataColumn ("one", typeof (string)));
329 table.Columns.Add (new DataColumn ("two", typeof (string)));
330 table.Columns.Add (new DataColumn ("three", typeof (string)));
331 table.Rows.Add (new object[] { "1", "2", "3" });
333 p.DataSource = new DataView (table);
336 e = new EditCommandColumn ();
337 e.ButtonType = ButtonColumnType.PushButton;
339 e.CancelText = "Abbrechen";
340 e.EditText = "Bearbeiten";
341 e.UpdateText = "Refresh";
344 // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
347 // This will trigger EditCommandColumn.InitializeCell
348 p.CreateControls (true);
351 markup = ControlMarkup (p.Controls[0]);
352 markup = markup.Replace ("\t", "");
353 markup = markup.Replace ("\r", "");
354 markup = markup.Replace ("\n", "");
356 Assert.AreEqual (2, p.Columns.Count, "I1");
358 "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
359 "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" /> " +
360 "<input name value=\"Abbrechen\" type=\"submit\" /></td>" +
361 "<td><input name=\"_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
362 "<td><input name=\"_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
363 "<td><input name=\"_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
364 "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
365 "</tr></table>", markup, "I2");