FormViewRowTest.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // Tests for System.Web.UI.WebControls.FormView.cs
  3. //
  4. // Author:
  5. // Merav Sudri ([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. #if NET_2_0
  30. using NUnit.Framework;
  31. using System;
  32. using System.IO;
  33. using System.Drawing;
  34. using System.Collections;
  35. using System.Globalization;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.WebControls;
  39. using MonoTests.SystemWeb.Framework;
  40. using MonoTests.stand_alone.WebHarness;
  41. namespace MonoTests.System.Web.UI.WebControls
  42. {
  43. [TestFixture]
  44. public class FormViewRowTest {
  45. public class PokerFormViewRow : FormViewRow {
  46. public PokerFormViewRow (int itemIndex,DataControlRowType rowType,DataControlRowState rowState) : base(itemIndex,rowType,rowState)
  47. {
  48. TrackViewState ();
  49. }
  50. public object SaveState ()
  51. {
  52. return SaveViewState ();
  53. }
  54. public void LoadState (object o)
  55. {
  56. LoadViewState (o);
  57. }
  58. public StateBag StateBag
  59. {
  60. get { return base.ViewState; }
  61. }
  62. public void DoOnBubbleEvent (Object sender, EventArgs e)
  63. {
  64. OnBubbleEvent(sender,e);
  65. }
  66. public string Render ()
  67. {
  68. StringWriter sw = new StringWriter ();
  69. HtmlTextWriter tw = new HtmlTextWriter (sw);
  70. Render (tw);
  71. return sw.ToString ();
  72. }
  73. }
  74. [Test]
  75. public void FormViewRow_Properties ()
  76. {
  77. PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.DataRow, DataControlRowState.Edit);
  78. Assert.AreEqual (2, row.ItemIndex, "ItemIndex");
  79. Assert.AreEqual (DataControlRowType.DataRow, row.RowType, "RowType");
  80. Assert.AreEqual (DataControlRowState.Edit, row.RowState, "RowState");
  81. }
  82. private bool dataDeleting=false;
  83. private bool dataInserting = false;
  84. private bool dataUpdating = false;
  85. [Test]
  86. public void FormViewRow_BubbleEvent ()
  87. {
  88. FormView fv = new FormView ();
  89. PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.Footer, DataControlRowState.Insert);
  90. Button bt=new Button ();
  91. fv.Controls.Add (row);
  92. CommandEventArgs com=new CommandEventArgs (new CommandEventArgs ("Delete",null));
  93. fv.ItemDeleting += new FormViewDeleteEventHandler (R_DataBinding);
  94. Assert.AreEqual (false, dataDeleting, "BeforeBubbleEvent");
  95. row.DoOnBubbleEvent (row,com);
  96. Assert.AreEqual (true, dataDeleting, "AfterBubbleEvent");
  97. fv.ChangeMode (FormViewMode.Insert);
  98. com = new CommandEventArgs (new CommandEventArgs ("Insert", null));
  99. fv.ItemInserting += new FormViewInsertEventHandler (dv_ItemInserting);
  100. Assert.AreEqual (false, dataInserting, "BeforeInsertBubbleEvent");
  101. row.DoOnBubbleEvent (row, com);
  102. Assert.AreEqual (true, dataInserting, "AfterInsertBubbleEvent");
  103. fv.ChangeMode (FormViewMode.Edit);
  104. com = new CommandEventArgs (new CommandEventArgs ("Update", null));
  105. fv.ItemUpdating += new FormViewUpdateEventHandler (dv_ItemUpdating);
  106. Assert.AreEqual (false, dataUpdating, "BeforeUpdateBubbleEvent");
  107. row.DoOnBubbleEvent (row, com);
  108. Assert.AreEqual (true, dataUpdating, "AfterUpdateBubbleEvent");
  109. fv.ItemUpdating += new FormViewUpdateEventHandler (dv_ItemUpdating);
  110. }
  111. void dv_ItemUpdating (object sender, FormViewUpdateEventArgs e)
  112. {
  113. dataUpdating = true;
  114. }
  115. void dv_ItemInserting (object sender, FormViewInsertEventArgs e)
  116. {
  117. dataInserting = true;
  118. }
  119. public void R_DataBinding (object sender, EventArgs e)
  120. {
  121. dataDeleting = true;
  122. }
  123. //ViewState
  124. [Test]
  125. public void FormViewRow_ViewState ()
  126. {
  127. PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.Header, DataControlRowState.Selected);
  128. PokerFormViewRow copy = new PokerFormViewRow (3, DataControlRowType.Pager, DataControlRowState.Insert);
  129. row.CssClass = "style.css";
  130. row.BackColor = Color.Red;
  131. object state = row.SaveState ();
  132. copy.LoadState (state);
  133. Assert.AreEqual ("style.css", copy.CssClass, "ViewStateCssClass");
  134. Assert.AreEqual (Color.Red, copy.BackColor, "ViewStateHeaderText");
  135. }
  136. [Test]
  137. public void FormView_render ()
  138. {
  139. PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.Header, DataControlRowState.Selected);
  140. row.ID = "TestingRow";
  141. row.BackColor = Color.Red;
  142. string originalHtml = @"<tr id=""TestingRow"" style=""background-color:Red;""></tr>";
  143. HtmlDiff.AssertAreEqual (row.Render (), originalHtml, "FormViewRowRender");
  144. }
  145. }
  146. }
  147. #endif