TextBoxTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Tests for System.Web.UI.WebControls.TextBox.cs
  3. //
  4. // Author:
  5. // Ben Maurer ([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. using NUnit.Framework;
  30. using System;
  31. using System.IO;
  32. using System.Globalization;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. namespace MonoTests.System.Web.UI.WebControls {
  37. [TestFixture]
  38. public class TextBoxTest {
  39. class Poker : TextBox {
  40. public new void AddParsedSubObject (object o)
  41. {
  42. base.AddParsedSubObject (o);
  43. }
  44. public void TrackState ()
  45. {
  46. TrackViewState ();
  47. }
  48. public object SaveState ()
  49. {
  50. foreach (string s in ViewState.Keys)
  51. Console.WriteLine ("{0}: {1}", s, ViewState[s]);
  52. return SaveViewState ();
  53. }
  54. public void LoadState (object o)
  55. {
  56. LoadViewState (o);
  57. }
  58. public string Render ()
  59. {
  60. StringWriter sw = new StringWriter ();
  61. sw.NewLine = "\n";
  62. HtmlTextWriter writer = new HtmlTextWriter (sw);
  63. base.Render (writer);
  64. return writer.InnerWriter.ToString ();
  65. }
  66. }
  67. [Test]
  68. [Category ("NotWorking")]
  69. public void MultilineRenderEscape ()
  70. {
  71. Poker t = new Poker ();
  72. t.TextMode = TextBoxMode.MultiLine;
  73. t.Text = "</textarea>";
  74. #if NET_2_0
  75. string exp = "<textarea rows=\"2\" cols=\"20\">&lt;/textarea&gt;</textarea>";
  76. #else
  77. string exp = "<textarea name>&lt;/textarea&gt;</textarea>";
  78. #endif
  79. Assert.AreEqual (exp, t.Render ());
  80. }
  81. #if NET_2_0
  82. [Test]
  83. public void ValidationProperties ()
  84. {
  85. Poker t = new Poker ();
  86. // initial values
  87. Assert.AreEqual (false, t.CausesValidation, "A1");
  88. Assert.AreEqual ("", t.ValidationGroup, "A2");
  89. t.ValidationGroup = "VG";
  90. Assert.AreEqual ("VG", t.ValidationGroup, "A3");
  91. t.CausesValidation = true;
  92. Assert.IsTrue (t.CausesValidation, "A4");
  93. }
  94. [Test]
  95. public void ViewState ()
  96. {
  97. Poker t = new Poker ();
  98. t.TrackState();
  99. t.ValidationGroup = "VG";
  100. t.CausesValidation = true;
  101. object s = t.SaveState ();
  102. Console.WriteLine ("state = {0}", s == null ? "null" : "not-null");
  103. Poker copy = new Poker ();
  104. copy.LoadState (s);
  105. Assert.AreEqual ("VG", copy.ValidationGroup, "A1");
  106. Assert.IsTrue (copy.CausesValidation, "A2");
  107. }
  108. [Test]
  109. [Category ("NotWorking")]
  110. public void ValidationRender ()
  111. {
  112. /* test to show that the validation settings
  113. * have no effect on downlevel rendering */
  114. Poker t = new Poker ();
  115. t.TrackState();
  116. t.ValidationGroup = "VG";
  117. t.CausesValidation = true;
  118. t.TextMode = TextBoxMode.MultiLine;
  119. string exp = "<textarea rows=\"2\" cols=\"20\"></textarea>";
  120. Assert.AreEqual (exp, t.Render ());
  121. }
  122. #endif
  123. }
  124. }