2
0

ButtonTest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Tests for System.Web.UI.WebControls.Button.cs
  3. //
  4. // Author:
  5. // Jordi Mas i Hernandez ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. //
  9. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using NUnit.Framework;
  31. using System;
  32. using System.IO;
  33. using System.Globalization;
  34. using System.Web;
  35. using System.Web.UI;
  36. using System.Web.UI.WebControls;
  37. namespace MonoTests.System.Web.UI.WebControls
  38. {
  39. class PokerButton : Button {
  40. public PokerButton ()
  41. {
  42. TrackViewState ();
  43. }
  44. public object SaveState ()
  45. {
  46. return SaveViewState ();
  47. }
  48. public void LoadState (object o)
  49. {
  50. LoadViewState (o);
  51. }
  52. }
  53. [TestFixture]
  54. public class ButtonTest {
  55. [Test]
  56. public void Button_DefaultValues ()
  57. {
  58. Button b = new Button ();
  59. Assert.AreEqual (true, b.CausesValidation, "CausesValidation");
  60. Assert.AreEqual (string.Empty, b.CommandArgument, "CommandArgument");
  61. Assert.AreEqual (string.Empty, b.CommandName, "CommandName");
  62. #if NET_2_0
  63. Assert.AreEqual (string.Empty, b.ValidationGroup, "ValidationGroup");
  64. #endif
  65. }
  66. [Test]
  67. public void Button_ViewState ()
  68. {
  69. PokerButton p = new PokerButton ();
  70. Assert.AreEqual (p.Text, "", "A1");
  71. p.Text = "Hello";
  72. Assert.AreEqual (p.Text, "Hello", "A2");
  73. #if NET_2_0
  74. p.ValidationGroup = "VG1";
  75. Assert.AreEqual (p.ValidationGroup, "VG1", "A3");
  76. #endif
  77. object state = p.SaveState ();
  78. PokerButton copy = new PokerButton ();
  79. copy.LoadState (state);
  80. Assert.AreEqual (copy.Text, "Hello", "A4");
  81. #if NET_2_0
  82. Assert.AreEqual (copy.ValidationGroup, "VG1", "A5");
  83. #endif
  84. }
  85. [Test]
  86. public void Button_Render ()
  87. {
  88. StringWriter sw = new StringWriter ();
  89. HtmlTextWriter tw = new HtmlTextWriter (sw);
  90. Button b = new Button ();
  91. b.Text = "Hello";
  92. b.RenderControl (tw);
  93. Assert.AreEqual (true, sw.ToString().IndexOf ("value=\"Hello\"") != -1, "A4");
  94. Assert.AreEqual (true, sw.ToString().IndexOf ("<input") != -1, "A5");
  95. Assert.AreEqual (true, sw.ToString().IndexOf ("type=\"submit\"") != -1, "A6");
  96. }
  97. [Test]
  98. public void IgnoresChildren ()
  99. {
  100. Button b = new Button ();
  101. b.Controls.Add (new LiteralControl ("hola"));
  102. Assert.AreEqual (1, b.Controls.Count, "controls");
  103. StringWriter sw = new StringWriter ();
  104. HtmlTextWriter tw = new HtmlTextWriter (sw);
  105. b.RenderControl (tw);
  106. string str = tw.ToString ();
  107. Assert.AreEqual (-1, str.IndexOf ("hola"), "hola");
  108. }
  109. }
  110. }