EditCommandColumnTest.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // Tests for System.Web.UI.WebControls.EditCommandColumn.cs
  3. //
  4. // Author:
  5. // Peter Dennis Bartok ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Data;
  33. using System.IO;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. namespace MonoTests.System.Web.UI.WebControls
  39. {
  40. [TestFixture]
  41. public class EditCommandColumnTest {
  42. private class DataGridTest : DataGrid {
  43. public ArrayList CreateColumns (PagedDataSource data_source, bool use_data_source) {
  44. return CreateColumnSet (data_source, use_data_source);
  45. }
  46. public void CreateControls (bool use_data_source) {
  47. CreateControlHierarchy (use_data_source);
  48. }
  49. }
  50. [Test]
  51. public void Defaults ()
  52. {
  53. EditCommandColumn e;
  54. e = new EditCommandColumn();
  55. Assert.AreEqual(ButtonColumnType.LinkButton, e.ButtonType, "D1");
  56. Assert.AreEqual(string.Empty, e.CancelText, "D2");
  57. Assert.AreEqual(string.Empty, e.EditText, "D3");
  58. Assert.AreEqual(string.Empty, e.UpdateText, "D4");
  59. }
  60. [Test]
  61. public void Properties () {
  62. EditCommandColumn e;
  63. e = new EditCommandColumn();
  64. e.ButtonType = ButtonColumnType.PushButton;
  65. Assert.AreEqual(ButtonColumnType.PushButton, e.ButtonType, "P1");
  66. e.CancelText = "Cancel this!";
  67. Assert.AreEqual("Cancel this!", e.CancelText, "D2");
  68. e.EditText = "Edit me good";
  69. Assert.AreEqual("Edit me good", e.EditText, "D3");
  70. e.UpdateText = "Update? What update?";
  71. Assert.AreEqual("Update? What update?", e.UpdateText, "D4");
  72. }
  73. private string ControlMarkup(Control c) {
  74. StringWriter sw = new StringWriter ();
  75. HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
  76. c.RenderControl (tw);
  77. return sw.ToString ();
  78. }
  79. private void ShowControlsRecursive (Control c, int depth) {
  80. StringWriter sw = new StringWriter ();
  81. HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
  82. c.RenderControl (tw);
  83. Console.WriteLine (sw.ToString ());
  84. Console.WriteLine (c);
  85. foreach (Control child in c.Controls)
  86. ShowControlsRecursive (child, depth + 5);
  87. }
  88. [Test]
  89. //[Ignore("Need a DataGrid ID rendering and DataGridColumn checked in")]
  90. public void InitializeCell () {
  91. DataGridTest p = new DataGridTest ();
  92. DataTable table = new DataTable ();
  93. EditCommandColumn e;
  94. string markup;
  95. e = new EditCommandColumn();
  96. e.ButtonType = ButtonColumnType.LinkButton;
  97. e.CancelText = "Cancel";
  98. e.EditText = "Edit";
  99. e.UpdateText = "Update";
  100. table.Columns.Add (new DataColumn ("one", typeof (string)));
  101. table.Columns.Add (new DataColumn ("two", typeof (string)));
  102. table.Columns.Add (new DataColumn ("three", typeof (string)));
  103. table.Rows.Add (new object [] { "1", "2", "3" });
  104. p.DataSource = new DataView (table);
  105. p.Columns.Add(e);
  106. e = new EditCommandColumn();
  107. e.ButtonType = ButtonColumnType.PushButton;
  108. e.CancelText = "Abbrechen";
  109. e.EditText = "Bearbeiten";
  110. e.UpdateText = "Refresh";
  111. p.Columns.Add(e);
  112. // This will trigger EditCommandColumn.InitializeCell, without any EditItem set, tests the EditText render
  113. p.CreateControls (true);
  114. p.ID = "sucker";
  115. Assert.AreEqual (2, p.Columns.Count, "I1");
  116. markup = ControlMarkup(p.Controls[0]);
  117. markup = markup.Replace("\t", "");
  118. markup = markup.Replace ("\r", "");
  119. markup = markup.Replace ("\n", "");
  120. #if NET_2_0
  121. Assert.AreEqual (
  122. "<table border=\"0\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  123. "</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>" +
  124. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  125. "</tr></table>", markup, "I2");
  126. #else
  127. Assert.AreEqual (
  128. "<table border=\"0\" id=\"sucker\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  129. "</tr><tr><td><a>Edit</a></td><td><input name type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
  130. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  131. "</tr></table>", markup, "I2");
  132. #endif
  133. //ShowControlsRecursive (p.Controls [0], 1);
  134. }
  135. [Test]
  136. public void InitializeEditCell () {
  137. DataGridTest p = new DataGridTest ();
  138. DataTable table = new DataTable ();
  139. EditCommandColumn e;
  140. string markup;
  141. e = new EditCommandColumn();
  142. e.ButtonType = ButtonColumnType.LinkButton;
  143. e.CancelText = "Cancel";
  144. e.EditText = "Edit";
  145. e.UpdateText = "Update";
  146. table.Columns.Add (new DataColumn ("one", typeof (string)));
  147. table.Columns.Add (new DataColumn ("two", typeof (string)));
  148. table.Columns.Add (new DataColumn ("three", typeof (string)));
  149. table.Rows.Add (new object [] { "1", "2", "3" });
  150. p.DataSource = new DataView (table);
  151. p.Columns.Add(e);
  152. e = new EditCommandColumn();
  153. e.ButtonType = ButtonColumnType.PushButton;
  154. e.CancelText = "Abbrechen";
  155. e.EditText = "Bearbeiten";
  156. e.UpdateText = "Refresh";
  157. p.Columns.Add(e);
  158. // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
  159. p.EditItemIndex = 0;
  160. // This will trigger EditCommandColumn.InitializeCell
  161. p.CreateControls (true);
  162. p.ID = "sucker";
  163. markup = ControlMarkup (p.Controls[0]);
  164. markup = markup.Replace ("\t", "");
  165. markup = markup.Replace ("\r", "");
  166. markup = markup.Replace ("\n", "");
  167. //Console.WriteLine("Markup:>{0}<", markup);
  168. Assert.AreEqual (2, p.Columns.Count, "I1");
  169. #if NET_2_0
  170. Assert.AreEqual (
  171. "<table border=\"0\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  172. "</tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name=\"sucker$ctl02$ctl00\" type=\"submit\" value=\"Refresh\" />&nbsp;" +
  173. "<input name=\"sucker$ctl02$ctl01\" type=\"submit\" value=\"Abbrechen\" /></td>" +
  174. "<td><input name=\"sucker$ctl02$ctl02\" type=\"text\" value=\"1\" /></td>" +
  175. "<td><input name=\"sucker$ctl02$ctl03\" type=\"text\" value=\"2\" /></td>" +
  176. "<td><input name=\"sucker$ctl02$ctl04\" type=\"text\" value=\"3\" /></td>" +
  177. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  178. "</tr></table>", markup, "I2");
  179. #else
  180. Assert.AreEqual (
  181. "<table border=\"0\" id=\"sucker\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  182. "</tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" />&nbsp;" +
  183. "<input name type=\"submit\" value=\"Abbrechen\" /></td>" +
  184. "<td><input name=\"sucker:_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
  185. "<td><input name=\"sucker:_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
  186. "<td><input name=\"sucker:_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
  187. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  188. "</tr></table>", markup, "I2");
  189. #endif
  190. }
  191. [Test]
  192. [Ignore("Unfinished")]
  193. public void InitializeReadOnlyEditCell ()
  194. {
  195. DataGridTest p = new DataGridTest ();
  196. DataTable table = new DataTable ();
  197. EditCommandColumn e;
  198. string markup;
  199. e = new EditCommandColumn ();
  200. e.ButtonType = ButtonColumnType.LinkButton;
  201. e.CancelText = "Cancel";
  202. e.EditText = "Edit";
  203. e.UpdateText = "Update";
  204. table.Columns.Add (new DataColumn ("one", typeof (string)));
  205. table.Columns.Add (new DataColumn ("two", typeof (string)));
  206. table.Columns.Add (new DataColumn ("three", typeof (string)));
  207. table.Rows.Add (new object[] { "1", "2", "3" });
  208. p.DataSource = new DataView (table);
  209. p.Columns.Add (e);
  210. e = new EditCommandColumn ();
  211. e.ButtonType = ButtonColumnType.PushButton;
  212. e.CancelText = "Abbrechen";
  213. e.EditText = "Bearbeiten";
  214. e.UpdateText = "Refresh";
  215. p.Columns.Add (e);
  216. // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
  217. p.EditItemIndex = 0;
  218. // This will trigger EditCommandColumn.InitializeCell
  219. p.CreateControls (true);
  220. p.ID = "sucker";
  221. markup = ControlMarkup (p.Controls[0]);
  222. markup = markup.Replace ("\t", "");
  223. markup = markup.Replace ("\r", "");
  224. markup = markup.Replace ("\n", "");
  225. Console.WriteLine ("Markup:>{0}<", markup);
  226. Assert.AreEqual (2, p.Columns.Count, "I1");
  227. Assert.AreEqual (
  228. "<table border=\"0\" id=\"sucker\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  229. "</tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" />&nbsp;" +
  230. "<input name value=\"Abbrechen\" type=\"submit\" /></td>" +
  231. "<td><input name=\"_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
  232. "<td><input name=\"_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
  233. "<td><input name=\"_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
  234. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  235. "</tr></table>", markup, "I2");
  236. }
  237. }
  238. }