| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- //
- // HtmlTableTest.cs
- // - Unit tests for System.Web.UI.HtmlControls.HtmlTable
- //
- // Author:
- // Sebastien Pouliot <[email protected]>
- //
- // 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.IO;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using NUnit.Framework;
- namespace MonoTests.System.Web.UI.HtmlControls {
- public class TestHtmlTable : HtmlTable {
- public string Render ()
- {
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- base.Render (writer);
- return writer.InnerWriter.ToString ();
- }
- public ControlCollection GetCollection ()
- {
- return base.CreateControlCollection ();
- }
- }
- public class InheritedHtmlTableRow : HtmlTableRow {
- }
- [TestFixture]
- public class HtmlTableTest {
- [Test]
- public void DefaultProperties ()
- {
- HtmlTable t = new HtmlTable ();
- Assert.AreEqual (0, t.Attributes.Count, "Attributes.Count");
- Assert.AreEqual (String.Empty, t.Align, "Align");
- Assert.AreEqual (String.Empty, t.BgColor, "BgColor");
- Assert.AreEqual (-1, t.Border, "Border");
- Assert.AreEqual (String.Empty, t.BorderColor, "BorderColor");
- Assert.AreEqual (-1, t.CellPadding, "CellPadding");
- Assert.AreEqual (-1, t.CellSpacing, "CellSpacing");
- Assert.AreEqual (String.Empty, t.Height, "Height");
- Assert.AreEqual (0, t.Rows.Count, "Rows");
- Assert.AreEqual (String.Empty, t.Width, "Width");
- Assert.AreEqual ("table", t.TagName, "TagName");
- }
- [Test]
- public void NullProperties ()
- {
- HtmlTable t = new HtmlTable ();
- t.Align = null;
- Assert.AreEqual (String.Empty, t.Align, "Align");
- t.BgColor = null;
- Assert.AreEqual (String.Empty, t.BgColor, "BgColor");
- t.BorderColor = null;
- Assert.AreEqual (String.Empty, t.BorderColor, "BorderColor");
- t.Height = null;
- Assert.AreEqual (String.Empty, t.Height, "Height");
- t.Width = null;
- Assert.AreEqual (String.Empty, t.Width, "Width");
- Assert.AreEqual (0, t.Attributes.Count, "Attributes.Count");
- }
- [Test]
- public void EmptyProperties ()
- {
- HtmlTable t = new HtmlTable ();
- t.Border = -1;
- Assert.AreEqual (-1, t.Border, "Border");
- t.CellPadding = -1;
- Assert.AreEqual (-1, t.CellPadding, "CellPadding");
- t.CellSpacing = -1;
- Assert.AreEqual (-1, t.CellSpacing, "CellSpacing");
- Assert.AreEqual (0, t.Attributes.Count, "Attributes.Count");
- }
- [Test]
- public void CleanProperties ()
- {
- HtmlTable t = new HtmlTable ();
- t.Align = "center";
- Assert.AreEqual ("center", t.Align, "Align");
- t.Border = 1;
- Assert.AreEqual (1, t.Border, "Border");
- Assert.AreEqual (2, t.Attributes.Count, "2");
- t.Border = -1;
- Assert.AreEqual (-1, t.Border, "-Border");
- t.Align = null;
- Assert.AreEqual (String.Empty, t.Align, "-Align");
- Assert.AreEqual (0, t.Attributes.Count, "0");
- }
- [Test]
- public void MaxInt32 ()
- {
- HtmlTable t = new HtmlTable ();
- t.Border = Int32.MaxValue;
- Assert.AreEqual (Int32.MaxValue, t.Border, "Border");
- t.CellPadding = Int32.MaxValue;
- Assert.AreEqual (Int32.MaxValue, t.CellPadding, "CellPadding");
- t.CellSpacing = Int32.MaxValue;
- Assert.AreEqual (Int32.MaxValue, t.CellSpacing, "CellSpacing");
- Assert.AreEqual (3, t.Attributes.Count, "Attributes.Count");
- }
- [Test]
- public void MinInt32 ()
- {
- HtmlTable t = new HtmlTable ();
- t.Border = Int32.MinValue;
- Assert.AreEqual (Int32.MinValue, t.Border, "Border");
- t.CellPadding = Int32.MinValue;
- Assert.AreEqual (Int32.MinValue, t.CellPadding, "CellPadding");
- t.CellSpacing = Int32.MinValue;
- Assert.AreEqual (Int32.MinValue, t.CellSpacing, "CellSpacing");
- Assert.AreEqual (3, t.Attributes.Count, "Attributes.Count");
- }
- [Test]
- [ExpectedException (typeof (FormatException))]
- public void WrongTypeString ()
- {
- HtmlTable t = new HtmlTable ();
- t.Attributes.Add ("Border", "yes");
- Assert.AreEqual (-1, t.Border, "Border");
- }
- [Test]
- public void WrongTypeInt ()
- {
- HtmlTable t = new HtmlTable ();
- t.Border = 42;
- Assert.AreEqual ("42", t.Attributes ["border"], "Border");
- }
- [Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void InnerHtml_Get ()
- {
- HtmlTable t = new HtmlTable ();
- Assert.IsNotNull (t.InnerHtml);
- }
- [Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void InnerHtml_Set ()
- {
- HtmlTable t = new HtmlTable ();
- t.InnerHtml = String.Empty;
- }
- [Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void InnerText_Get ()
- {
- HtmlTable t = new HtmlTable ();
- Assert.IsNotNull (t.InnerText);
- }
- [Test]
- [ExpectedException (typeof (NotSupportedException))]
- public void InnerText_Set ()
- {
- HtmlTable t = new HtmlTable ();
- t.InnerText = String.Empty;
- }
- private string AdjustLineEndings (string s)
- {
- return s.Replace ("\r\n", Environment.NewLine);
- }
- [Test]
- public void Render_Table_Simple ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- Assert.AreEqual (AdjustLineEndings ("<table>\r\n</table>\r\n"), t.Render ());
- }
- [Test]
- public void Render_Table ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- t.Align = "*1*";
- t.BgColor = "*2*";
- t.Border = 3;
- t.BorderColor = "*4*";
- t.CellPadding = 5;
- t.CellSpacing = 6;
- t.Height = "*7*";
- t.Width = "*8*";
- Assert.AreEqual (AdjustLineEndings ("<table align=\"*1*\" bgcolor=\"*2*\" border=\"3\" bordercolor=\"*4*\" cellpadding=\"5\" cellspacing=\"6\" height=\"*7*\" width=\"*8*\">\r\n</table>\r\n"), t.Render ());
- }
- [Test]
- public void Render_TableRow_Simple ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- t.Rows.Add (new HtmlTableRow ());
- Assert.AreEqual (AdjustLineEndings ("<table>\r\n\t<tr>\r\n\t</tr>\r\n</table>\r\n"), t.Render ());
- }
- [Test]
- public void Render_TableRow ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- t.Border = 0;
- HtmlTableRow r1 = new HtmlTableRow ();
- r1.Align = "right";
- t.Rows.Add (r1);
- HtmlTableRow r2 = new HtmlTableRow ();
- r2.Align = "left";
- t.Rows.Add (r2);
- Assert.AreEqual (AdjustLineEndings ("<table border=\"0\">\r\n\t<tr align=\"right\">\r\n\t</tr>\r\n\t<tr align=\"left\">\r\n\t</tr>\r\n</table>\r\n"), t.Render ());
- }
- [Test]
- public void Render_TableRowCell_Simple ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- HtmlTableRow r = new HtmlTableRow ();
- r.Cells.Add (new HtmlTableCell ());
- t.Rows.Add (r);
- Assert.AreEqual (AdjustLineEndings ("<table>\r\n\t<tr>\r\n\t\t<td></td>\r\n\t</tr>\r\n</table>\r\n"), t.Render ());
- }
- [Test]
- public void Render_TableRowCell ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- t.Align = "center";
- HtmlTableRow r = new HtmlTableRow ();
- r.VAlign = "top";
- t.Rows.Add (r);
- HtmlTableCell c1 = new HtmlTableCell ();
- c1.Align = "right";
- c1.InnerText = "Go";
- r.Cells.Add (c1);
- HtmlTableCell c2 = new HtmlTableCell ();
- c2.Align = "left";
- c2.InnerHtml = "<a href=\"http://www.go-mono.com\">Mono</a>";
- r.Cells.Add (c2);
- Assert.AreEqual (AdjustLineEndings ("<table align=\"center\">\r\n\t<tr valign=\"top\">\r\n\t\t<td align=\"right\">Go</td>\r\n\t\t<td align=\"left\"><a href=\"http://www.go-mono.com\">Mono</a></td>\r\n\t</tr>\r\n</table>\r\n"), t.Render ());
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void HtmlTableRowControlCollectionAdd_Null ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- ControlCollection c = t.GetCollection ();
- c.Add (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void HtmlTableRowControlCollectionAdd_WrongType ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- ControlCollection c = t.GetCollection ();
- c.Add (new HtmlTable ());
- }
- [Test]
- public void HtmlTableRowControlCollectionAdd ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- ControlCollection c = t.GetCollection ();
- c.Add (new HtmlTableRow ());
- c.Add (new InheritedHtmlTableRow ());
- Assert.AreEqual (2, c.Count, "Rows");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void HtmlTableRowControlCollectionAddAt_Null ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- ControlCollection c = t.GetCollection ();
- c.AddAt (0, null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void HtmlTableRowControlCollectionAddAt_WrongType ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- ControlCollection c = t.GetCollection ();
- c.AddAt (0, new HtmlTable ());
- }
- [Test]
- public void HtmlTableRowControlCollectionAddAt ()
- {
- TestHtmlTable t = new TestHtmlTable ();
- ControlCollection c = t.GetCollection ();
- c.AddAt (0, new HtmlTableRow ());
- c.AddAt (0, new InheritedHtmlTableRow ());
- Assert.AreEqual (2, c.Count, "Rows");
- }
- }
- }
|