RadioButtonListTest.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // Tests for System.Web.UI.WebControls.RadioButtonListTest.cs
  3. //
  4. // Author:
  5. // Jordi Mas i Hernandez ([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 System.Web.UI.WebControls;
  30. using NUnit.Framework;
  31. using System;
  32. using System.Drawing;
  33. using System.IO;
  34. using System.Web;
  35. using System.Web.UI;
  36. using System.Globalization;
  37. namespace MonoTests.System.Web.UI.WebControls {
  38. [TestFixture]
  39. public class RadioButtonListTest {
  40. public class TestRadioButtonList : RadioButtonList {
  41. public StateBag StateBag {
  42. get { return base.ViewState; }
  43. }
  44. public string Render ()
  45. {
  46. HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
  47. base.Render (writer);
  48. return writer.InnerWriter.ToString ();
  49. }
  50. }
  51. [Test]
  52. public void RadioButtonList_Constructor ()
  53. {
  54. TestRadioButtonList r = new TestRadioButtonList ();
  55. Assert.AreEqual (-1, r.CellPadding, "A1");
  56. Assert.AreEqual (-1, r.CellSpacing, "A2");
  57. Assert.AreEqual (0, r.RepeatColumns, "A3");
  58. Assert.AreEqual (RepeatDirection.Vertical, r.RepeatDirection, "A4");
  59. Assert.AreEqual (RepeatLayout.Table, r.RepeatLayout, "A5");
  60. Assert.AreEqual (TextAlign.Right, r.TextAlign, "A6");
  61. Assert.AreEqual (false, ((IRepeatInfoUser)r).HasFooter, "A7");
  62. Assert.AreEqual (false, ((IRepeatInfoUser)r).HasHeader, "A8");
  63. Assert.AreEqual (false, ((IRepeatInfoUser)r).HasSeparators, "A9");
  64. Assert.AreEqual (0, ((IRepeatInfoUser)r).RepeatedItemCount, "A10");
  65. }
  66. [Test]
  67. public void CellPaddingProperties ()
  68. {
  69. TestRadioButtonList r = new TestRadioButtonList ();
  70. r.CellPadding = 5;
  71. Assert.AreEqual (5, r.CellPadding, "setting");
  72. string s = r.Render ();
  73. Assert.IsTrue (s.ToLower ().IndexOf ("cellpadding=\"5\"") != -1, "htmloutput");
  74. }
  75. [Test]
  76. public void CellSpacingProperties ()
  77. {
  78. TestRadioButtonList r = new TestRadioButtonList ();
  79. r.CellSpacing = 5;
  80. Assert.AreEqual (5, r.CellSpacing, "setting");
  81. string s = r.Render ();
  82. Assert.IsTrue (s.ToLower ().IndexOf ("cellspacing=\"5\"") != -1, "htmloutput");
  83. }
  84. [Test]
  85. public void Render ()
  86. {
  87. TestRadioButtonList c = new TestRadioButtonList ();
  88. c.Items.Add (new ListItem ("text2", "value1"));
  89. string s = c.Render ();
  90. Assert.IsTrue (s.ToLower ().IndexOf (" type=\"radio\"") != -1, "type");
  91. Assert.IsTrue (s.ToLower ().IndexOf ("value1") != -1, "value");
  92. Assert.IsTrue (s.ToLower ().IndexOf ("text2") != -1, "text");
  93. }
  94. // Exceptions
  95. [Test]
  96. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  97. public void RepeatColumnsException ()
  98. {
  99. TestRadioButtonList r = new TestRadioButtonList ();
  100. r.RepeatColumns = -1;
  101. }
  102. [Test]
  103. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  104. public void RepeatDirectionException ()
  105. {
  106. TestRadioButtonList r = new TestRadioButtonList ();
  107. r.RepeatDirection = (RepeatDirection) 4;
  108. }
  109. [Test]
  110. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  111. public void RepeatLayoutException ()
  112. {
  113. TestRadioButtonList r = new TestRadioButtonList ();
  114. r.RepeatLayout = (RepeatLayout) 3;
  115. }
  116. }
  117. }