HtmlInputCheckBoxTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // HtmlInputCheckBoxTest.cs
  3. // - Unit tests for System.Web.UI.HtmlControls.HtmlInputCheckBox
  4. //
  5. // Author:
  6. // Dick Porter <[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 TestHtmlInputCheckBox : HtmlInputCheckBox {
  36. public string Render ()
  37. {
  38. HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
  39. base.Render (writer);
  40. return writer.InnerWriter.ToString ();
  41. }
  42. }
  43. [TestFixture]
  44. public class HtmlInputCheckBoxTest {
  45. [Test]
  46. public void DefaultProperties ()
  47. {
  48. HtmlInputCheckBox c = new HtmlInputCheckBox ();
  49. #if NET_2_0
  50. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
  51. #else
  52. Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count");
  53. #endif
  54. Assert.IsFalse (c.Checked, "Checked");
  55. #if NET_2_0
  56. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count after");
  57. #else
  58. Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count after");
  59. #endif
  60. }
  61. [Test]
  62. public void NullProperties ()
  63. {
  64. HtmlInputCheckBox c = new HtmlInputCheckBox ();
  65. #if NET_2_0
  66. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count");
  67. #else
  68. Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count");
  69. #endif
  70. c.Checked = true;
  71. Assert.IsTrue (c.Checked, "Checked");
  72. #if NET_2_0
  73. Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count after");
  74. #else
  75. Assert.AreEqual (2, c.Attributes.Count, "Attributes.Count after");
  76. #endif
  77. }
  78. [Test]
  79. public void CleanProperties ()
  80. {
  81. HtmlInputCheckBox c = new HtmlInputCheckBox ();
  82. c.Checked = true;
  83. #if NET_2_0
  84. Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count");
  85. #else
  86. Assert.AreEqual (2, c.Attributes.Count, "Attributes.Count");
  87. #endif
  88. c.Checked = false;
  89. #if NET_2_0
  90. Assert.AreEqual (0, c.Attributes.Count, "Attributes.Count after");
  91. #else
  92. Assert.AreEqual (1, c.Attributes.Count, "Attributes.Count after");
  93. #endif
  94. }
  95. [Test]
  96. public void Render ()
  97. {
  98. TestHtmlInputCheckBox c = new TestHtmlInputCheckBox ();
  99. c.ID = "*1*";
  100. string s = c.Render ();
  101. Assert.IsTrue (s.IndexOf (" type=\"checkbox\"") > 0, "type");
  102. c.Checked = true;
  103. s = c.Render ();
  104. #if NET_2_0
  105. Assert.AreEqual ("<input name=\"*1*\" type=\"checkbox\" id=\"*1*\" checked=\"checked\" />", s);
  106. #else
  107. Assert.AreEqual ("<input name=\"*1*\" id=\"*1*\" type=\"checkbox\" checked=\"checked\" />", s);
  108. #endif
  109. }
  110. }
  111. }