2 // RepeatInfoTest.cs - Unit tests for System.Web.UI.WebControls.RepeatInfo
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
31 using System.ComponentModel;
36 using System.Web.UI.WebControls;
38 using NUnit.Framework;
40 namespace MonoTests.System.Web.UI.WebControls {
42 public class RepeatInfoUser : IRepeatInfoUser {
46 private bool separators;
51 public RepeatInfoUser (bool footer, bool header, bool separators, int count)
56 this.separators = separators;
61 public bool HasFooter {
62 get { return footer; }
65 public bool HasHeader {
66 get { return header; }
69 public bool HasSeparators {
70 get { return separators; }
73 public int RepeatedItemCount {
77 public Style GetItemStyle (ListItemType itemType, int repeatIndex)
82 public void RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
84 writer.Write ((counter++).ToString ());
89 public class RepeatInfoTest {
91 private HtmlTextWriter GetWriter ()
93 StringWriter sw = new StringWriter ();
95 return new HtmlTextWriter (sw);
98 string DoTest (int cols, int cnt, RepeatDirection d, RepeatLayout l, bool OuterTableImplied, bool ftr, bool hdr, bool sep)
100 HtmlTextWriter htw = GetWriter ();
101 RepeatInfo ri = new RepeatInfo ();
102 ri.RepeatColumns = cols;
103 ri.RepeatDirection = d;
105 ri.OuterTableImplied = OuterTableImplied;
107 ri.RenderRepeater (htw, new RepeatInfoUser (ftr, hdr, sep, cnt), new TableStyle (), new DataList ());
108 return htw.InnerWriter.ToString ();
112 public void DefaultValues ()
114 RepeatInfo ri = new RepeatInfo ();
115 Assert.AreEqual (0, ri.RepeatColumns, "RepeatColumns");
116 Assert.AreEqual (RepeatDirection.Vertical, ri.RepeatDirection, "RepeatDirection");
117 Assert.AreEqual (RepeatLayout.Table, ri.RepeatLayout, "RepeatLayout");
118 Assert.IsFalse (ri.OuterTableImplied, "OuterTableImplied");
122 public void RepeatColumns_Negative ()
124 RepeatInfo ri = new RepeatInfo ();
125 ri.RepeatColumns = -1;
126 Assert.AreEqual (-1, ri.RepeatColumns, "-1");
127 ri.RepeatColumns = Int32.MinValue;
128 Assert.AreEqual (Int32.MinValue, ri.RepeatColumns, "Int32.MinValue");
132 [ExpectedException (typeof (ArgumentOutOfRangeException))]
133 public void RepeatDirection_Invalid ()
135 RepeatInfo ri = new RepeatInfo ();
136 ri.RepeatDirection = (RepeatDirection) Int32.MinValue;
140 [ExpectedException (typeof (ArgumentOutOfRangeException))]
141 public void RepeatLayout_Invalid ()
143 RepeatInfo ri = new RepeatInfo ();
144 ri.RepeatLayout = (RepeatLayout) Int32.MinValue;
147 private void RenderRepeater_BaseControl (string s, string msg, WebControl wc)
149 RepeatInfo ri = new RepeatInfo ();
150 ri.RepeatColumns = 3;
151 ri.RepeatDirection = RepeatDirection.Vertical;
152 ri.RepeatLayout = RepeatLayout.Table;
154 HtmlTextWriter writer = GetWriter ();
155 ri.RenderRepeater (writer, new RepeatInfoUser (false, false, false, 1), new TableStyle (), wc);
156 string rendered = writer.InnerWriter.ToString ();
157 Assert.AreEqual (s, rendered, msg);
161 [ExpectedException (typeof (NullReferenceException))]
162 public void RenderRepeater_BaseControl_Null ()
164 RenderRepeater_BaseControl ("shouldn't get here", "null", null);
168 public void RenderRepeater_BaseControl ()
170 string noid = "<table>\n\t<tr>\n\t\t<td>0</td><td></td><td></td>\n\t</tr>\n</table>";
171 string id_enabled = "<table id=\"foo\" class=\"aspNetDisabled\">\n\t<tr>\n\t\t<td>0</td><td></td><td></td>\n\t</tr>\n</table>";
172 RenderRepeater_BaseControl (noid, "Table", new Table ());
173 RenderRepeater_BaseControl (noid, "DataList", new DataList ());
174 RenderRepeater_BaseControl (noid, "DataListItem", new DataListItem (0, ListItemType.Item));
176 Label l = new Label ();
180 RenderRepeater_BaseControl (id_enabled, "id and disabled", l);