HtmlInputHiddenTest.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. //
  22. // System.Web.UI.HtmlControls.HtmlInputHidden.cs
  23. //
  24. // Authors:
  25. // Jackson Harper ([email protected])
  26. //
  27. // (C) 2005 Novell, Inc.
  28. using System;
  29. using System.IO;
  30. using System.Web.UI;
  31. using System.Web.UI.HtmlControls;
  32. using System.Collections.Specialized;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Web.UI.HtmlControls {
  35. public class HtmlInputHiddenPoker : HtmlInputHidden {
  36. public string Render ()
  37. {
  38. StringWriter sw = new StringWriter ();
  39. HtmlTextWriter tw = new HtmlTextWriter (sw);
  40. base.Render (tw);
  41. return sw.ToString ();
  42. }
  43. }
  44. [TestFixture]
  45. public class HtmlInputHiddenTest {
  46. [Test]
  47. public void Defaults ()
  48. {
  49. HtmlInputHidden h = new HtmlInputHidden ();
  50. Assert.AreEqual (h.Type, "hidden", "A1");
  51. Assert.AreEqual (h.Value, String.Empty, "A2");
  52. }
  53. [Test]
  54. public void PropertiesNull ()
  55. {
  56. HtmlInputHidden h = new HtmlInputHidden ();
  57. h.Value = null;
  58. Assert.AreEqual (h.Value, String.Empty, "A1");
  59. }
  60. [Test]
  61. public void Postback ()
  62. {
  63. HtmlInputHidden h = new HtmlInputHidden ();
  64. IPostBackDataHandler p = (IPostBackDataHandler) h;
  65. NameValueCollection collection = new NameValueCollection ();
  66. string key = "key";
  67. string value = "Hi i am a value";
  68. collection [key] = value;
  69. p.LoadPostData (key, collection);
  70. Assert.AreEqual (h.Value, value, "A1");
  71. }
  72. [Test]
  73. public void TestPostbackHandling ()
  74. {
  75. HtmlInputHidden h = new HtmlInputHidden ();
  76. IPostBackDataHandler p = (IPostBackDataHandler) h;
  77. NameValueCollection collection = new NameValueCollection ();
  78. string key = "key";
  79. string value = "Hi i am a value";
  80. collection [key] = value;
  81. Assert.IsTrue(p.LoadPostData (key, collection));
  82. Assert.IsFalse (p.LoadPostData (key, collection));
  83. Assert.AreEqual (h.Value, value);
  84. }
  85. [Test]
  86. public void Render ()
  87. {
  88. HtmlInputHiddenPoker p = new HtmlInputHiddenPoker ();
  89. Assert.AreEqual (p.Render (), "<input name type=\"hidden\" />");
  90. p.Value = "foobar";
  91. Assert.AreEqual (p.Render (), "<input name type=\"hidden\" " +
  92. "value=\"foobar\" />");
  93. }
  94. }
  95. }