FormViewTest.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // Tests for System.Web.UI.WebControls.FormView.cs
  3. //
  4. // Author:
  5. // Chris Toshok ([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.Collections;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. namespace MonoTests.System.Web.UI.WebControls
  39. {
  40. [TestFixture]
  41. public class FormViewTest {
  42. class Poker : FormView {
  43. public Poker () {
  44. TrackViewState ();
  45. }
  46. public object SaveState () {
  47. return SaveViewState ();
  48. }
  49. public void LoadState (object state) {
  50. LoadViewState (state);
  51. }
  52. public void DoConfirmInitState ()
  53. {
  54. base.ConfirmInitState ();
  55. }
  56. public void DoOnPreRender (EventArgs e)
  57. {
  58. base.OnPreRender (e);
  59. }
  60. }
  61. [Test]
  62. public void Defaults ()
  63. {
  64. Poker p = new Poker ();
  65. Assert.IsFalse (p.AllowPaging, "A1");
  66. Assert.AreEqual ("", p.BackImageUrl, "A2");
  67. Assert.IsNull (p.BottomPagerRow, "A3");
  68. Assert.AreEqual ("", p.Caption, "A4");
  69. Assert.AreEqual (TableCaptionAlign.NotSet, p.CaptionAlign ,"A5");
  70. Assert.AreEqual (-1, p.CellPadding, "A6");
  71. Assert.AreEqual (0, p.CellSpacing, "A7");
  72. Assert.AreEqual (FormViewMode.ReadOnly, p.CurrentMode, "A8");
  73. Assert.AreEqual (FormViewMode.ReadOnly, p.DefaultMode, "A9");
  74. Assert.IsNotNull (p.DataKeyNames, "A10");
  75. Assert.AreEqual (0, p.DataKeyNames.Length, "A10.1");
  76. Assert.IsNotNull (p.DataKey, "A11");
  77. Assert.AreEqual (0, p.DataKey.Values.Count, "A11.1");
  78. Assert.IsNull (p.EditItemTemplate, "A12");
  79. Assert.IsNotNull (p.EditRowStyle, "A13");
  80. Assert.IsNotNull (p.EmptyDataRowStyle, "A14");
  81. Assert.IsNull (p.EmptyDataTemplate, "A15");
  82. Assert.AreEqual ("", p.EmptyDataText, "A16");
  83. Assert.IsNull (p.FooterRow, "A17");
  84. Assert.IsNull (p.FooterTemplate, "A18");
  85. Assert.AreEqual ("", p.FooterText, "A19");
  86. Assert.IsNotNull (p.FooterStyle, "A20");
  87. Assert.AreEqual (GridLines.None, p.GridLines, "A21");
  88. Assert.IsNull (p.HeaderRow, "A22");
  89. Assert.IsNotNull (p.HeaderStyle, "A23");
  90. Assert.IsNull (p.HeaderTemplate, "A24");
  91. Assert.AreEqual ("", p.HeaderText, "A25");
  92. Assert.AreEqual (HorizontalAlign.NotSet, p.HorizontalAlign, "A26");
  93. Assert.IsNull (p.InsertItemTemplate, "A27");
  94. Assert.IsNotNull (p.InsertRowStyle, "A28");
  95. Assert.IsNull (p.ItemTemplate, "A29");
  96. Assert.AreEqual (0, p.PageCount, "A30");
  97. Assert.AreEqual (0, p.PageIndex, "A31");
  98. Assert.IsNull (p.PagerTemplate, "A32");
  99. Assert.IsNull (p.Row, "A33");
  100. Assert.IsNotNull (p.RowStyle, "A34");
  101. Assert.IsNull (p.SelectedValue, "A35");
  102. Assert.IsNull (p.TopPagerRow, "A36");
  103. Assert.IsNull (p.DataItem, "A37");
  104. Assert.AreEqual (0, p.DataItemCount, "A38");
  105. Assert.AreEqual (0, p.DataItemIndex, "A39");
  106. }
  107. [Test]
  108. public void PageIndex ()
  109. {
  110. ObjectDataSource ds = new ObjectDataSource ();
  111. ds.ID = "ObjectDataSource1";
  112. ds.TypeName = "System.Guid";
  113. ds.SelectMethod = "ToByteArray";
  114. Page p = new Page ();
  115. Poker f = new Poker ();
  116. f.Page = p;
  117. ds.Page = p;
  118. p.Controls.Add (f);
  119. p.Controls.Add (ds);
  120. f.DataSourceID = "ObjectDataSource1";
  121. f.DoConfirmInitState ();
  122. f.DoOnPreRender (EventArgs.Empty);
  123. object cur = f.DataItem;
  124. f.PageIndex = 1;
  125. Assert.IsTrue (cur != f.DataItem, "#01");
  126. }
  127. [Test]
  128. public void PageCount ()
  129. {
  130. ObjectDataSource ds = new ObjectDataSource ();
  131. ds.ID = "ObjectDataSource1";
  132. ds.TypeName = "System.Guid";
  133. ds.SelectMethod = "ToByteArray";
  134. Page p = new Page ();
  135. Poker f = new Poker ();
  136. f.Page = p;
  137. ds.Page = p;
  138. p.Controls.Add (f);
  139. p.Controls.Add (ds);
  140. f.DataSourceID = "ObjectDataSource1";
  141. f.DoConfirmInitState ();
  142. f.DoOnPreRender (EventArgs.Empty);
  143. f.PageIndex = 1;
  144. Assert.AreEqual (16, f.PageCount, "#01");
  145. }
  146. }
  147. }
  148. #endif