HtmlInputButtonTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // HtmlInputButtonTest.cs
  3. // - Unit tests for System.Web.UI.HtmlControls.HtmlInputButton
  4. //
  5. // Author:
  6. // Jackson Harper ([email protected])
  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 System;
  30. using System.IO;
  31. using System.Web.UI;
  32. using System.Web.UI.HtmlControls;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Web.UI.HtmlControls {
  35. public class HtmlInputButtonPoker : HtmlInputButton {
  36. public HtmlInputButtonPoker ()
  37. {
  38. TrackViewState ();
  39. }
  40. public object SaveState ()
  41. {
  42. return SaveViewState ();
  43. }
  44. public void LoadState (object state)
  45. {
  46. LoadViewState (state);
  47. }
  48. public void DoRenderAttributes (HtmlTextWriter writer)
  49. {
  50. RenderAttributes (writer);
  51. }
  52. }
  53. [TestFixture]
  54. public class HtmlInputButtonTest {
  55. [Test]
  56. public void Defaults ()
  57. {
  58. HtmlInputButtonPoker p = new HtmlInputButtonPoker ();
  59. Assert.IsTrue (p.CausesValidation, "A1");
  60. }
  61. [Test]
  62. public void CleanProperties ()
  63. {
  64. HtmlInputButtonPoker p = new HtmlInputButtonPoker ();
  65. p.CausesValidation = false;
  66. Assert.IsFalse (p.CausesValidation, "A1");
  67. p.CausesValidation = true;
  68. Assert.IsTrue (p.CausesValidation, "A2");
  69. p.CausesValidation = false;
  70. Assert.IsFalse (p.CausesValidation, "A3");
  71. }
  72. [Test]
  73. public void ViewState ()
  74. {
  75. HtmlInputButtonPoker p = new HtmlInputButtonPoker ();
  76. #if NET_2_0
  77. p.CausesValidation = false;
  78. p.ValidationGroup = "VG";
  79. #endif
  80. object s = p.SaveState();
  81. HtmlInputButtonPoker copy = new HtmlInputButtonPoker ();
  82. copy.LoadState (s);
  83. #if NET_2_0
  84. Assert.IsFalse (copy.CausesValidation, "A1");
  85. Assert.AreEqual ("VG", p.ValidationGroup, "A2");
  86. #endif
  87. }
  88. [Test]
  89. public void RenderAttributes ()
  90. {
  91. StringWriter sw = new StringWriter ();
  92. HtmlTextWriter tw = new HtmlTextWriter (sw);
  93. HtmlInputButtonPoker p = new HtmlInputButtonPoker ();
  94. p.Page = new Page ();
  95. p.CausesValidation = false;
  96. #if NET_2_0
  97. p.ValidationGroup = "VG";
  98. Assert.AreEqual (3, p.Attributes.Count, "A1");
  99. #else
  100. Assert.AreEqual (2, p.Attributes.Count, "A1");
  101. #endif
  102. p.DoRenderAttributes (tw);
  103. #if NET_2_0
  104. Assert.AreEqual (" name type=\"button\" ValidationGroup=\"VG\" /", sw.ToString (), "A2");
  105. #else
  106. Assert.AreEqual (" name type=\"button\" /", sw.ToString (), "A2");
  107. #endif
  108. }
  109. [Test]
  110. public void OnClickAttribute ()
  111. {
  112. StringWriter sw = new StringWriter ();
  113. HtmlTextWriter tw = new HtmlTextWriter (sw);
  114. HtmlInputButtonPoker p = new HtmlInputButtonPoker ();
  115. p.Page = new Page ();
  116. p.DoRenderAttributes (tw);
  117. string str = sw.ToString ();
  118. int found = str.IndexOf ("onclick");
  119. Assert.AreEqual (-1, found, "#01");
  120. p.ServerClick += new EventHandler (EmptyHandler);
  121. sw = new StringWriter ();
  122. tw = new HtmlTextWriter (sw);
  123. p.DoRenderAttributes (tw);
  124. str = sw.ToString ();
  125. found = str.IndexOf ("onclick");
  126. Assert.IsTrue (found >= 0, "#02");
  127. }
  128. private static void EmptyHandler (object sender, EventArgs e)
  129. {
  130. }
  131. }
  132. }