2 // Tests for System.Web.UI.WebControls.RadioButtonList.cs
5 // Jordi Mas i Hernandez (jordi@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@novell.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Web.UI.WebControls;
33 using NUnit.Framework;
35 using System.Collections.Specialized;
39 using System.Globalization;
42 namespace MonoTests.System.Web.UI.WebControls {
45 public class RadioButtonListTest {
47 public class TestRadioButtonList : RadioButtonList {
48 public StateBag StateBag {
49 get { return base.ViewState; }
52 public string Render ()
54 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
56 return writer.InnerWriter.ToString ();
61 public void RadioButtonList_Constructor ()
63 TestRadioButtonList r = new TestRadioButtonList ();
64 Assert.AreEqual (-1, r.CellPadding, "A1");
65 Assert.AreEqual (-1, r.CellSpacing, "A2");
66 Assert.AreEqual (0, r.RepeatColumns, "A3");
67 Assert.AreEqual (RepeatDirection.Vertical, r.RepeatDirection, "A4");
68 Assert.AreEqual (RepeatLayout.Table, r.RepeatLayout, "A5");
69 Assert.AreEqual (TextAlign.Right, r.TextAlign, "A6");
70 Assert.AreEqual (false, ((IRepeatInfoUser)r).HasFooter, "A7");
71 Assert.AreEqual (false, ((IRepeatInfoUser)r).HasHeader, "A8");
72 Assert.AreEqual (false, ((IRepeatInfoUser)r).HasSeparators, "A9");
73 Assert.AreEqual (0, ((IRepeatInfoUser)r).RepeatedItemCount, "A10");
77 public void CellPaddingProperties ()
79 TestRadioButtonList r = new TestRadioButtonList ();
81 Assert.AreEqual (5, r.CellPadding, "setting");
83 string s = r.Render ();
85 // FIXME: missing some info to start rendering ?
86 Assert.AreEqual (String.Empty, s, "htmloutput");
88 Assert.IsTrue (s.ToLower ().IndexOf ("cellpadding=\"5\"") != -1, "htmloutput");
93 public void CellSpacingProperties ()
95 TestRadioButtonList r = new TestRadioButtonList ();
97 Assert.AreEqual (5, r.CellSpacing, "setting");
99 string s = r.Render ();
101 // FIXME: missing some info to start rendering ?
102 Assert.AreEqual (String.Empty, s, "htmloutput");
104 Assert.IsTrue (s.ToLower ().IndexOf ("cellspacing=\"5\"") != -1, "htmloutput");
110 // FIXME: missing some info to start rendering ?
111 [ExpectedException (typeof (NullReferenceException))]
113 public void Render ()
115 TestRadioButtonList c = new TestRadioButtonList ();
117 c.Items.Add (new ListItem ("text2", "value1"));
119 string s = c.Render ();
121 Assert.IsTrue (s.ToLower ().IndexOf (" type=\"radio\"") != -1, "type");
122 Assert.IsTrue (s.ToLower ().IndexOf ("value1") != -1, "value");
123 Assert.IsTrue (s.ToLower ().IndexOf ("text2") != -1, "text");
128 [ExpectedException (typeof (ArgumentOutOfRangeException))]
129 public void RepeatColumnsException ()
131 TestRadioButtonList r = new TestRadioButtonList ();
132 r.RepeatColumns = -1;
136 [ExpectedException (typeof (ArgumentOutOfRangeException))]
137 public void RepeatDirectionException ()
139 TestRadioButtonList r = new TestRadioButtonList ();
140 r.RepeatDirection = (RepeatDirection) 4;
145 [ExpectedException (typeof (ArgumentOutOfRangeException))]
146 public void RepeatLayoutException ()
148 TestRadioButtonList r = new TestRadioButtonList ();
149 r.RepeatLayout = (RepeatLayout) 3;
153 void OnSelected (object sender, EventArgs args)
159 public void LoadAndRaise1 ()
161 RadioButtonList rbl = new RadioButtonList ();
162 rbl.Items.Add (new ListItem ("Uno", "1"));
163 rbl.Items.Add (new ListItem ("Dos", "2"));
164 rbl.Items.Add (new ListItem ("Tres", "3"));
165 rbl.SelectedIndex = 2;
166 NameValueCollection nvc = new NameValueCollection ();
169 IPostBackDataHandler handler = (IPostBackDataHandler) rbl;
171 Assert.IsFalse (handler.LoadPostData ("XXX", nvc), "#01");
173 Assert.IsTrue (handler.LoadPostData ("XXX", nvc), "#01");
175 rbl.SelectedIndexChanged += new EventHandler (OnSelected);
176 event_called = false;
177 handler.RaisePostDataChangedEvent ();
179 Assert.IsTrue (event_called, "#02");
181 // Not called. Value is the same as the selected previously
182 Assert.IsFalse (event_called, "#02");
184 Assert.AreEqual ("3", rbl.SelectedValue, "#03");
188 public void LoadAndRaise2 ()
190 RadioButtonList rbl = new RadioButtonList ();
191 rbl.Items.Add (new ListItem ("Uno", "1"));
192 rbl.Items.Add (new ListItem ("Dos", "2"));
193 rbl.Items.Add (new ListItem ("Tres", "3"));
194 rbl.SelectedIndex = 2;
195 NameValueCollection nvc = new NameValueCollection ();
198 IPostBackDataHandler handler = (IPostBackDataHandler) rbl;
199 Assert.AreEqual (true, handler.LoadPostData ("XXX", nvc), "#01");
200 rbl.SelectedIndexChanged += new EventHandler (OnSelected);
201 event_called = false;
202 handler.RaisePostDataChangedEvent ();
203 Assert.AreEqual (true, event_called, "#02");
204 Assert.AreEqual ("2", rbl.SelectedValue, "#03");
208 public void LoadAndRaise3 ()
210 RadioButtonList rbl = new RadioButtonList ();
211 rbl.Items.Add (new ListItem ("Uno", "1"));
212 rbl.Items.Add (new ListItem ("Dos", "2"));
213 rbl.Items.Add (new ListItem ("Tres", "3"));
214 rbl.SelectedIndex = 2;
215 NameValueCollection nvc = new NameValueCollection ();
216 nvc ["XXX"] = "blah";
218 IPostBackDataHandler handler = (IPostBackDataHandler) rbl;
219 Assert.AreEqual (false, handler.LoadPostData ("XXX", nvc), "#01");