1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
//
// RepeatInfoTest.cs - Unit tests for System.Web.UI.WebControls.RepeatInfo
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUnit.Framework;
namespace MonoTests.System.Web.UI.WebControls {
public class RepeatInfoUser : IRepeatInfoUser {
private bool footer;
private bool header;
private bool separators;
private int count;
private int counter;
public RepeatInfoUser (bool footer, bool header, bool separators, int count)
{
counter = 0;
this.footer = footer;
this.header = header;
this.separators = separators;
this.count = count;
}
public bool HasFooter {
get { return footer; }
}
public bool HasHeader {
get { return header; }
}
public bool HasSeparators {
get { return separators; }
}
public int RepeatedItemCount {
get { return count; }
}
public Style GetItemStyle (ListItemType itemType, int repeatIndex)
{
return null;
}
public void RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
writer.Write ((counter++).ToString ());
}
}
[TestFixture]
public class RepeatInfoTest {
private HtmlTextWriter GetWriter ()
{
StringWriter sw = new StringWriter ();
sw.NewLine = "\n";
return new HtmlTextWriter (sw);
}
string DoTest (int cols, int cnt, RepeatDirection d, RepeatLayout l, bool OuterTableImplied, bool ftr, bool hdr, bool sep)
{
HtmlTextWriter htw = GetWriter ();
RepeatInfo ri = new RepeatInfo ();
ri.RepeatColumns = cols;
ri.RepeatDirection = d;
ri.RepeatLayout = l;
ri.OuterTableImplied = OuterTableImplied;
ri.RenderRepeater (htw, new RepeatInfoUser (ftr, hdr, sep, cnt), new TableStyle (), new DataList ());
return htw.InnerWriter.ToString ();
}
[Test]
public void DefaultValues ()
{
RepeatInfo ri = new RepeatInfo ();
Assert.AreEqual (0, ri.RepeatColumns, "RepeatColumns");
Assert.AreEqual (RepeatDirection.Vertical, ri.RepeatDirection, "RepeatDirection");
Assert.AreEqual (RepeatLayout.Table, ri.RepeatLayout, "RepeatLayout");
Assert.IsFalse (ri.OuterTableImplied, "OuterTableImplied");
}
[Test]
public void RepeatColumns_Negative ()
{
RepeatInfo ri = new RepeatInfo ();
ri.RepeatColumns = -1;
Assert.AreEqual (-1, ri.RepeatColumns, "-1");
ri.RepeatColumns = Int32.MinValue;
Assert.AreEqual (Int32.MinValue, ri.RepeatColumns, "Int32.MinValue");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void RepeatDirection_Invalid ()
{
RepeatInfo ri = new RepeatInfo ();
ri.RepeatDirection = (RepeatDirection) Int32.MinValue;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void RepeatLayout_Invalid ()
{
RepeatInfo ri = new RepeatInfo ();
ri.RepeatLayout = (RepeatLayout) Int32.MinValue;
}
private void RenderRepeater_BaseControl (string s, string msg, WebControl wc)
{
RepeatInfo ri = new RepeatInfo ();
ri.RepeatColumns = 3;
ri.RepeatDirection = RepeatDirection.Vertical;
ri.RepeatLayout = RepeatLayout.Table;
HtmlTextWriter writer = GetWriter ();
ri.RenderRepeater (writer, new RepeatInfoUser (false, false, false, 1), new TableStyle (), wc);
Assert.AreEqual (s, writer.InnerWriter.ToString (), msg);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void RenderRepeater_BaseControl_Null ()
{
RenderRepeater_BaseControl ("shouldn't get here", "null", null);
}
[Test]
public void RenderRepeater_BaseControl ()
{
#if NET_2_0
string noid = "<table border=\"0\">\n\t<tr>\n\t\t<td>0</td><td></td><td></td>\n\t</tr>\n</table>";
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>";
#else
string noid = "<table border=\"0\">\n\t<tr>\n\t\t<td>0</td>\n\t</tr>\n</table>";
string id_enabled = "<table id=\"foo\" disabled=\"disabled\" border=\"0\">\n\t<tr>\n\t\t<td>0</td>\n\t</tr>\n</table>";
#endif
RenderRepeater_BaseControl (noid, "Table", new Table ());
RenderRepeater_BaseControl (noid, "DataList", new DataList ());
RenderRepeater_BaseControl (noid, "DataListItem", new DataListItem (0, ListItemType.Item));
Label l = new Label ();
l.Enabled = false;
l.ID = "foo";
RenderRepeater_BaseControl (id_enabled, "id and disabled", l);
}
}
}
|