2
0

EditCommandColumnTest.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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.Text;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.WebControls;
  39. using MonoTests.stand_alone.WebHarness;
  40. using MonoTests.SystemWeb.Framework;
  41. namespace MonoTests.System.Web.UI.WebControls
  42. {
  43. [TestFixture]
  44. public class EditCommandColumnTest {
  45. private class DataGridTest : DataGrid {
  46. public ArrayList CreateColumns (PagedDataSource data_source, bool use_data_source) {
  47. return CreateColumnSet (data_source, use_data_source);
  48. }
  49. public void CreateControls (bool use_data_source) {
  50. CreateControlHierarchy (use_data_source);
  51. }
  52. }
  53. [Test]
  54. public void Defaults ()
  55. {
  56. EditCommandColumn e;
  57. e = new EditCommandColumn();
  58. Assert.AreEqual(ButtonColumnType.LinkButton, e.ButtonType, "D1");
  59. Assert.AreEqual(string.Empty, e.CancelText, "D2");
  60. Assert.AreEqual(string.Empty, e.EditText, "D3");
  61. Assert.AreEqual(string.Empty, e.UpdateText, "D4");
  62. Assert.AreEqual (true, e.CausesValidation, "CausesValidation");
  63. Assert.AreEqual (string.Empty, e.ValidationGroup, "ValidationGroup");
  64. }
  65. [Test]
  66. public void Properties () {
  67. EditCommandColumn e;
  68. e = new EditCommandColumn();
  69. e.ButtonType = ButtonColumnType.PushButton;
  70. Assert.AreEqual(ButtonColumnType.PushButton, e.ButtonType, "P1");
  71. e.CancelText = "Cancel this!";
  72. Assert.AreEqual("Cancel this!", e.CancelText, "D2");
  73. e.EditText = "Edit me good";
  74. Assert.AreEqual("Edit me good", e.EditText, "D3");
  75. e.UpdateText = "Update? What update?";
  76. Assert.AreEqual("Update? What update?", e.UpdateText, "D4");
  77. e.CausesValidation = false;
  78. Assert.AreEqual (false, e.CausesValidation, "CausesValidation");
  79. e.ValidationGroup = "test";
  80. Assert.AreEqual ("test", e.ValidationGroup, "ValidationGroup");
  81. }
  82. private string ControlMarkup(Control c) {
  83. StringWriter sw = new StringWriter ();
  84. HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
  85. c.RenderControl (tw);
  86. return sw.ToString ();
  87. }
  88. private void ShowControlsRecursive (Control c, int depth) {
  89. StringWriter sw = new StringWriter ();
  90. HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
  91. c.RenderControl (tw);
  92. Console.WriteLine (sw.ToString ());
  93. Console.WriteLine (c);
  94. foreach (Control child in c.Controls)
  95. ShowControlsRecursive (child, depth + 5);
  96. }
  97. [Test]
  98. public void InitializeCell ()
  99. {
  100. string origHtml = "<table><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td></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></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>";
  101. DataGridTest p = new DataGridTest ();
  102. DataTable table = new DataTable ();
  103. EditCommandColumn e;
  104. string markup;
  105. e = new EditCommandColumn();
  106. e.ButtonType = ButtonColumnType.LinkButton;
  107. e.CancelText = "Cancel";
  108. e.EditText = "Edit";
  109. e.UpdateText = "Update";
  110. table.Columns.Add (new DataColumn ("one", typeof (string)));
  111. table.Columns.Add (new DataColumn ("two", typeof (string)));
  112. table.Columns.Add (new DataColumn ("three", typeof (string)));
  113. table.Rows.Add (new object [] { "1", "2", "3" });
  114. p.DataSource = new DataView (table);
  115. p.Columns.Add(e);
  116. e = new EditCommandColumn();
  117. e.ButtonType = ButtonColumnType.PushButton;
  118. e.CancelText = "Abbrechen";
  119. e.EditText = "Bearbeiten";
  120. e.UpdateText = "Refresh";
  121. p.Columns.Add(e);
  122. // This will trigger EditCommandColumn.InitializeCell, without any EditItem set, tests the EditText render
  123. p.CreateControls (true);
  124. p.ID = "sucker";
  125. Assert.AreEqual (2, p.Columns.Count, "I1");
  126. markup = ControlMarkup(p.Controls[0]);
  127. markup = markup.Replace("\t", "");
  128. markup = markup.Replace ("\r", "");
  129. markup = markup.Replace ("\n", "");
  130. HtmlDiff.AssertAreEqual (origHtml, markup, "I2");
  131. //ShowControlsRecursive (p.Controls [0], 1);
  132. }
  133. [Test]
  134. public void ThisIsADGTest ()
  135. {
  136. string origHtml = "<table id=\"sucker_tbl\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td></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></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>";
  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. p.CreateControls (true);
  159. // This is the test we want to run: setting the ID of the table created by
  160. // the datagrid overrides the using the ID of the datagrid itself and uses
  161. // the table ClientID instead.
  162. p.ID = "sucker";
  163. p.Controls [0].ID = "tbl";
  164. Assert.AreEqual (2, p.Columns.Count, "I1");
  165. markup = ControlMarkup(p.Controls[0]);
  166. markup = markup.Replace("\t", "");
  167. markup = markup.Replace ("\r", "");
  168. markup = markup.Replace ("\n", "");
  169. HtmlDiff.AssertAreEqual (origHtml, markup, "I2");
  170. }
  171. static void GetHierarchy (ControlCollection coll, int level, StringBuilder sb)
  172. {
  173. foreach (Control c in coll) {
  174. sb.AppendFormat ("{0}{1}\n", new string (' ', 2 * level), c.GetType ());
  175. GetHierarchy (c.Controls, level + 1, sb);
  176. }
  177. }
  178. [Test]
  179. public void InitializeEditCell ()
  180. {
  181. string origHtml = "<table><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td></tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name=\"sucker$ctl02$ctl00\" type=\"submit\" value=\"Refresh\" />&nbsp;<input name=\"sucker$ctl02$ctl01\" type=\"submit\" value=\"Abbrechen\" /></td><td><input name=\"sucker$ctl02$ctl02\" type=\"text\" value=\"1\" /></td><td><input name=\"sucker$ctl02$ctl03\" type=\"text\" value=\"2\" /></td><td><input name=\"sucker$ctl02$ctl04\" type=\"text\" value=\"3\" /></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>";
  182. DataGridTest p = new DataGridTest ();
  183. DataTable table = new DataTable ();
  184. EditCommandColumn e;
  185. string markup;
  186. e = new EditCommandColumn();
  187. e.ButtonType = ButtonColumnType.LinkButton;
  188. e.CancelText = "Cancel";
  189. e.EditText = "Edit";
  190. e.UpdateText = "Update";
  191. table.Columns.Add (new DataColumn ("one", typeof (string)));
  192. table.Columns.Add (new DataColumn ("two", typeof (string)));
  193. table.Columns.Add (new DataColumn ("three", typeof (string)));
  194. table.Rows.Add (new object [] { "1", "2", "3" });
  195. p.DataSource = new DataView (table);
  196. p.Columns.Add(e);
  197. e = new EditCommandColumn();
  198. e.ButtonType = ButtonColumnType.PushButton;
  199. e.CancelText = "Abbrechen";
  200. e.EditText = "Bearbeiten";
  201. e.UpdateText = "Refresh";
  202. p.Columns.Add(e);
  203. // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
  204. p.EditItemIndex = 0;
  205. // This will trigger EditCommandColumn.InitializeCell
  206. p.CreateControls (true);
  207. p.ID = "sucker";
  208. StringBuilder sb = new StringBuilder ();
  209. GetHierarchy (p.Controls, 0, sb);
  210. string h = sb.ToString ();
  211. int x = h.IndexOf (".TextBox");
  212. // These are from the BoundColumns
  213. Assert.IsTrue (x != -1, "textbox1");
  214. x = h.IndexOf (".TextBox", x + 1);
  215. Assert.IsTrue (x != -1, "textbox2");
  216. x = h.IndexOf (".TextBox", x + 1);
  217. Assert.IsTrue (x != -1, "textbox3");
  218. x = h.IndexOf (".TextBox", x + 1);
  219. Assert.IsTrue (x == -1, "textbox-end");
  220. markup = ControlMarkup (p.Controls[0]);
  221. markup = markup.Replace ("\t", "");
  222. markup = markup.Replace ("\r", "");
  223. markup = markup.Replace ("\n", "");
  224. //Console.WriteLine("Markup:>{0}<", markup);
  225. Assert.AreEqual (2, p.Columns.Count, "I1");
  226. HtmlDiff.AssertAreEqual (origHtml, markup, "I2");
  227. }
  228. [Test]
  229. [Ignore("Unfinished")]
  230. public void InitializeReadOnlyEditCell ()
  231. {
  232. DataGridTest p = new DataGridTest ();
  233. DataTable table = new DataTable ();
  234. EditCommandColumn e;
  235. string markup;
  236. e = new EditCommandColumn ();
  237. e.ButtonType = ButtonColumnType.LinkButton;
  238. e.CancelText = "Cancel";
  239. e.EditText = "Edit";
  240. e.UpdateText = "Update";
  241. table.Columns.Add (new DataColumn ("one", typeof (string)));
  242. table.Columns.Add (new DataColumn ("two", typeof (string)));
  243. table.Columns.Add (new DataColumn ("three", typeof (string)));
  244. table.Rows.Add (new object[] { "1", "2", "3" });
  245. p.DataSource = new DataView (table);
  246. p.Columns.Add (e);
  247. e = new EditCommandColumn ();
  248. e.ButtonType = ButtonColumnType.PushButton;
  249. e.CancelText = "Abbrechen";
  250. e.EditText = "Bearbeiten";
  251. e.UpdateText = "Refresh";
  252. p.Columns.Add (e);
  253. // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
  254. p.EditItemIndex = 0;
  255. // This will trigger EditCommandColumn.InitializeCell
  256. p.CreateControls (true);
  257. p.ID = "sucker";
  258. markup = ControlMarkup (p.Controls[0]);
  259. markup = markup.Replace ("\t", "");
  260. markup = markup.Replace ("\r", "");
  261. markup = markup.Replace ("\n", "");
  262. Assert.AreEqual (2, p.Columns.Count, "I1");
  263. Assert.AreEqual (
  264. "<table border=\"0\" id=\"sucker\"><tr><td>&nbsp;</td><td>&nbsp;</td><td>one</td><td>two</td><td>three</td>" +
  265. "</tr><tr><td><a>Update</a>&nbsp;<a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" />&nbsp;" +
  266. "<input name value=\"Abbrechen\" type=\"submit\" /></td>" +
  267. "<td><input name=\"_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
  268. "<td><input name=\"_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
  269. "<td><input name=\"_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
  270. "</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>" +
  271. "</tr></table>", markup, "I2");
  272. }
  273. [Test]
  274. [Category ("NunitWeb")]
  275. public void Validation_ValidatingValid ()
  276. {
  277. WebTest t = new WebTest ();
  278. PageDelegates pd = new PageDelegates ();
  279. pd.Load = Validation_Load;
  280. pd.PreRender = Validation_PreRender;
  281. t.Invoker = new PageInvoker (pd);
  282. t.UserData = "ValidatingValid";
  283. string html = t.Run ();
  284. FormRequest fr = new FormRequest (t.Response, "form1");
  285. fr.Controls.Add ("__EVENTTARGET");
  286. fr.Controls.Add ("__EVENTARGUMENT");
  287. fr.Controls ["__EVENTTARGET"].Value = (string) t.UserData;
  288. fr.Controls ["__EVENTARGUMENT"].Value = "";
  289. t.Request = fr;
  290. t.UserData = "ValidatingValid";
  291. html = t.Run ();
  292. }
  293. [Test]
  294. [Category ("NunitWeb")]
  295. [Ignore ("Possibly incorrectly constructed test - conflicts with fix for bug #471305")]
  296. public void Validation_ValidatingInvalid () {
  297. WebTest t = new WebTest ();
  298. PageDelegates pd = new PageDelegates ();
  299. pd.Load = Validation_Load;
  300. pd.PreRender = Validation_PreRender;
  301. t.Invoker = new PageInvoker (pd);
  302. t.UserData = "ValidatingInvalid";
  303. string html = t.Run ();
  304. FormRequest fr = new FormRequest (t.Response, "form1");
  305. fr.Controls.Add ("__EVENTTARGET");
  306. fr.Controls.Add ("__EVENTARGUMENT");
  307. fr.Controls ["__EVENTTARGET"].Value = (string)t.UserData;
  308. fr.Controls ["__EVENTARGUMENT"].Value = "";
  309. t.Request = fr;
  310. t.UserData = "ValidatingInvalid";
  311. html = t.Run ();
  312. }
  313. [Test]
  314. [Category ("NunitWeb")]
  315. public void Validation_NotValidatingInvalid () {
  316. WebTest t = new WebTest ();
  317. PageDelegates pd = new PageDelegates ();
  318. pd.Load = Validation_Load;
  319. pd.PreRender = Validation_PreRender;
  320. t.Invoker = new PageInvoker (pd);
  321. t.UserData = "NotValidatingInvalid";
  322. string html = t.Run ();
  323. FormRequest fr = new FormRequest (t.Response, "form1");
  324. fr.Controls.Add ("__EVENTTARGET");
  325. fr.Controls.Add ("__EVENTARGUMENT");
  326. fr.Controls ["__EVENTTARGET"].Value = (string) t.UserData;
  327. fr.Controls ["__EVENTARGUMENT"].Value = "";
  328. t.Request = fr;
  329. t.UserData = "NotValidatingInvalid";
  330. html = t.Run ();
  331. }
  332. [Test]
  333. [Category ("NunitWeb")]
  334. [Ignore ("Possibly incorrectly constructed test - conflicts with fix for bug #471305")]
  335. public void Validation_ValidationGroupIncluded () {
  336. WebTest t = new WebTest ();
  337. PageDelegates pd = new PageDelegates ();
  338. pd.Load = Validation_Load;
  339. pd.PreRender = Validation_PreRender;
  340. t.Invoker = new PageInvoker (pd);
  341. t.UserData = "ValidationGroupIncluded";
  342. string html = t.Run ();
  343. FormRequest fr = new FormRequest (t.Response, "form1");
  344. fr.Controls.Add ("__EVENTTARGET");
  345. fr.Controls.Add ("__EVENTARGUMENT");
  346. fr.Controls ["__EVENTTARGET"].Value = (string) t.UserData;
  347. fr.Controls ["__EVENTARGUMENT"].Value = "";
  348. t.Request = fr;
  349. t.UserData = "ValidationGroupIncluded";
  350. html = t.Run ();
  351. }
  352. [Test]
  353. [Category ("NunitWeb")]
  354. public void Validation_ValidationGroupNotIncluded () {
  355. WebTest t = new WebTest ();
  356. PageDelegates pd = new PageDelegates ();
  357. pd.Load = Validation_Load;
  358. pd.PreRender = Validation_PreRender;
  359. t.Invoker = new PageInvoker (pd);
  360. t.UserData = "ValidationGroupNotIncluded";
  361. string html = t.Run ();
  362. FormRequest fr = new FormRequest (t.Response, "form1");
  363. fr.Controls.Add ("__EVENTTARGET");
  364. fr.Controls.Add ("__EVENTARGUMENT");
  365. fr.Controls ["__EVENTTARGET"].Value = (string) t.UserData;
  366. fr.Controls ["__EVENTARGUMENT"].Value = "";
  367. t.Request = fr;
  368. t.UserData = "ValidationGroupNotIncluded";
  369. html = t.Run ();
  370. }
  371. public static void Validation_Load (Page p)
  372. {
  373. string testType = (string)WebTest.CurrentTest.UserData;
  374. DataGridTest dg = new DataGridTest ();
  375. dg.ID = "mygrid";
  376. EditCommandColumn e;
  377. e = new EditCommandColumn ();
  378. e.ButtonType = ButtonColumnType.LinkButton;
  379. e.CancelText = "Cancel";
  380. e.EditText = "Edit";
  381. e.UpdateText = "Update";
  382. switch (testType) {
  383. case "ValidatingValid":
  384. case "ValidatingInvalid":
  385. case "ValidationGroupIncluded":
  386. case "ValidationGroupNotIncluded":
  387. e.CausesValidation = true;
  388. break;
  389. case "NotValidatingInvalid":
  390. e.CausesValidation = false;
  391. break;
  392. }
  393. switch (testType) {
  394. case "ValidationGroupIncluded":
  395. case "ValidationGroupNotIncluded":
  396. e.ValidationGroup = "Group1";
  397. break;
  398. default:
  399. e.ValidationGroup = "";
  400. break;
  401. }
  402. dg.Columns.Add (e);
  403. TextBox tb = new TextBox ();
  404. tb.ID = "Text1";
  405. switch (testType) {
  406. case "ValidatingValid":
  407. tb.Text = "111";
  408. break;
  409. case "ValidatingInvalid":
  410. case "NotValidatingInvalid":
  411. case "ValidationGroupIncluded":
  412. case "ValidationGroupNotIncluded":
  413. tb.Text = "";
  414. break;
  415. }
  416. RequiredFieldValidator v = new RequiredFieldValidator ();
  417. v.ControlToValidate = "Text1";
  418. switch (testType) {
  419. case "ValidationGroupIncluded":
  420. v.ValidationGroup = "Group1";
  421. break;
  422. case "ValidationGroupNotIncluded":
  423. v.ValidationGroup = "NotGroup1";
  424. break;
  425. default:
  426. v.ValidationGroup = "";
  427. break;
  428. }
  429. TemplateColumn tc = new TemplateColumn ();
  430. tc.EditItemTemplate = new ValidatingEditTemplate (tb, v);
  431. dg.Columns.Add (tc);
  432. ObjectDataSource ods = new ObjectDataSource ("MyObjectDS", "Select");
  433. ods.UpdateMethod = "Update";
  434. ods.DataObjectTypeName = "MyObjectDS";
  435. ods.ID = "MyDS";
  436. p.Form.Controls.Add (ods);
  437. dg.DataSource = ods;
  438. //dg.DataKeyField = "i";
  439. //DataTable table = new DataTable ();
  440. //table.Columns.Add (new DataColumn ("one", typeof (string)));
  441. //table.Columns.Add (new DataColumn ("two", typeof (string)));
  442. //table.Columns.Add (new DataColumn ("three", typeof (string)));
  443. //table.Rows.Add (new object [] { "1", "2", "3" });
  444. //dg.DataSource = new DataView (table);
  445. dg.EditItemIndex = 0;
  446. p.Form.Controls.Add (dg);
  447. dg.DataBind ();
  448. if (!p.IsPostBack) {
  449. WebTest.CurrentTest.UserData = dg.Items [0].Cells [0].Controls [0].UniqueID;
  450. }
  451. }
  452. public static void Validation_PreRender (Page p)
  453. {
  454. string testType = (string) WebTest.CurrentTest.UserData;
  455. if (p.IsPostBack) {
  456. switch (testType) {
  457. case "ValidatingValid":
  458. case "ValidationGroupNotIncluded":
  459. Assert.AreEqual (true, p.IsValid, "ValidatingValid");
  460. break;
  461. case "ValidatingInvalid":
  462. case "ValidationGroupIncluded":
  463. Assert.AreEqual (false, p.IsValid, "ValidatingInvalid");
  464. break;
  465. case "NotValidatingInvalid":
  466. bool isValidated = true;
  467. try {
  468. if (p.IsValid) {
  469. Assert.Fail ("NotValidatingInvalid IsValid == true");
  470. }
  471. }
  472. catch (HttpException httpException) {
  473. isValidated = false;
  474. }
  475. Assert.AreEqual(false, isValidated, "NotValidatingInvalid");
  476. break;
  477. }
  478. }
  479. }
  480. public class ValidatingEditTemplate : ITemplate
  481. {
  482. public ValidatingEditTemplate (params Control [] templateControls)
  483. {
  484. this.templateControls = new Control[templateControls.Length];
  485. templateControls.CopyTo (this.templateControls, 0);
  486. }
  487. #region ITemplate Members
  488. public void InstantiateIn (Control container)
  489. {
  490. foreach (Control c in templateControls) {
  491. container.Controls.Add (c);
  492. }
  493. }
  494. #endregion
  495. private Control[] templateControls;
  496. }
  497. }
  498. }
  499. #region MyObjectDS
  500. public class MyObjectDS
  501. {
  502. public MyObjectDS () {
  503. _i = 0;
  504. }
  505. public MyObjectDS (int value) {
  506. _i = value;
  507. }
  508. private int _i;
  509. public int i {
  510. get { return _i; }
  511. set { _i = value; }
  512. }
  513. static MyObjectDS [] myData = null;
  514. public static IList Select () {
  515. if (myData == null) {
  516. myData = new MyObjectDS [] { new MyObjectDS (1), new MyObjectDS (2), new MyObjectDS (3) };
  517. }
  518. return myData;
  519. }
  520. public static void Update (MyObjectDS instance) {
  521. }
  522. }
  523. #endregion