PageRenderTime 62ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs

https://bitbucket.org/danipen/mono
C# | 3282 lines | 2718 code | 438 blank | 126 comment | 79 complexity | fee1de75173ca8fa5c8664b3e19ee155 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. //
  2. // Tests for System.Web.UI.WebControls.GridView.cs
  3. //
  4. // Author:
  5. // Tal Klahr (talk@mainsoft.com)
  6. // Yoni Klain (yonik@mainsoft.com)
  7. //
  8. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.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. // NOT TESTED :
  29. // ondatasourceviewchanged(),onpagepreload(),RaiseCallbackEvent(),RaisePostbackEvent
  30. #if NET_2_0
  31. using NUnit.Framework;
  32. using System;
  33. using System.IO;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. using System.Collections;
  39. using MonoTests.SystemWeb.Framework;
  40. using MonoTests.stand_alone.WebHarness;
  41. using MyWebControl = System.Web.UI.WebControls;
  42. using System.Data;
  43. using System.Drawing;
  44. using System.Threading;
  45. using System.Collections.Generic;
  46. namespace MonoTests.System.Web.UI.WebControls
  47. {
  48. class PokerGridView : GridView
  49. {
  50. public bool ifPagerInitilized;
  51. public bool dataPropertyChanged;
  52. public bool pagePreLoad;
  53. public bool controlHierarchy;
  54. public PokerGridView ()
  55. {
  56. TrackViewState ();
  57. }
  58. public object SaveState ()
  59. {
  60. return SaveViewState ();
  61. }
  62. public void LoadState (object o)
  63. {
  64. LoadViewState (o);
  65. }
  66. public StateBag StateBag
  67. {
  68. get { return base.ViewState; }
  69. }
  70. public HtmlTextWriterTag PTagKey
  71. {
  72. get { return base.TagKey;}
  73. }
  74. public string Render ()
  75. {
  76. StringWriter sw = new StringWriter ();
  77. HtmlTextWriter tw = new HtmlTextWriter (sw);
  78. Render (tw);
  79. return sw.ToString ();
  80. }
  81. public AutoGeneratedField DoCreateAutoGeneratedColumn (AutoGeneratedFieldProperties fieldProperties)
  82. {
  83. return base.CreateAutoGeneratedColumn (fieldProperties);
  84. }
  85. public int DoCreateChildControls (IEnumerable dataSource, bool dataBinding)
  86. {
  87. return base.CreateChildControls (dataSource, dataBinding);
  88. }
  89. public Table DoCreateChildTable ()
  90. {
  91. return base.CreateChildTable ();
  92. }
  93. public ICollection DoCreateColumns (PagedDataSource dataSource, bool useDataSource)
  94. {
  95. return base.CreateColumns (dataSource, useDataSource);
  96. }
  97. public Style DoCreateControlStyle ()
  98. {
  99. return base.CreateControlStyle ();
  100. }
  101. public DataSourceSelectArguments DoCreateDataSourceSelectArguments ()
  102. {
  103. return CreateDataSourceSelectArguments();
  104. }
  105. public DataSourceView DoGetData ()
  106. {
  107. return GetData ();
  108. }
  109. public GridViewRow doCreateRow (int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState)
  110. {
  111. return base.CreateRow (rowIndex, dataSourceIndex, rowType, rowState);
  112. }
  113. public string doGetCallbackResult ()
  114. {
  115. return base.GetCallbackResult ();
  116. }
  117. public string doGetCallbackScript (IButtonControl buttonControl, string argument)
  118. {
  119. return base.GetCallbackScript (buttonControl, argument);
  120. }
  121. protected override void InitializePager (GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
  122. {
  123. base.InitializePager (row, columnSpan, pagedDataSource);
  124. ifPagerInitilized = true;
  125. }
  126. protected override void InitializeRow (GridViewRow row, DataControlField[] fields)
  127. {
  128. base.InitializeRow (row, fields);
  129. }
  130. public bool DoOnBubbleEvent (object source, EventArgs e)
  131. {
  132. return base.OnBubbleEvent (source, e);
  133. }
  134. public void DoOnDataBinding (EventArgs e)
  135. {
  136. base.OnDataBinding (e);
  137. }
  138. public void DoOnDataBound (EventArgs e)
  139. {
  140. base.OnDataBound (e);
  141. }
  142. protected override void OnDataPropertyChanged ()
  143. {
  144. base.OnDataPropertyChanged ();
  145. dataPropertyChanged = true;
  146. }
  147. public void DoOnDataSourceViewChanged (object sender, EventArgs e)
  148. {
  149. base.OnDataSourceViewChanged (sender, e);
  150. }
  151. public void DoOnInit (EventArgs e)
  152. {
  153. base.OnInit (e);
  154. }
  155. public void DoOnLoad (EventArgs e)
  156. {
  157. base.OnLoad (e);
  158. }
  159. public void DoOnPageIndexChanged (EventArgs e)
  160. {
  161. base.OnPageIndexChanged (e);
  162. }
  163. public void DoOnPageIndexChanging (GridViewPageEventArgs e)
  164. {
  165. base.OnPageIndexChanging (e);
  166. }
  167. protected override void OnPagePreLoad (object sender, EventArgs e)
  168. {
  169. base.OnPagePreLoad (sender, e);
  170. pagePreLoad = true;
  171. }
  172. public void DoOnPreRender (EventArgs e)
  173. {
  174. base.OnPreRender (e);
  175. }
  176. public void DoOnRowCancelingEdit (GridViewCancelEditEventArgs e)
  177. {
  178. base.OnRowCancelingEdit (e);
  179. }
  180. public void DoOnRowCommand (GridViewCommandEventArgs e)
  181. {
  182. base.OnRowCommand (e);
  183. }
  184. public void DoOnRowCreated (GridViewRowEventArgs e)
  185. {
  186. base.OnRowCreated (e);
  187. }
  188. public void DoOnRowDataBound (GridViewRowEventArgs e)
  189. {
  190. base.OnRowDataBound (e);
  191. }
  192. public void DoOnRowDeleted (GridViewDeletedEventArgs e)
  193. {
  194. base.OnRowDeleted (e);
  195. }
  196. public void DoOnRowDeleting (GridViewDeleteEventArgs e)
  197. {
  198. base.OnRowDeleting (e);
  199. }
  200. public void DoOnRowEditing (GridViewEditEventArgs e)
  201. {
  202. base.OnRowEditing (e);
  203. }
  204. public void DoOnRowUpdated (GridViewUpdatedEventArgs e)
  205. {
  206. base.OnRowUpdated (e);
  207. }
  208. public void DoOnRowUpdating (GridViewUpdateEventArgs e)
  209. {
  210. base.OnRowUpdating (e);
  211. }
  212. public void DoOnSelectedIndexChanged (EventArgs e)
  213. {
  214. base.OnSelectedIndexChanged (e);
  215. }
  216. public void DoOnSelectedIndexChanging (GridViewSelectEventArgs e)
  217. {
  218. base.OnSelectedIndexChanging (e);
  219. }
  220. public void DoOnSorted (EventArgs e)
  221. {
  222. base.OnSorted (e);
  223. }
  224. public void DoOnSorting (GridViewSortEventArgs e)
  225. {
  226. base.OnSorting (e);
  227. }
  228. public void DoOnUnload (EventArgs e)
  229. {
  230. base.OnUnload (e);
  231. }
  232. public void DoPerformDataBinding (IEnumerable data)
  233. {
  234. base.PerformDataBinding (data);
  235. }
  236. protected internal override void PrepareControlHierarchy ()
  237. {
  238. base.PrepareControlHierarchy ();
  239. controlHierarchy = true;
  240. }
  241. public object DoSaveControlState ()
  242. {
  243. return base.SaveControlState ();
  244. }
  245. public void DoLoadControlState (object savedState)
  246. {
  247. base.LoadControlState (savedState);
  248. }
  249. public void SetRequiresDataBinding (bool value)
  250. {
  251. RequiresDataBinding = value;
  252. }
  253. public bool GetRequiresDataBinding ()
  254. {
  255. return RequiresDataBinding;
  256. }
  257. }
  258. [Serializable]
  259. [TestFixture]
  260. public class GridViewTest
  261. {
  262. class DS : ObjectDataSource, IDataSource
  263. {
  264. public static List<string> GetList ()
  265. {
  266. List<string> list = new List<string> ();
  267. list.Add ("Norway");
  268. list.Add ("Sweden");
  269. list.Add ("France");
  270. list.Add ("Italy");
  271. list.Add ("Israel");
  272. list.Add ("Russia");
  273. return list;
  274. }
  275. public void DoRaiseDataSourceChangedEvent (EventArgs e)
  276. {
  277. RaiseDataSourceChangedEvent (e);
  278. }
  279. }
  280. public class DataSourceObject
  281. {
  282. public static List<string> GetList (string sortExpression, int startRowIndex, int maximumRows)
  283. {
  284. return GetList ();
  285. }
  286. public static List<string> GetList (int startRowIndex, int maximumRows)
  287. {
  288. return GetList ();
  289. }
  290. public static List<string> GetList (string sortExpression)
  291. {
  292. return GetList ();
  293. }
  294. public static List<string> GetList ()
  295. {
  296. List<string> list = new List<string> ();
  297. list.Add ("Norway");
  298. list.Add ("Sweden");
  299. list.Add ("France");
  300. list.Add ("Italy");
  301. list.Add ("Israel");
  302. list.Add ("Russia");
  303. return list;
  304. }
  305. public static int GetCount ()
  306. {
  307. return GetList ().Count;
  308. }
  309. }
  310. public class data
  311. {
  312. private static ArrayList _data = new ArrayList ();
  313. static data ()
  314. {
  315. _data.Add (new DataItem (1, "heh1"));
  316. _data.Add (new DataItem (2, "heh2"));
  317. }
  318. public data ()
  319. {
  320. }
  321. public ArrayList GetAllItems ()
  322. {
  323. return _data;
  324. }
  325. public void UpdateItem (int id, string name)
  326. {
  327. foreach (DataItem i in _data) {
  328. if (i.ID == id) {
  329. i.Name = name;
  330. return;
  331. }
  332. }
  333. }
  334. }
  335. public class DataItem
  336. {
  337. int _id = 0;
  338. string _name = "";
  339. public DataItem (int id, string name)
  340. {
  341. _id = id;
  342. _name = name;
  343. }
  344. public int ID {
  345. get { return _id; }
  346. }
  347. public string Name {
  348. get { return _name; }
  349. set { _name = value; }
  350. }
  351. }
  352. public const string BOOLFIELD = "bool";
  353. public const string STRINGFIELD = "str";
  354. ArrayList myds = new ArrayList ();
  355. public bool InitilizePager;
  356. [TestFixtureSetUp]
  357. public void GridViewInit ()
  358. {
  359. myds.Add ("Norway");
  360. myds.Add ("Sweden");
  361. myds.Add ("France");
  362. myds.Add ("Italy");
  363. myds.Add ("Israel");
  364. myds.Add ("Russia");
  365. WebTest.CopyResource (GetType (), "GridViewUpdate.aspx", "GridViewUpdate.aspx");
  366. WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
  367. WebTest.CopyResource (GetType (), "TableSections_Bug551666.aspx", "TableSections_Bug551666.aspx");
  368. WebTest.CopyResource (GetType (), "TableSections_Bug551666.aspx.cs", "TableSections_Bug551666.aspx.cs");
  369. WebTest.CopyResource (GetType (), "GridView_Bug595567.aspx", "GridView_Bug595567.aspx");
  370. }
  371. [Test (Description="Bug 595567")]
  372. public void HeaderFooterVisibility_Bug595567 ()
  373. {
  374. WebTest t = new WebTest ("GridView_Bug595567.aspx");
  375. string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">Item</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td>0</td>\r\n\t\t</tr><tr>\r\n\t\t\t<td>0</td>\r\n\t\t</tr><tr>\r\n\t\t\t<td>0</td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
  376. string pageHtml = t.Run ();
  377. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  378. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  379. }
  380. [Test]
  381. public void GridView_DefaultProperties ()
  382. {
  383. PokerGridView g = new PokerGridView ();
  384. Assert.AreEqual (0, g.StateBag.Count, "ViewState.Count");
  385. Assert.AreEqual (false, g.AllowPaging, "AllowPaging");
  386. Assert.AreEqual (false, g.AllowSorting, "AllowSorting");
  387. // The AlternatingRowStyle property is tested by the TableItemStyle test (already exists)
  388. Assert.AreEqual (true, g.AutoGenerateColumns, "AutoGenerateColumns");
  389. Assert.AreEqual (false, g.AutoGenerateDeleteButton, "AutoGenerateDeleteButton");
  390. Assert.AreEqual (false, g.AutoGenerateEditButton, "AutoGenerateEditButton");
  391. Assert.AreEqual (false, g.AutoGenerateSelectButton, "AutoGenerateSelectButton");
  392. Assert.AreEqual ("", g.BackImageUrl, "BackImageUrl");
  393. Assert.AreEqual (null, g.BottomPagerRow, "BottomPagerRow");
  394. Assert.AreEqual ("", g.Caption, "Caption");
  395. Assert.AreEqual (TableCaptionAlign.NotSet, g.CaptionAlign, "CaptionAlign");
  396. Assert.AreEqual (-1, g.CellPadding, "CellPadding");
  397. Assert.AreEqual (0, g.CellSpacing, "CellSpacing");
  398. // ToDo: The Columns property default value is tested by the DataControlFieldCollection and DataControlField tests
  399. Assert.AreEqual (0, g.DataKeyNames.Length, "DataKeyNames");
  400. // ToDo: The DataKeys property default value is tested by the DataKeyArray and DataKey tests
  401. Assert.AreEqual (-1, g.EditIndex, "EditIndex");
  402. // The EditRowStyle property is tested by the TableItemStyle test (already exists)
  403. // The EmptyDataRowStyle property is tested by the TableItemStyle test (already exists)
  404. Assert.AreEqual (null, g.EmptyDataTemplate, "EmptyDataTemplate");
  405. Assert.AreEqual ("", g.EmptyDataText, "EmptyDataText");
  406. Assert.AreEqual (false, g.EnableSortingAndPagingCallbacks, "EnableSortingAndPagingCallbacks");
  407. // The FooterStyle property is tested by the TableItemStyle test (already exists)
  408. Assert.AreEqual (GridLines.Both, g.GridLines, "GridLines");
  409. // The HeaderStyle property is tested by the TableItemStyle test (already exists)
  410. Assert.AreEqual (HorizontalAlign.NotSet, g.HorizontalAlign, "HorizontalAlign");
  411. Assert.AreEqual (0, g.PageIndex, "PageIndex");
  412. // ToDo: The PagerSettings property is tested by the PagerSettings test
  413. // The PagerStyle property is tested by the TableItemStyle test (already exists)
  414. Assert.AreEqual (null, g.PagerTemplate, "PagerTemplate");
  415. Assert.AreEqual (10, g.PageSize, "PageSize");
  416. Assert.AreEqual ("", g.RowHeaderColumn, "RowHeaderColumn");
  417. // ToDo: The Rows property is tested by the GridViewRowCollection and GridViewRow test
  418. // The RowStyle property is tested by the TableItemStyle test (already exists)
  419. Assert.AreEqual (false, g.ShowFooter, "ShowFooter");
  420. Assert.AreEqual (true, g.ShowHeader, "ShowHeader");
  421. Assert.AreEqual (SortDirection.Ascending, g.SortDirection, "SortDirection");
  422. Assert.AreEqual (null, g.TopPagerRow, "TopPagerRow");
  423. Assert.AreEqual (true, g.UseAccessibleHeader, "UseAccessibleHeader");
  424. }
  425. [Test]
  426. public void GridView_DefaultPropertiesNotWorking ()
  427. {
  428. PokerGridView g = new PokerGridView ();
  429. Assert.AreEqual (null, g.FooterRow, "FooterRow");
  430. Assert.AreEqual (null, g.HeaderRow, "HeaderRow");
  431. Assert.AreEqual (true, g.Visible, "ViewVisible");
  432. Assert.AreEqual (0, g.PageCount, "PageCount");
  433. Assert.AreEqual ("", g.SortExpression, "SortExpression");
  434. }
  435. [Test]
  436. public void GridView_AssignedProperties ()
  437. {
  438. PokerGridView g = new PokerGridView ();
  439. Assert.AreEqual (0, g.StateBag.Count, "ViewState.Count");
  440. g.AllowPaging = true;
  441. Assert.AreEqual (true, g.AllowPaging, "AllowPaging");
  442. g.AllowSorting = true;
  443. Assert.AreEqual (true, g.AllowSorting, "AllowSorting");
  444. g.AutoGenerateColumns = false;
  445. Assert.AreEqual (false, g.AutoGenerateColumns, "AutoGenerateColumns");
  446. g.AutoGenerateDeleteButton = true;
  447. Assert.AreEqual (true, g.AutoGenerateDeleteButton, "AutoGenerateDeleteButton");
  448. g.AutoGenerateEditButton = true;
  449. Assert.AreEqual (true, g.AutoGenerateEditButton, "AutoGenerateEditButton");
  450. g.AutoGenerateSelectButton = true;
  451. Assert.AreEqual (true, g.AutoGenerateSelectButton, "AutoGenerateSelectButton");
  452. g.BackImageUrl = "test";
  453. Assert.AreEqual ("test", g.BackImageUrl, "BackImageUrl");
  454. g.Caption = "test";
  455. Assert.AreEqual ("test", g.Caption, "Caption");
  456. g.CaptionAlign = TableCaptionAlign.Left;
  457. Assert.AreEqual (TableCaptionAlign.Left, g.CaptionAlign, "CaptionAlign");
  458. g.CellPadding = 0;
  459. Assert.AreEqual (0, g.CellPadding, "CellPadding");
  460. g.CellSpacing = 1;
  461. Assert.AreEqual (1, g.CellSpacing, "CellSpacing");
  462. // ToDo: The Columns property default value is tested by the DataControlFieldCollection and DataControlField tests
  463. string[] str = new String[1];
  464. str[0] = "test";
  465. g.DataKeyNames = str;
  466. Assert.AreEqual ("test", g.DataKeyNames[0], "DataKeyNames");
  467. // ToDo: The DataKeys property default value is tested by the DataKeyArray and DataKey tests
  468. g.EditIndex = 0;
  469. Assert.AreEqual (0, g.EditIndex, "EditIndex");
  470. // The EditRowStyle property default value is tested by the TableItemStyle test (already exists)
  471. // The EmptyDataRowStyle property default value is tested by the TableItemStyle test (already exists)
  472. MyWebControl.Image myImage = new MyWebControl.Image ();
  473. myImage.ImageUrl = "myimage.jpg";
  474. ImageTemplate template = new ImageTemplate ();
  475. template.MyImage = myImage;
  476. // end create template image
  477. g.EmptyDataTemplate = template;
  478. Assert.IsNotNull (g.EmptyDataTemplate, "EmptyDataTemplate");
  479. g.EmptyDataText = "test";
  480. Assert.AreEqual ("test", g.EmptyDataText, "EmptyDataText");
  481. g.EnableSortingAndPagingCallbacks = true;
  482. Assert.AreEqual (true, g.EnableSortingAndPagingCallbacks, "EnableSortingAndPagingCallbacks");
  483. // The FooterStyle property default value is tested by the TableItemStyle test (already exists)
  484. g.GridLines = GridLines.Horizontal;
  485. Assert.AreEqual (GridLines.Horizontal, g.GridLines, "GridLines");
  486. g.HorizontalAlign = HorizontalAlign.Justify;
  487. Assert.AreEqual (HorizontalAlign.Justify, g.HorizontalAlign, "HorizontalAlign");
  488. g.PageIndex = 1;
  489. Assert.AreEqual (1, g.PageIndex, "PageIndex");
  490. // ToDo: The PagerSettings property default value is tested by the PagerSettings test
  491. // The PagerStyle property default value is tested by the TableItemStyle test (already exists)
  492. g.PagerTemplate = template;
  493. Assert.IsNotNull (g.PagerTemplate, "PagerTemplate");
  494. g.PageSize = 5;
  495. Assert.AreEqual (5, g.PageSize, "PageSize");
  496. g.RowHeaderColumn = "test";
  497. Assert.AreEqual ("test", g.RowHeaderColumn, "RowHeaderColumn");
  498. // ToDo: The Rows property default value is tested by the GridViewRowCollection and GridViewRow test
  499. // The RowStyle property default value is tested by the TableItemStyle test (already exists)
  500. g.ShowFooter = true;
  501. Assert.AreEqual (true, g.ShowFooter, "ShowFooter");
  502. g.ShowHeader = false;
  503. Assert.AreEqual (false, g.ShowHeader, "ShowHeader");
  504. g.UseAccessibleHeader = false;
  505. Assert.AreEqual (false, g.UseAccessibleHeader, "UseAccessibleHeader");
  506. }
  507. #if NET_4_0
  508. [Test]
  509. public void SortedAscendingCellStyle ()
  510. {
  511. var g = new PokerGridView ();
  512. Assert.IsNotNull (g.SortedAscendingCellStyle, "#A1-1");
  513. }
  514. [Test]
  515. public void SortedAscendingHeaderStyle ()
  516. {
  517. var g = new PokerGridView ();
  518. Assert.IsNotNull (g.SortedAscendingHeaderStyle, "#A1-1");
  519. }
  520. [Test]
  521. public void SortedDescendingCellStyle ()
  522. {
  523. var g = new PokerGridView ();
  524. Assert.IsNotNull (g.SortedDescendingCellStyle, "#A1-1");
  525. }
  526. [Test]
  527. public void SortedDescendingHeaderStyle ()
  528. {
  529. var g = new PokerGridView ();
  530. Assert.IsNotNull (g.SortedDescendingHeaderStyle, "#A1-1");
  531. }
  532. #endif
  533. [Test]
  534. public void GridView_DefaultProtectedProperties ()
  535. {
  536. PokerGridView g = new PokerGridView ();
  537. Assert.AreEqual (HtmlTextWriterTag.Table, g.PTagKey, "TagKey");
  538. }
  539. [Test]
  540. public void GridView_Sort_and_DataSourceSelectArguments ()
  541. {
  542. DataSourceView view;
  543. DataSourceSelectArguments arg;
  544. Page p = new Page ();
  545. PokerGridView g = new PokerGridView ();
  546. g.Columns.Add (new BoundField ());
  547. g.AllowSorting = true;
  548. p.Controls.Add (g);
  549. ObjectDataSource data = new ObjectDataSource ();
  550. data.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
  551. data.SelectMethod = "GetList";
  552. data.SortParameterName = "sortExpression";
  553. data.ID = "Data";
  554. p.Controls.Add (data);
  555. g.DataSourceID = "Data";
  556. g.EditIndex = 2;
  557. g.PageIndex = 1;
  558. g.DataBind ();
  559. g.Sort ("sort", SortDirection.Descending);
  560. Assert.AreEqual (-1, g.EditIndex, "EditIndex after Sort, Bound by DataSourceID");
  561. Assert.AreEqual (0, g.PageIndex, "PageIndex after Sort, Bound by DataSourceID");
  562. arg = g.DoCreateDataSourceSelectArguments();
  563. view = g.DoGetData ();
  564. Assert.IsTrue (view.CanSort);
  565. Assert.AreEqual ("sort", g.SortExpression, "SortExpression, Bound by DataSourceID");
  566. Assert.AreEqual (SortDirection.Descending, g.SortDirection, "SortDirection, Bound by DataSourceID");
  567. Assert.AreEqual ("sort DESC", arg.SortExpression, "AllowSorting = true, Bound by DataSourceID");
  568. g.AllowSorting = false;
  569. arg = g.DoCreateDataSourceSelectArguments ();
  570. Assert.AreEqual ("sort DESC", arg.SortExpression, "AllowSorting = false, Bound by DataSourceID");
  571. }
  572. [Test]
  573. public void GridView_PageCount ()
  574. {
  575. Page p = new Page ();
  576. PokerGridView gv = new PokerGridView ();
  577. gv.PageSize = 3;
  578. gv.AllowPaging = true;
  579. p.Controls.Add (gv);
  580. ObjectDataSource data = new ObjectDataSource ();
  581. data.ID = "ObjectDataSource1";
  582. data.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
  583. data.SelectMethod = "GetList";
  584. p.Controls.Add (data);
  585. gv.DataSourceID = "ObjectDataSource1";
  586. gv.SetRequiresDataBinding (true);
  587. Assert.AreEqual (0, gv.PageCount, "PageCount before binding");
  588. gv.DataBind ();
  589. Assert.AreEqual (2, gv.PageCount, "PageCount after binding");
  590. PokerGridView copy = new PokerGridView ();
  591. copy.DoLoadControlState (gv.DoSaveControlState ());
  592. Assert.AreEqual (2, copy.PageCount, "PageCount from ViewState");
  593. }
  594. [Test]
  595. public void GridView_DataKeys ()
  596. {
  597. Page p = new Page ();
  598. PokerGridView gv = new PokerGridView ();
  599. p.Controls.Add (gv);
  600. ObjectDataSource data = new ObjectDataSource ();
  601. data.TypeName = typeof (DataObject).AssemblyQualifiedName;
  602. data.SelectMethod = "Select";
  603. p.Controls.Add (data);
  604. gv.DataSource = data;
  605. gv.DataKeyNames = new string [] { "ID", "FName" };
  606. DataKeyArray keys1 = gv.DataKeys;
  607. Assert.AreEqual (0, keys1.Count, "DataKeys count before binding");
  608. gv.DataBind ();
  609. DataKeyArray keys2 = gv.DataKeys;
  610. DataKeyArray keys3 = gv.DataKeys;
  611. Assert.IsFalse (Object.ReferenceEquals (keys1, keys2), "DataKey returns the same instans");
  612. Assert.IsTrue (Object.ReferenceEquals (keys2, keys3), "DataKey returns the same instans");
  613. Assert.AreEqual (1, keys1.Count, "DataKeys count after binding");
  614. Assert.AreEqual (1001, keys1 [0].Value, "DataKey.Value after binding");
  615. Assert.AreEqual (2, keys1 [0].Values.Count, "DataKey.Values count after binding");
  616. Assert.AreEqual (1001, keys1 [0].Values [0], "DataKey.Values[0] after binding");
  617. Assert.AreEqual ("Mahesh", keys1 [0].Values [1], "DataKey.Values[1] after binding");
  618. PokerGridView copy = new PokerGridView ();
  619. object state = gv.DoSaveControlState ();
  620. copy.DoLoadControlState (state);
  621. DataKeyArray keys4 = copy.DataKeys;
  622. Assert.AreEqual (1, keys4.Count, "DataKeys count from ControlState");
  623. Assert.AreEqual (1001, keys4 [0].Value, "DataKey.Value from ControlState");
  624. Assert.AreEqual (2, keys4 [0].Values.Count, "DataKey.Values count from ControlState");
  625. Assert.AreEqual (1001, keys4 [0].Values [0], "DataKey.Values[0] from ControlState");
  626. Assert.AreEqual ("Mahesh", keys4 [0].Values [1], "DataKey.Values[1] from ControlState");
  627. }
  628. // MSDN: The CreateDataSourceSelectArguments method is a helper method called by
  629. // the GridView control to create the DataSourceSelectArguments object that
  630. // contains the arguments passed to the data source. In this implementation,
  631. // the DataSourceSelectArguments object contains the arguments for paging operations.
  632. [Test]
  633. public void GridView_CreateDataSourceSelectArguments ()
  634. {
  635. DataSourceView view;
  636. Page p = new Page ();
  637. PokerGridView g = new PokerGridView ();
  638. g.Sorting += new GridViewSortEventHandler (g_Sorting);
  639. p.Controls.Add (g);
  640. ObjectDataSource data = new ObjectDataSource ();
  641. data.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
  642. data.SelectMethod = "GetList";
  643. data.SortParameterName = "sortExpression";
  644. DataSourceSelectArguments arg;
  645. p.Controls.Add (data);
  646. g.DataSource = data;
  647. g.DataBind ();
  648. arg = g.DoCreateDataSourceSelectArguments ();
  649. Assert.IsTrue (arg.Equals (DataSourceSelectArguments.Empty), "Default");
  650. g.AllowPaging = true;
  651. g.PageIndex = 2;
  652. g.PageSize = 3;
  653. arg = g.DoCreateDataSourceSelectArguments ();
  654. view = g.DoGetData ();
  655. Assert.IsFalse (view.CanPage);
  656. Assert.IsTrue (view.CanRetrieveTotalRowCount);
  657. Assert.IsTrue (arg.Equals (DataSourceSelectArguments.Empty), "AllowPaging = true, CanPage = false, CanRetrieveTotalRowCount = true");
  658. // make DataSourceView.CanPage = true
  659. data.EnablePaging = true;
  660. arg = g.DoCreateDataSourceSelectArguments ();
  661. view = g.DoGetData ();
  662. Assert.IsTrue (view.CanPage);
  663. Assert.IsFalse (view.CanRetrieveTotalRowCount);
  664. Assert.IsTrue (arg.Equals (new DataSourceSelectArguments (6, -1)), "AllowPaging = true, CanPage = true, CanRetrieveTotalRowCount = false");
  665. g.AllowPaging = false;
  666. arg = g.DoCreateDataSourceSelectArguments ();
  667. Assert.IsTrue (arg.Equals (DataSourceSelectArguments.Empty), "AllowPaging = false, CanPage = true, CanRetrieveTotalRowCount = false");
  668. // make DataSourceView.CanRetrieveTotalRowCount = true
  669. data.SelectCountMethod = "GetCount";
  670. arg = g.DoCreateDataSourceSelectArguments ();
  671. Assert.IsTrue (arg.Equals (DataSourceSelectArguments.Empty), "AllowPaging = false, CanPage = true, CanRetrieveTotalRowCount = true");
  672. g.AllowPaging = true;
  673. arg = g.DoCreateDataSourceSelectArguments ();
  674. DataSourceSelectArguments arg1 = new DataSourceSelectArguments (6, 3);
  675. arg1.RetrieveTotalRowCount = true;
  676. view = g.DoGetData ();
  677. Assert.IsTrue (view.CanPage);
  678. Assert.IsTrue (view.CanRetrieveTotalRowCount);
  679. Assert.IsTrue (arg.Equals (arg1), "AllowPaging = true, CanPage = true, CanRetrieveTotalRowCount = true");
  680. g.AllowPaging = false;
  681. g.AllowSorting = true;
  682. g.EditIndex = 2;
  683. g.PageIndex = 1;
  684. g.Sort ("sort", SortDirection.Descending);
  685. Assert.AreEqual (2, g.EditIndex, "EditIndex after Sort, Bound by DataSource");
  686. Assert.AreEqual (1, g.PageIndex, "PageIndex after Sort, Bound by DataSource");
  687. arg = g.DoCreateDataSourceSelectArguments ();
  688. view = g.DoGetData ();
  689. Assert.IsTrue (view.CanSort);
  690. Assert.AreEqual (String.Empty, g.SortExpression, "SortExpression, Bound by DataSource");
  691. Assert.AreEqual (SortDirection.Ascending, g.SortDirection, "SortDirection, Bound by DataSource");
  692. Assert.IsTrue (arg.Equals (DataSourceSelectArguments.Empty), "AllowSorting = true, Bound by DataSource");
  693. }
  694. static void g_Sorting (object sender, GridViewSortEventArgs e)
  695. {
  696. Assert.AreEqual ("sort", e.SortExpression, "GridViewSortEventArgs.SortExpression");
  697. Assert.AreEqual (SortDirection.Descending, e.SortDirection, "GridViewSortEventArgs.SortDirection");
  698. }
  699. [Test]
  700. public void GridView_DataBind()
  701. {
  702. PokerGridView g = new PokerGridView ();
  703. g.DataSource = myds;
  704. g.DataBind ();
  705. Assert.AreEqual (6, g.Rows.Count, "DataBind");
  706. g.DataSource = null;
  707. g.DataBind ();
  708. Assert.AreEqual (0, g.Rows.Count, "DataBind");
  709. }
  710. [Test]
  711. public void GridView_DataBind_NoDataSource ()
  712. {
  713. PokerGridView g = new PokerGridView ();
  714. g.DataBind ();
  715. Assert.AreEqual (0, g.Rows.Count, "GridView_DataBind_NoDataSource");
  716. }
  717. bool rowcreatedchecker;
  718. bool deleteitemchecker;
  719. bool sortingaction;
  720. [Test]
  721. public void GridView_DeleteItem ()
  722. {
  723. PokerGridView g = new PokerGridView ();
  724. ArrayList myds = new ArrayList ();
  725. myds.Add ("Norway");
  726. myds.Add ("Sweden");
  727. myds.Add ("France");
  728. myds.Add ("Italy");
  729. g.DataSource = myds;
  730. g.DataBind ();
  731. Assert.AreEqual (false, deleteitemchecker, "DeleteItem#1");
  732. g.RowDeleting += new GridViewDeleteEventHandler (RowDeletingHandler);
  733. g.DeleteRow (0);
  734. Assert.AreEqual (true, deleteitemchecker, "DeleteItem#2");
  735. }
  736. protected void RowDeletingHandler (object sender, GridViewDeleteEventArgs e)
  737. {
  738. deleteitemchecker = true;
  739. }
  740. [Test]
  741. public void GridView_RowCreated ()
  742. {
  743. GridView g = new GridView ();
  744. ButtonField field = new ButtonField ();
  745. field.ButtonType = ButtonType.Link;
  746. field.Text = "Click";
  747. field.CommandName = "CMD";
  748. g.Columns.Add (field);
  749. g.RowCreated += new GridViewRowEventHandler (RowCreatedHandler);
  750. Assert.AreEqual (false, rowcreatedchecker, "RowCreated#1");
  751. ArrayList myds = new ArrayList ();
  752. myds.Add ("Norway");
  753. myds.Add ("Sweden");
  754. myds.Add ("France");
  755. myds.Add ("Italy");
  756. g.DataSource = myds;
  757. g.DataBind ();
  758. Assert.AreEqual (true, rowcreatedchecker, "RowCreated#2");
  759. }
  760. protected void RowCreatedHandler (object sender, GridViewRowEventArgs e)
  761. {
  762. if (e.Row.Cells.Count > 0)
  763. rowcreatedchecker = true;
  764. // Example from MSDN: GridView.RowCreated Event
  765. // The GridViewCommandEventArgs class does not contain a
  766. // property that indicates which row's command button was
  767. // clicked. To identify which row's button was clicked, use
  768. // the button's CommandArgument property by setting it to the
  769. // row's index.
  770. if (e.Row.RowType == DataControlRowType.DataRow) {
  771. // Retrieve the LinkButton control from the first column.
  772. IButtonControl addButton = (IButtonControl) e.Row.Cells [0].Controls [0];
  773. // Set the LinkButton's CommandArgument property with the
  774. // row's index.
  775. addButton.CommandArgument = e.Row.RowIndex.ToString ();
  776. }
  777. }
  778. [Test]
  779. public void GridView_Sort ()
  780. {
  781. PokerGridView g = new PokerGridView ();
  782. Assert.AreEqual (false, sortingaction, "BeforeSorting");
  783. g.Sorting += new GridViewSortEventHandler (Gridview_sorting);
  784. g.Sort("Item",SortDirection.Descending);
  785. Assert.AreEqual (true, sortingaction, "AfterSorting");
  786. }
  787. protected void Gridview_sorting (object sender, GridViewSortEventArgs e)
  788. {
  789. sortingaction = true;
  790. }
  791. [Test]
  792. public void GridView_IsBindableType ()
  793. {
  794. Type [] types = new Type [] {
  795. typeof(Boolean),
  796. typeof(Byte),
  797. typeof(Char),
  798. typeof(DateTime),
  799. typeof(Decimal),
  800. typeof(Double),
  801. typeof(Guid),
  802. typeof(Int16),
  803. typeof(Int32),
  804. typeof(Int64),
  805. typeof(SByte),
  806. typeof(Single),
  807. typeof(String),
  808. typeof(UInt16),
  809. typeof(UInt32),
  810. typeof(UInt64)
  811. };
  812. GridView g = new GridView ();
  813. foreach (Type type in types)
  814. Assert.AreEqual (true, g.IsBindableType (type), type.ToString ());
  815. Assert.AreEqual (false, g.IsBindableType (typeof (Enum)), "test");
  816. Assert.AreEqual (false, g.IsBindableType (typeof (Object)), "test");
  817. }
  818. [Test]
  819. public void GridView_CreateAutoGeneratedColumn ()
  820. {
  821. PokerGridView g = new PokerGridView ();
  822. AutoGeneratedFieldProperties fp = new AutoGeneratedFieldProperties();
  823. fp.Name = "testfield";
  824. fp.Type = typeof (string);
  825. AutoGeneratedField gf = g.DoCreateAutoGeneratedColumn (fp);
  826. Assert.AreEqual (typeof (string), gf.DataType , "AutoGeneratedColumn#1");
  827. Assert.AreEqual ("testfield", gf.HeaderText, "AutoGeneratedColumn#2");
  828. Assert.AreEqual ("System.Web.UI.WebControls.AutoGeneratedField", gf.GetType ().ToString (), "AutoGeneratedColumn#3");
  829. }
  830. [Test]
  831. public void GridView_CreateChildControls ()
  832. {
  833. PokerGridView g = new PokerGridView ();
  834. g.Page = new Page ();
  835. g.DataSource = myds;
  836. g.DataBind ();
  837. Assert.AreEqual(6,g.DoCreateChildControls(myds,true),"CreateChildControls#1");
  838. g.AllowPaging = true;
  839. g.PageSize = 3;
  840. g.DataBind ();
  841. Assert.AreEqual (6, g.DoCreateChildControls (myds, true), "CreateChildControls#1");
  842. }
  843. class MyEnumSource : IEnumerable
  844. {
  845. int _count;
  846. public MyEnumSource (int count)
  847. {
  848. _count = count;
  849. }
  850. #region IEnumerable Members
  851. public IEnumerator GetEnumerator ()
  852. {
  853. for (int i = 0; i < _count; i++)
  854. yield return i;
  855. }
  856. #endregion
  857. }
  858. [Test]
  859. public void GridView_CreateChildControls_2 ()
  860. {
  861. PokerGridView g = new PokerGridView ();
  862. g.AutoGenerateColumns = false;
  863. g.AutoGenerateSelectButton = true;
  864. g.EmptyDataText = "empty";
  865. g.Page = new Page ();
  866. g.DataSource = new MyEnumSource (20);
  867. //g.DataBind ();
  868. //Assert.AreEqual (20, g.DoCreateChildControls (new MyEnumSource (20), true), "CreateChildControls#1");
  869. Assert.AreEqual (0, g.DoCreateChildControls (new MyEnumSource (0), true), "CreateChildControls#2");
  870. }
  871. [Test]
  872. public void GridView_CreateChildControls_1 ()
  873. {
  874. PokerGridView g = new PokerGridView ();
  875. g.AutoGenerateSelectButton = true;
  876. g.EmptyDataText = "empty";
  877. Assert.AreEqual (0, g.DoCreateChildControls (new object [0], false), "CreateChildControls#2");
  878. Assert.AreEqual (-1, g.DoCreateChildControls (new object [5], false), "CreateChildControls#3");
  879. }
  880. [Test]
  881. public void GridView_NullDS ()
  882. {
  883. PokerGridView g = new PokerGridView ();
  884. g.DataSource = null;
  885. g.DataBind ();
  886. Assert.AreEqual (0, g.Rows.Count, "NullDS");
  887. }
  888. [Test]
  889. public void GridView_CreateChildTable ()
  890. {
  891. PokerGridView g = new PokerGridView ();
  892. g.ID = "PokerGridView";
  893. g.Caption = "Caption";
  894. g.CaptionAlign = TableCaptionAlign.Right;
  895. g.CellPadding = 2;
  896. g.CellSpacing = 2;
  897. Table t = g.DoCreateChildTable ();
  898. Assert.IsNotNull (t, "CreateChildTable#1");
  899. Assert.AreEqual (false, t.ControlStyleCreated, "CreateChildTable#2");
  900. }
  901. [Test]
  902. public void GridView_CreateControlStyle ()
  903. {
  904. PokerGridView g = new PokerGridView ();
  905. g.BorderColor = Color.Red;
  906. g.BorderStyle = BorderStyle.Dashed;
  907. Style s = g.DoCreateControlStyle ();
  908. Assert.AreEqual (typeof(TableStyle), s.GetType(), "CreateControlStyle#1");
  909. Assert.AreEqual (((TableStyle) s).GridLines, GridLines.Both, "CreateControlStyle#2");
  910. Assert.AreEqual (((TableStyle) s).CellSpacing, 0, "CreateControlStyle#3");
  911. }
  912. [Test]
  913. public void GridView_CreateRow ()
  914. {
  915. PokerGridView g = new PokerGridView ();
  916. GridViewRow gr = g.doCreateRow(0, 0, DataControlRowType.Pager, DataControlRowState.Normal);
  917. Assert.AreEqual (0, gr.RowIndex, "CreateRow#1");
  918. Assert.AreEqual (0, gr.DataItemIndex, "CreateRow#2");
  919. Assert.AreEqual (DataControlRowType.Pager, gr.RowType, "CreateRow#3");
  920. Assert.AreEqual (DataControlRowState.Normal, gr.RowState, "CreateRow#4");
  921. }
  922. [Test]
  923. public void GridView_GetCallbackResult()
  924. {
  925. Page page = new Page ();
  926. PokerGridView g = new PokerGridView ();
  927. page.Controls.Add (g);
  928. string s = g.doGetCallbackResult ();
  929. if (s == null || s == string.Empty)
  930. Assert.Fail ("GetCallbackResult");
  931. }
  932. [Test]
  933. public void GridView_InitializePager ()
  934. {
  935. PokerGridView gv = new PokerGridView ();
  936. Page page = new Page ();
  937. page.Controls.Add (gv);
  938. gv.AllowPaging = true;
  939. gv.PageSize = 2;
  940. gv.DataSource = myds;
  941. Assert.AreEqual (false, gv.ifPagerInitilized, "BeforeInitializePagerRunned");
  942. Assert.AreEqual (0, gv.PageCount, "BeforeInitializePagerPageCount");
  943. gv.DataBind ();
  944. Assert.AreEqual (true, gv.ifPagerInitilized, "AfterInitializePagerRunned");
  945. Assert.AreEqual (3, gv.PageCount, "AfterInitializePagerPageCount");
  946. }
  947. [Test]
  948. public void GridView_InitializeRow ()
  949. {
  950. // not implemented yet
  951. }
  952. [Test]
  953. public void GridView_ViewState ()
  954. {
  955. PokerGridView gv = new PokerGridView ();
  956. PokerGridView copy = new PokerGridView ();
  957. gv.AllowPaging = true;
  958. gv.AllowSorting = true;
  959. gv.BackColor = Color.Red;
  960. object state = gv.SaveState ();
  961. copy.LoadState (state);
  962. Assert.AreEqual (true, copy.AllowPaging, "ViewStateAllowPaging");
  963. Assert.AreEqual (true, copy.AllowSorting, "ViewStateAllowSorting");
  964. Assert.AreEqual (Color.Red, copy.BackColor, "ViewStateBackColor");
  965. }
  966. // Private variables for bubble events
  967. private bool bubbledeleterow;
  968. private bool bubbleupdaterow;
  969. private bool bubbleeditingrow;
  970. private bool bubblesortint;
  971. private bool bubblecanceling;
  972. private bool bubbleselect;
  973. private bool bubblepage;
  974. private int newPageIndex;
  975. [Test]
  976. public void GridView_BubbleEvent ()
  977. {
  978. PokerGridView gv = new PokerGridView ();
  979. Page page = new Page ();
  980. LinkButton lb = new LinkButton ();
  981. gv.AllowPaging = true;
  982. page.Controls.Add (gv);
  983. gv.DataSource = myds;
  984. gv.DataBind ();
  985. gv.EditIndex = 0;
  986. //
  987. gv.RowDeleting += new GridViewDeleteEventHandler (gv_RowDeleting);
  988. gv.RowUpdating += new GridViewUpdateEventHandler (gv_RowUpdating);
  989. gv.RowEditing += new GridViewEditEventHandler (gv_RowEditing);
  990. gv.Sorting += new GridViewSortEventHandler (gv_Sorting);
  991. gv.RowCancelingEdit += new GridViewCancelEditEventHandler (gv_RowCancelingEdit);
  992. gv.SelectedIndexChanging+=new GridViewSelectEventHandler(gv_SelectedIndexChanging);
  993. gv.PageIndexChanging+=new GridViewPageEventHandler(gv_PageIndexChanging);
  994. // Delete
  995. GridViewCommandEventArgs com1 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Delete", "0"));
  996. Assert.AreEqual (false, bubbledeleterow, "BeforeBubbleEventDeleteRow");
  997. gv.DoOnBubbleEvent (gv, com1);
  998. Assert.AreEqual (true, bubbledeleterow, "AfterBubbleEventDeleteRow");
  999. // Update
  1000. GridViewCommandEventArgs com2 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Update", "0"));
  1001. Assert.AreEqual (false, bubbleupdaterow, "BeforeBubbleEventUpdateRow");
  1002. gv.DoOnBubbleEvent (gv, com2);
  1003. Assert.AreEqual (true, bubbleupdaterow, "AfterBubbleEventUpdateRow");
  1004. // Edit
  1005. GridViewCommandEventArgs com3 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Edit", "0"));
  1006. Assert.AreEqual (false, bubbleeditingrow, "BeforeBubbleEventEditingRow");
  1007. gv.DoOnBubbleEvent (gv, com3);
  1008. Assert.AreEqual (true, bubbleeditingrow, "AfterBubbleEventEditingRow");
  1009. // Sort
  1010. gv.AllowSorting = true;
  1011. GridViewCommandEventArgs com4 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Sort", null));
  1012. Assert.AreEqual (false, bubblesortint, "BeforeBubbleEventSortingRow");
  1013. gv.DoOnBubbleEvent (gv, com4);
  1014. Assert.AreEqual (true, bubblesortint, "AfterBubbleEventSortingRow");
  1015. // Canceling Edit
  1016. GridViewCommandEventArgs com5 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Cancel", null));
  1017. Assert.AreEqual (false, bubblecanceling, "BeforeBubbleEventcancelingEdit");
  1018. gv.DoOnBubbleEvent (gv, com5);
  1019. Assert.AreEqual (true, bubblecanceling, "AfterBubbleEventcancelingEdit");
  1020. // Select
  1021. GridViewCommandEventArgs com6 = new GridViewCommandEventArgs (gv.SelectedRow, lb, new CommandEventArgs ("Select", "2"));
  1022. Assert.AreEqual (false, bubbleselect, "BeforeBubbleEventSelect");
  1023. gv.DoOnBubbleEvent (gv, com6);
  1024. Assert.AreEqual (true, bubbleselect, "AfterBubbleEventSelect");
  1025. //Next Page
  1026. GridViewCommandEventArgs com7 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Page", "Next"));
  1027. Assert.AreEqual (false, bubblepage, "BeforeBubbleEventNextPage");
  1028. gv.DoOnBubbleEvent (gv, com7);
  1029. Assert.AreEqual (true, bubblepage, "AfterBubbleEventNextPage");
  1030. Assert.AreEqual (1, newPageIndex, "NextPage");
  1031. // Prev Page
  1032. ResetEvents ();
  1033. GridViewCommandEventArgs com8 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Page", "Prev"));
  1034. Assert.AreEqual (false, bubblepage, "BeforeBubbleEventPrevPage");
  1035. gv.DoOnBubbleEvent (gv, com8);
  1036. Assert.AreEqual (true, bubblepage, "AfterBubbleEventPrevPage");
  1037. Assert.AreEqual (-1, newPageIndex, "PrevPage");
  1038. ResetEvents ();
  1039. GridViewCommandEventArgs com9 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Page", "Last"));
  1040. Assert.AreEqual (false, bubblepage, "BeforeBubbleEventLastPage");
  1041. gv.DoOnBubbleEvent (gv, com9);
  1042. Assert.AreEqual (true, bubblepage, "AfterBubbleEventLastPage");
  1043. ResetEvents ();
  1044. GridViewCommandEventArgs com10 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Page", "First"));
  1045. Assert.AreEqual (false, bubblepage, "BeforeBubbleEventFirstPage");
  1046. gv.DoOnBubbleEvent (gv, com10);
  1047. Assert.AreEqual (true, bubblepage, "AfterBubbleEventFirstPage");
  1048. Assert.AreEqual (0, newPageIndex, "FirstPage");
  1049. }
  1050. private void gv_RowDeleting (object sender, EventArgs e)
  1051. {
  1052. bubbledeleterow = true;
  1053. rowDeleting = true;
  1054. }
  1055. private void gv_RowUpdating (object sender, EventArgs e)
  1056. {
  1057. bubbleupdaterow = true;
  1058. rowUpdating = true;
  1059. }
  1060. private void gv_RowEditing (object sender, EventArgs e)
  1061. {
  1062. bubbleeditingrow = true;
  1063. rowEditing = true;
  1064. }
  1065. private void gv_Sorting (object sender, EventArgs e)
  1066. {
  1067. bubblesortint = true;
  1068. sorting = true;
  1069. }
  1070. private void gv_RowCancelingEdit (object sender, EventArgs e)
  1071. {
  1072. bubblecanceling = true;
  1073. gridViewCancelEdit = true;
  1074. }
  1075. private void gv_SelectedIndexChanging (object sender, GridViewSelectEventArgs e)
  1076. {
  1077. bubbleselect = true;
  1078. selectIndexChanging = true;
  1079. Assert.AreEqual (2, e.NewSelectedIndex, "SelectedIndexChanging");
  1080. }
  1081. private void gv_PageIndexChanging (object sender, GridViewPageEventArgs e)
  1082. {
  1083. bubblepage = true;
  1084. pageIndexChanging = true;
  1085. newPageIndex = e.NewPageIndex;
  1086. e.NewPageIndex = 0;
  1087. }
  1088. private void ResetEvents ()
  1089. {
  1090. bubblepage = false;
  1091. dataBinding = false;
  1092. pageIndexChanging = false;
  1093. gridViewCancelEdit = false;
  1094. rowDeleting = false;
  1095. rowEditing = false;
  1096. rowUpdating = false;
  1097. selectIndexChanging = false;
  1098. sorting = false;
  1099. }
  1100. // Events variable
  1101. private bool dataBinding;
  1102. private bool dataBound;
  1103. private bool init;
  1104. private bool load;
  1105. private bool pageIndexChanged;
  1106. private bool pageIndexChanging;
  1107. private bool preRender;
  1108. private bool gridViewCancelEdit;
  1109. private bool rowCommand;
  1110. private bool rowCreated;
  1111. private bool rowDataBound;
  1112. private bool rowDeleted;
  1113. private bool rowDeleting;
  1114. private bool rowEditing;
  1115. private bool rowUpdated;
  1116. private bool rowUpdating;
  1117. private bool selectIndexChanged;
  1118. private bool selectIndexChanging;
  1119. private bool sorted;
  1120. private bool sorting;
  1121. private bool unload;
  1122. [Test]
  1123. public void GridView_Events ()
  1124. {
  1125. PokerGridView gv = new PokerGridView ();
  1126. gv.DataSource = myds;
  1127. gv.DataBinding += new EventHandler (gv_DataBinding);
  1128. gv.DataBound += new EventHandler (gv_DataBound);
  1129. gv.PageIndexChanging += new GridViewPageEventHandler (gv_PageIndexChanging);
  1130. gv.PageIndexChanged += new EventHandler (gv_PageIndexChanged);
  1131. gv.PreRender += new EventHandler (gv_PreRender);
  1132. gv.RowCancelingEdit += new GridViewCancelEditEventHandler (gv_RowCancelingEdit);
  1133. gv.RowCommand += new GridViewCommandEventHandler (gv_RowCommand);
  1134. gv.RowCreated += new GridViewRowEventHandler (gv_RowCreated);
  1135. gv.RowDataBound += new GridViewRowEventHandler (gv_RowDataBound);
  1136. gv.RowDeleted += new GridViewDeletedEventHandler(gv_RowDeleted);
  1137. gv.RowDeleting+= new GridViewDeleteEventHandler(gv_RowDeleting);
  1138. gv.RowEditing+=new GridViewEditEventHandler(gv_RowEditing);
  1139. gv.RowUpdated+= new GridViewUpdatedEventHandler(gv_RowUpdated);
  1140. gv.RowUpdating+=new GridViewUpdateEventHandler(gv_RowUpdating);
  1141. gv.SelectedIndexChanged +=new EventHandler(gv_SelectedIndexChanged);
  1142. gv.SelectedIndexChanging+=new GridViewSelectEventHandler(gv_SelectedIndexChanging);
  1143. gv.Sorted +=new EventHandler(gv_Sorted);
  1144. gv.Sorting +=new GridViewSortEventHandler(gv_Sorting);
  1145. gv.Unload+=new EventHandler(gv_Unload);
  1146. Assert.AreEqual (false, dataBinding, "BeforeDataBinding");
  1147. gv.DoOnDataBinding (new EventArgs ());
  1148. Assert.AreEqual (true, dataBinding, "AfterDataBinding");
  1149. Assert.AreEqual (false, dataBound, "BeforeDataBound");
  1150. gv.DoOnDataBound (new EventArgs ());
  1151. Assert.AreEqual (true, dataBound, "AfterDataBound");
  1152. Assert.AreEqual (false, pageIndexChanged, "BeforepageIndexChanged");
  1153. gv.DoOnPageIndexChanged (new EventArgs ());
  1154. Assert.AreEqual (true, pageIndexChanged, "AfterpageIndexChanged");
  1155. ResetEvents ();
  1156. Assert.AreEqual (false, pageIndexChanging, "BeforepageIndexChanging");
  1157. gv.DoOnPageIndexChanging (new GridViewPageEventArgs(1));
  1158. Assert.AreEqual (true, pageIndexChanging, "AfterpageIndexChanging");
  1159. Assert.AreEqual (false, preRender, "BeforePreRender");
  1160. gv.DoOnPreRender (new EventArgs ());
  1161. Assert.AreEqual (true, preRender, "AfterPreRender");
  1162. ResetEvents ();
  1163. Assert.AreEqual (false, gridViewCancelEdit, "BeforeGridViewCancelEdit");
  1164. gv.DoOnRowCancelingEdit (new GridViewCancelEditEventArgs (1));
  1165. Assert.AreEqual (true, gridViewCancelEdit, "AfterGridViewCancelEdit");
  1166. ResetEvents ();
  1167. Assert.AreEqual (false, rowCommand, "BeforeRowCommand");
  1168. LinkButton lb= new LinkButton();
  1169. gv.DoOnRowCommand (new GridViewCommandEventArgs(lb,new CommandEventArgs("",null)));
  1170. Assert.AreEqual (true, rowCommand, "AfterRowCommand");
  1171. Assert.AreEqual (false, rowCreated, "BeforeRowCreated");
  1172. gv.DoOnRowCreated (new GridViewRowEventArgs (gv.SelectedRow));
  1173. Assert.AreEqual (true, rowCommand, "AfterRowCreated");
  1174. Assert.AreEqual (false, rowDataBound, "BeforeRowDataBound");
  1175. gv.DoOnRowDataBound (new GridViewRowEventArgs (gv.SelectedRow));
  1176. Assert.AreEqual (true, rowDataBound, "AfterRowDataBound");
  1177. Assert.AreEqual (false, rowDeleted, "BeforeRowDeleted");
  1178. gv.DoOnRowDeleted(new GridViewDeletedEventArgs(1,new ArgumentException()));
  1179. Assert.AreEqual (true, rowDeleted, "AfterRowDeleted");
  1180. ResetEvents ();
  1181. Assert.AreEqual (false, rowDeleting, "BeforeRowDeleting");
  1182. gv.DoOnRowDeleting (new GridViewDeleteEventArgs (0));
  1183. Assert.AreEqual (true, rowDeleting, "AfterRowDeleting");
  1184. ResetEvents ();
  1185. Assert.AreEqual (false, rowEditing, "BeforeRowEditing");
  1186. gv.DoOnRowEditing (new GridViewEditEventArgs (0));
  1187. Assert.AreEqual (true, rowEditing, "AfterRowEditing");
  1188. Assert.AreEqual (false, rowUpdated, "BeforeRowUpdated");
  1189. gv.DoOnRowUpdated (new GridViewUpdatedEventArgs(1,new Exception()));
  1190. Assert.AreEqual (true, rowUpdated, "AfterRowUpdated");
  1191. ResetEvents ();
  1192. Assert.AreEqual (false, rowUpdating, "BeforeRowUpdating");
  1193. gv.DoOnRowUpdating (new GridViewUpdateEventArgs (0));
  1194. Assert.AreEqual (true, rowUpdating, "AfterRowUpdating");
  1195. Assert.AreEqual (false, selectIndexChanged, "BeforeSelectedIndexChanged");
  1196. gv.DoOnSelectedIndexChanged (new EventArgs ());
  1197. Assert.AreEqual (true, selectIndexChanged, "AfterSelectedIndexChanged");
  1198. ResetEvents ();
  1199. Assert.AreEqual (false, selectIndexChanging, "BeforeSelectedIndexChanging");
  1200. gv.DoOnSelectedIndexChanging (new GridViewSelectEventArgs (2));
  1201. Assert.AreEqual (true, selectIndexChanging, "AfterSelectedIndexChanging");
  1202. Assert.AreEqual (false, sorted, "BeforeSorted");
  1203. gv.DoOnSorted (new EventArgs ());
  1204. Assert.AreEqual (true, sorted, "AfterSorted");
  1205. Assert.AreEqual (false, sorting, "BeforeSorting");
  1206. gv.DoOnSorting(new GridViewSortEventArgs("",SortDirection.Ascending));
  1207. Assert.AreEqual (true, sorting, "AfterSorting");
  1208. Assert.AreEqual (false, unload, "BeforeUnload");
  1209. gv.DoOnUnload (new EventArgs ());
  1210. Assert.AreEqual (true, unload, "AfterUnload");
  1211. }
  1212. private void gv_Unload (object sender, EventArgs e)
  1213. {
  1214. unload = true;
  1215. }
  1216. private void gv_Sorted (object sender, EventArgs e)
  1217. {
  1218. sorted = true;
  1219. }
  1220. private void gv_SelectedIndexChanged (object sender, EventArgs e)
  1221. {
  1222. selectIndexChanged = true;
  1223. }
  1224. private void gv_RowUpdated (object sender, EventArgs e)
  1225. {
  1226. rowUpdated = true;
  1227. }
  1228. private void gv_RowDeleted (object sender, EventArgs e)
  1229. {
  1230. rowDeleted = true;
  1231. }
  1232. private void gv_RowDataBound (object sender, EventArgs e)
  1233. {
  1234. rowDataBound = true;
  1235. }
  1236. private void gv_RowCreated (object sender, EventArgs e)
  1237. {
  1238. rowCreated = true;
  1239. }
  1240. private void gv_RowCommand (object sender, EventArgs e)
  1241. {
  1242. rowCommand = true;
  1243. }
  1244. private void gv_PreRender (object sender, EventArgs e)
  1245. {
  1246. preRender = true;
  1247. }
  1248. private void gv_DataBinding (object sender, EventArgs e)
  1249. {
  1250. dataBinding = true;
  1251. }
  1252. private void gv_DataBound (object sender, EventArgs e)
  1253. {
  1254. dataBound = true;
  1255. }
  1256. private void gv_Init (object sender, EventArgs e)
  1257. {
  1258. init = true;
  1259. }
  1260. private void gv_Load (object sender, EventArgs e)
  1261. {
  1262. load = true;
  1263. }
  1264. private void gv_PageIndexChanged (object sender, EventArgs e)
  1265. {
  1266. pageIndexChanged = true;
  1267. }
  1268. [Test]
  1269. [Category ("NunitWeb")]
  1270. public void GridView_DataSourceChangedEvent ()
  1271. {
  1272. WebTest t = new WebTest ();
  1273. PageDelegates pd = new PageDelegates ();
  1274. pd.Load = GridView_Init;
  1275. pd.PreRenderComplete = GridView_Load;
  1276. t.Invoker = new PageInvoker (pd);
  1277. t.Run ();
  1278. FormRequest fr = new FormRequest (t.Response, "form1");
  1279. fr.Controls.Add ("__EVENTTARGET");
  1280. fr.Controls.Add ("__EVENTARGUMENT");
  1281. fr.Controls["__EVENTTARGET"].Value = "";
  1282. fr.Controls["__EVENTARGUMENT"].Value = "";
  1283. t.Request = fr;
  1284. t.Run ();
  1285. if (t.UserData == null)
  1286. Assert.Fail ("DataSourceChangedEvent#1");
  1287. Assert.AreEqual ("Data_rebounded", t.UserData.ToString (), "DataSourceChangedEvent#2");
  1288. }
  1289. #region GridView_DataSourceChangedEvent
  1290. public static void GridView_Init (Page p)
  1291. {
  1292. PokerGridView gv = new PokerGridView ();
  1293. DS data = new DS ();
  1294. p.Controls.Add (gv);
  1295. p.Controls.Add (data);
  1296. data.TypeName = typeof (DS).AssemblyQualifiedName;
  1297. data.SelectMethod = "GetList";
  1298. data.ID = "Data";
  1299. gv.DataBinding += new EventHandler (data_DataBinding);
  1300. gv.DataSourceID = "Data";
  1301. }
  1302. public static void GridView_Load (Page p)
  1303. {
  1304. if (p.IsPostBack) {
  1305. DS data = (DS) p.FindControl ("Data");
  1306. if (data == null)
  1307. Assert.Fail ("Data soource control not created#1");
  1308. data.DoRaiseDataSourceChangedEvent (new EventArgs ());
  1309. }
  1310. }
  1311. public static void data_DataBinding (object sender, EventArgs e)
  1312. {
  1313. if (((WebControl) sender).Page.IsPostBack)
  1314. WebTest.CurrentTest.UserData = "Data_rebounded";
  1315. }
  1316. #endregion
  1317. [Test]
  1318. public void GridView_PerformDataBiding ()
  1319. {
  1320. PokerGridView gv = new PokerGridView ();
  1321. gv.DoPerformDataBinding (myds);
  1322. Assert.AreEqual (6, gv.Rows.Count, "PerformDataBiding_Rows");
  1323. }
  1324. [Test]
  1325. public void GridView_PrepareControlHierarchy ()
  1326. {
  1327. PokerGridView gv = new PokerGridView ();
  1328. gv.controlHierarchy = false;
  1329. gv.Render ();
  1330. Assert.AreEqual (0, gv.Controls.Count, "ControlHierarchy_ControlsCount");
  1331. Assert.AreEqual (true, gv.controlHierarchy, "ControlHierarchy_FirstFlow");
  1332. gv.DataSource = myds;
  1333. gv.DataBind ();
  1334. gv.controlHierarchy = false;
  1335. gv.Render ();
  1336. Assert.AreEqual (1, gv.Controls.Count, "ControlHierarchy_ControlsCountSecondaryFlow");
  1337. Assert.AreEqual (true, gv.controlHierarchy, "ControlHierarchy_SecondaryFlow");
  1338. }
  1339. [Test]
  1340. public void GridView_State ()
  1341. {
  1342. PokerGridView g = new PokerGridView ();
  1343. PokerGridView copy = new PokerGridView ();
  1344. string[] test = new String[1];
  1345. test[0] = "test";
  1346. g.DataKeyNames = test;
  1347. g.EditIndex = 0;
  1348. g.PageIndex = 2;
  1349. object state = g.DoSaveControlState ();
  1350. copy.DoLoadControlState (state);
  1351. Assert.AreEqu

Large files files are truncated, but you can click here to view the full file