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 ();
111 public void DefaultValues ()
113 RepeatInfo ri = new RepeatInfo ();
114 Assert.AreEqual (0, ri.RepeatColumns, "RepeatColumns");
115 Assert.AreEqual (RepeatDirection.Vertical, ri.RepeatDirection, "RepeatDirection");
116 Assert.AreEqual (RepeatLayout.Table, ri.RepeatLayout, "RepeatLayout");
117 Assert.IsFalse (ri.OuterTableImplied, "OuterTableImplied");
121 public void RepeatColumns_Negative ()
123 RepeatInfo ri = new RepeatInfo ();
124 ri.RepeatColumns = -1;
125 Assert.AreEqual (-1, ri.RepeatColumns, "-1");
126 ri.RepeatColumns = Int32.MinValue;
127 Assert.AreEqual (Int32.MinValue, ri.RepeatColumns, "Int32.MinValue");
131 [ExpectedException (typeof (ArgumentOutOfRangeException))]
132 public void RepeatDirection_Invalid ()
134 RepeatInfo ri = new RepeatInfo ();
135 ri.RepeatDirection = (RepeatDirection) Int32.MinValue;
139 [ExpectedException (typeof (ArgumentOutOfRangeException))]
140 public void RepeatLayout_Invalid ()
142 RepeatInfo ri = new RepeatInfo ();
143 ri.RepeatLayout = (RepeatLayout) Int32.MinValue;
146 private void RenderRepeater_BaseControl (string s, string msg, WebControl wc)
148 RepeatInfo ri = new RepeatInfo ();
149 ri.RepeatColumns = 3;
150 ri.RepeatDirection = RepeatDirection.Vertical;
151 ri.RepeatLayout = RepeatLayout.Table;
153 HtmlTextWriter writer = GetWriter ();
154 ri.RenderRepeater (writer, new RepeatInfoUser (false, false, false, 1), new TableStyle (), wc);
155 Assert.AreEqual (s, writer.InnerWriter.ToString (), msg);
159 [ExpectedException (typeof (NullReferenceException))]
160 public void RenderRepeater_BaseControl_Null ()
162 RenderRepeater_BaseControl ("shouldn't get here", "null", null);
168 public void RenderRepeater_BaseControl ()
171 string noid = "<table border=\"0\">\n\t<tr>\n\t\t<td>0</td><td></td><td></td>\n\t</tr>\n</table>";
172 string id_enabled = "<table id=\"foo\" disabled=\"disabled\" border=\"0\">\n\t<tr>\n\t\t<td>0</td><td></td><td></td>\n\t</tr>\n</table>";
174 string noid = "<table border=\"0\">\n\t<tr>\n\t\t<td>0</td>\n\t</tr>\n</table>";
175 string id_enabled = "<table id=\"foo\" disabled=\"disabled\" border=\"0\">\n\t<tr>\n\t\t<td>0</td>\n\t</tr>\n</table>";
177 RenderRepeater_BaseControl (noid, "Table", new Table ());
178 RenderRepeater_BaseControl (noid, "DataList", new DataList ());
179 RenderRepeater_BaseControl (noid, "DataListItem", new DataListItem (0, ListItemType.Item));
181 Label l = new Label ();
185 RenderRepeater_BaseControl (id_enabled, "id and disabled", l);