EditCommandColumnTest.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  2. // Tests for System.Web.UI.WebControls.Style.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.Drawing;
  34. using System.IO;
  35. using System.Globalization;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.WebControls;
  39. namespace MonoTests.System.Web.UI.WebControls
  40. {
  41. [TestFixture]
  42. public class EditCommandColumnTest {
  43. private class DataGridTest : DataGrid {
  44. public ArrayList CreateColumns (PagedDataSource data_source, bool use_data_source) {
  45. return CreateColumnSet (data_source, use_data_source);
  46. }
  47. public void CreateControls (bool use_data_source) {
  48. CreateControlHierarchy (use_data_source);
  49. }
  50. }
  51. [Test]
  52. public void Defaults ()
  53. {
  54. EditCommandColumn e;
  55. e = new EditCommandColumn();
  56. Assert.AreEqual(ButtonColumnType.LinkButton, e.ButtonType, "D1");
  57. Assert.AreEqual(string.Empty, e.CancelText, "D2");
  58. Assert.AreEqual(string.Empty, e.EditText, "D3");
  59. Assert.AreEqual(string.Empty, e.UpdateText, "D4");
  60. }
  61. [Test]
  62. public void Properties () {
  63. EditCommandColumn e;
  64. e = new EditCommandColumn();
  65. e.ButtonType = ButtonColumnType.PushButton;
  66. Assert.AreEqual(ButtonColumnType.PushButton, e.ButtonType, "P1");
  67. e.CancelText = "Cancel this!";
  68. Assert.AreEqual("Cancel this!", e.CancelText, "D2");
  69. e.EditText = "Edit me good";
  70. Assert.AreEqual("Edit me good", e.EditText, "D3");
  71. e.UpdateText = "Update? What update?";
  72. Assert.AreEqual("Update? What update?", e.UpdateText, "D4");
  73. }
  74. private string ControlMarkup(Control c) {
  75. StringWriter sw = new StringWriter ();
  76. HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
  77. c.RenderControl (tw);
  78. return sw.ToString ();
  79. }
  80. private void ShowControlsRecursive (Control c, int depth) {
  81. StringWriter sw = new StringWriter ();
  82. HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
  83. c.RenderControl (tw);
  84. Console.WriteLine (sw.ToString ());
  85. Console.WriteLine (c);
  86. foreach (Control child in c.Controls)
  87. ShowControlsRecursive (child, depth + 5);
  88. }
  89. [Test]
  90. //[Ignore("Need a DataGrid ID rendering and DataGridColumn checked in")]
  91. public void InitializeCell () {
  92. DataGridTest p = new DataGridTest ();
  93. DataTable table = new DataTable ();
  94. EditCommandColumn e;
  95. string markup;
  96. e = new EditCommandColumn();
  97. e.ButtonType = ButtonColumnType.LinkButton;
  98. e.CancelText = "Cancel";
  99. e.EditText = "Edit";
  100. e.UpdateText = "Update";
  101. table.Columns.Add (new DataColumn ("one", typeof (string)));
  102. table.Columns.Add (new DataColumn ("two", typeof (string)));
  103. table.Columns.Add (new DataColumn ("three", typeof (string)));
  104. table.Rows.Add (new object [] { "1", "2", "3" });
  105. p.DataSource = new DataView (table);
  106. p.Columns.Add(e);
  107. e = new EditCommandColumn();
  108. e.ButtonType = ButtonColumnType.PushButton;
  109. e.CancelText = "Abbrechen";
  110. e.EditText = "Bearbeiten";
  111. e.UpdateText = "Refresh";
  112. p.Columns.Add(e);
  113. // This will trigger EditCommandColumn.InitializeCell, without any EditItem set, tests the EditText render
  114. p.CreateControls (true);
  115. p.ID = "sucker";
  116. Assert.AreEqual (2, p.Columns.Count, "I1");
  117. markup = ControlMarkup(p.Controls[0]);
  118. markup = markup.Replace("\t", "");
  119. markup = markup.Replace ("\r", "");
  120. markup = markup.Replace ("\n", "");
  121. Assert.AreEqual (
  122. "<table border=\"0\" id=\"sucker\"><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 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. //ShowControlsRecursive (p.Controls [0], 1);
  127. }
  128. [Test]
  129. public void InitializeEditCell () {
  130. DataGridTest p = new DataGridTest ();
  131. DataTable table = new DataTable ();
  132. EditCommandColumn e;
  133. string markup;
  134. e = new EditCommandColumn();
  135. e.ButtonType = ButtonColumnType.LinkButton;
  136. e.CancelText = "Cancel";
  137. e.EditText = "Edit";
  138. e.UpdateText = "Update";
  139. table.Columns.Add (new DataColumn ("one", typeof (string)));
  140. table.Columns.Add (new DataColumn ("two", typeof (string)));
  141. table.Columns.Add (new DataColumn ("three", typeof (string)));
  142. table.Rows.Add (new object [] { "1", "2", "3" });
  143. p.DataSource = new DataView (table);
  144. p.Columns.Add(e);
  145. e = new EditCommandColumn();
  146. e.ButtonType = ButtonColumnType.PushButton;
  147. e.CancelText = "Abbrechen";
  148. e.EditText = "Bearbeiten";
  149. e.UpdateText = "Refresh";
  150. p.Columns.Add(e);
  151. // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
  152. p.EditItemIndex = 0;
  153. // This will trigger EditCommandColumn.InitializeCell
  154. p.CreateControls (true);
  155. p.ID = "sucker";
  156. markup = ControlMarkup (p.Controls[0]);
  157. markup = markup.Replace ("\t", "");
  158. markup = markup.Replace ("\r", "");
  159. markup = markup.Replace ("\n", "");
  160. //Console.WriteLine("Markup:>{0}<", markup);
  161. Assert.AreEqual (2, p.Columns.Count, "I1");
  162. Assert.AreEqual (
  163. "<table border=\"0\" id=\"sucker\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  164. "</tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" />&nbsp;" +
  165. "<input name type=\"submit\" value=\"Abbrechen\" /></td>" +
  166. "<td><input name=\"sucker:_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
  167. "<td><input name=\"sucker:_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
  168. "<td><input name=\"sucker:_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
  169. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  170. "</tr></table>", markup, "I2");
  171. }
  172. [Test]
  173. [Ignore("Unfinished")]
  174. public void InitializeReadOnlyEditCell ()
  175. {
  176. DataGridTest p = new DataGridTest ();
  177. DataTable table = new DataTable ();
  178. EditCommandColumn e;
  179. string markup;
  180. e = new EditCommandColumn ();
  181. e.ButtonType = ButtonColumnType.LinkButton;
  182. e.CancelText = "Cancel";
  183. e.EditText = "Edit";
  184. e.UpdateText = "Update";
  185. table.Columns.Add (new DataColumn ("one", typeof (string)));
  186. table.Columns.Add (new DataColumn ("two", typeof (string)));
  187. table.Columns.Add (new DataColumn ("three", typeof (string)));
  188. table.Rows.Add (new object[] { "1", "2", "3" });
  189. p.DataSource = new DataView (table);
  190. p.Columns.Add (e);
  191. e = new EditCommandColumn ();
  192. e.ButtonType = ButtonColumnType.PushButton;
  193. e.CancelText = "Abbrechen";
  194. e.EditText = "Bearbeiten";
  195. e.UpdateText = "Refresh";
  196. p.Columns.Add (e);
  197. // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
  198. p.EditItemIndex = 0;
  199. // This will trigger EditCommandColumn.InitializeCell
  200. p.CreateControls (true);
  201. p.ID = "sucker";
  202. markup = ControlMarkup (p.Controls[0]);
  203. markup = markup.Replace ("\t", "");
  204. markup = markup.Replace ("\r", "");
  205. markup = markup.Replace ("\n", "");
  206. Console.WriteLine ("Markup:>{0}<", markup);
  207. Assert.AreEqual (2, p.Columns.Count, "I1");
  208. Assert.AreEqual (
  209. "<table border=\"0\" id=\"sucker\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  210. "</tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" />&nbsp;" +
  211. "<input name value=\"Abbrechen\" type=\"submit\" /></td>" +
  212. "<td><input name=\"_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
  213. "<td><input name=\"_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
  214. "<td><input name=\"_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
  215. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  216. "</tr></table>", markup, "I2");
  217. }
  218. }
  219. }