| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- //
- // TableStyleTest.cs
- // - Unit tests for System.Web.UI.WebControls.TableStyle
- //
- // 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;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using NUnit.Framework;
- namespace MonoTests.System.Web.UI.WebControls {
- public class TestTableStyle : TableStyle {
- public TestTableStyle ()
- : base ()
- {
- }
- public TestTableStyle (StateBag bag)
- : base (bag)
- {
- }
- public bool Empty {
- get { return base.IsEmpty; }
- }
- public StateBag StateBag {
- get { return base.ViewState; }
- }
- #if NET_2_0
- public void Fill (CssStyleCollection attributes, IUrlResolutionService urlResolver)
- {
- base.FillStyleAttributes (attributes, urlResolver);
- }
- #endif
- }
- #if NET_2_0
- public class TestResolutionService : IUrlResolutionService {
- public string ResolveClientUrl (string relativeUrl)
- {
- return "http://www.mono-project.com";
- }
- }
- #endif
- [TestFixture]
- public class TableStyleTest {
- private const string imageUrl = "http://www.mono-project.com/stylesheets/images.wiki.png";
- private void DefaultProperties (TestTableStyle ts)
- {
- Assert.AreEqual (0, ts.StateBag.Count, "ViewState.Count");
- Assert.AreEqual (String.Empty, ts.BackImageUrl, "BackImageUrl");
- Assert.AreEqual (-1, ts.CellPadding, "CellPadding");
- Assert.AreEqual (-1, ts.CellSpacing, "CellSpacing");
- // LAMESPEC: default is document to be GridLines.Both
- Assert.AreEqual (GridLines.None, ts.GridLines, "GridLines");
- Assert.AreEqual (HorizontalAlign.NotSet, ts.HorizontalAlign, "HorizontalAlign");
- Assert.AreEqual (0, ts.StateBag.Count, "ViewState.Count-2");
- ts.Reset ();
- Assert.AreEqual (0, ts.StateBag.Count, "Reset");
- }
- private void NullProperties (TestTableStyle ts)
- {
- Assert.IsTrue (ts.Empty, "Empty");
- ts.BackImageUrl = String.Empty; // doesn't accept null, see specific test
- Assert.AreEqual (String.Empty, ts.BackImageUrl, "BackImageUrl");
- Assert.IsFalse (ts.Empty, "!Empty");
- ts.CellPadding = -1;
- Assert.AreEqual (-1, ts.CellPadding, "CellPadding");
- ts.CellSpacing = -1;
- Assert.AreEqual (-1, ts.CellSpacing, "CellSpacing");
- ts.GridLines = GridLines.None;
- Assert.AreEqual (GridLines.None, ts.GridLines, "GridLines");
- ts.HorizontalAlign = HorizontalAlign.NotSet;
- Assert.AreEqual (HorizontalAlign.NotSet, ts.HorizontalAlign, "HorizontalAlign");
- Assert.AreEqual (5, ts.StateBag.Count, "ViewState.Count-1");
- ts.Reset ();
- Assert.AreEqual (0, ts.StateBag.Count, "Reset");
- Assert.IsTrue (ts.Empty, "Empty/Reset");
- }
- [Test]
- public void Constructor_Default ()
- {
- TestTableStyle ts = new TestTableStyle ();
- DefaultProperties (ts);
- NullProperties (ts);
- }
- [Test]
- public void Constructor_StateBag_Null ()
- {
- TestTableStyle ts = new TestTableStyle (null);
- Assert.IsNotNull (ts.StateBag, "StateBag");
- DefaultProperties (ts);
- NullProperties (ts);
- }
- [Test]
- public void Constructor_StateBag ()
- {
- TestTableStyle ts = new TestTableStyle (new StateBag ());
- Assert.IsNotNull (ts.StateBag, "StateBag");
- DefaultProperties (ts);
- NullProperties (ts);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void BackImageUrl_Null ()
- {
- TableStyle ts = new TableStyle ();
- ts.BackImageUrl = null;
- }
- [Test]
- [ExpectedException (typeof (ArgumentOutOfRangeException))]
- public void CellPadding_Invalid ()
- {
- TableStyle ts = new TableStyle ();
- ts.CellPadding = Int32.MinValue;
- }
- [Test]
- [ExpectedException (typeof (ArgumentOutOfRangeException))]
- public void CellSpacing_Invalid ()
- {
- TableStyle ts = new TableStyle ();
- ts.CellSpacing = Int32.MinValue;
- }
- [Test]
- // LAMESPEC: documented as ArgumentException
- [ExpectedException (typeof (ArgumentOutOfRangeException))]
- public void GridLines_Invalid ()
- {
- TableStyle ts = new TableStyle ();
- ts.GridLines = (GridLines)Int32.MinValue;
- }
- [Test]
- // LAMESPEC: documented as ArgumentException
- [ExpectedException (typeof (ArgumentOutOfRangeException))]
- public void HorizontalAlign_Invalid ()
- {
- TableStyle ts = new TableStyle ();
- ts.HorizontalAlign = (HorizontalAlign)Int32.MinValue;
- }
- [Test]
- public void AddAttributesToRender_Null_WebControl ()
- {
- TableStyle ts = new TableStyle ();
- ts.AddAttributesToRender (null, new Table ());
- // no exception
- }
- [Test]
- public void AddAttributesToRender_HtmlTextWriter_Null ()
- {
- TableStyle ts = GetTableStyle ();
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- ts.AddAttributesToRender (writer, null);
- Assert.AreEqual (String.Empty, writer.InnerWriter.ToString (), "empty");
- }
- [Test]
- public void AddAttributesToRender ()
- {
- TableStyle ts = GetTableStyle ();
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- ts.AddAttributesToRender (writer, new Table ());
- Assert.AreEqual (String.Empty, writer.InnerWriter.ToString (), "empty");
- }
- private TableStyle GetTableStyle ()
- {
- TableStyle ts = new TableStyle ();
- ts.BackImageUrl = imageUrl;
- ts.CellPadding = 1;
- ts.CellSpacing = 2;
- ts.GridLines = GridLines.Both;
- ts.HorizontalAlign = HorizontalAlign.Justify;
- return ts;
- }
- private void CheckTableStyle (TableStyle ts)
- {
- Assert.AreEqual (imageUrl, ts.BackImageUrl, "BackImageUrl");
- Assert.AreEqual (1, ts.CellPadding, "CellPadding");
- Assert.AreEqual (2, ts.CellSpacing, "CellSpacing");
- Assert.AreEqual (GridLines.Both, ts.GridLines, "GridLines");
- Assert.AreEqual (HorizontalAlign.Justify, ts.HorizontalAlign, "HorizontalAlign");
- }
- [Test]
- public void CopyFrom_Null ()
- {
- TableStyle ts = GetTableStyle ();
- ts.CopyFrom (null);
- CheckTableStyle (ts);
- }
- [Test]
- public void CopyFrom_Self ()
- {
- TableStyle ts = GetTableStyle ();
- ts.CopyFrom (ts);
- CheckTableStyle (ts);
- }
- [Test]
- public void CopyFrom_Empty ()
- {
- TestTableStyle ts = new TestTableStyle ();
- ts.CopyFrom (new TableStyle ());
- DefaultProperties (ts);
- }
- [Test]
- public void CopyFrom_IsEmpty ()
- {
- TestTableStyle c = new TestTableStyle ();
- TableStyle s = new TableStyle ();
-
- s.BorderWidth = Unit.Empty;
- c.CopyFrom (s);
- Assert.IsTrue (c.Empty, "A1");
-
- s.GridLines = GridLines.Both;
- c.CopyFrom (s);
- Assert.IsFalse (c.Empty, "A2");
- }
- [Test]
- public void CopyFrom ()
- {
- TableStyle ts = new TableStyle ();
- ts.BackImageUrl = imageUrl + "1";
- ts.CellPadding = 2;
- ts.CellSpacing = 3;
- ts.GridLines = GridLines.Horizontal;
- ts.HorizontalAlign = HorizontalAlign.Left;
- ts.CopyFrom (GetTableStyle ());
- CheckTableStyle (ts);
- }
- [Test]
- public void MergeWith_Null ()
- {
- TableStyle ts = GetTableStyle ();
- ts.MergeWith (null);
- CheckTableStyle (ts);
- }
- [Test]
- public void MergeWith_Self ()
- {
- TableStyle ts = GetTableStyle ();
- ts.MergeWith (ts);
- CheckTableStyle (ts);
- }
- [Test]
- public void MergeWith_Empty ()
- {
- TestTableStyle ts = new TestTableStyle ();
- ts.MergeWith (new TableStyle ());
- DefaultProperties (ts);
- }
- [Test]
- public void MergeWith ()
- {
- TableStyle ts = new TableStyle ();
- ts.BackImageUrl = imageUrl + "1";
- ts.CellPadding = 2;
- ts.CellSpacing = 3;
- ts.GridLines = GridLines.Horizontal;
- ts.HorizontalAlign = HorizontalAlign.Left;
- ts.MergeWith (GetTableStyle ());
- Assert.AreEqual (imageUrl + "1", ts.BackImageUrl, "BackImageUrl");
- Assert.AreEqual (2, ts.CellPadding, "CellPadding");
- Assert.AreEqual (3, ts.CellSpacing, "CellSpacing");
- Assert.AreEqual (GridLines.Horizontal, ts.GridLines, "GridLines");
- Assert.AreEqual (HorizontalAlign.Left, ts.HorizontalAlign, "HorizontalAlign");
- }
- #if NET_2_0
- private CssStyleCollection GetCssCollection ()
- {
- return new AttributeCollection (new StateBag ()).CssStyle;
- }
- [Test]
- public void FillStyleAttributes_Null_Resolver ()
- {
- TestTableStyle ts = new TestTableStyle ();
- ts.Fill (null, new TestResolutionService ());
- // no exception
- }
- [Test]
- public void FillStyleAttributes_Css_Null ()
- {
- TestTableStyle ts = new TestTableStyle ();
- ts.Fill (GetCssCollection (), null);
- // no exception
- }
- [Test]
- public void FillStyleAttributes_Empty ()
- {
- CssStyleCollection css = GetCssCollection ();
- TestTableStyle ts = new TestTableStyle ();
- ts.Fill (css, new TestResolutionService ());
- Assert.AreEqual (0, css.Count, "Count");
- }
- [Test]
- public void FillStyleAttributes_NotCss ()
- {
- CssStyleCollection css = GetCssCollection ();
- TestTableStyle ts = new TestTableStyle ();
- ts.CellPadding = 1;
- ts.CellSpacing = 1;
- ts.GridLines = GridLines.Both;
- ts.HorizontalAlign = HorizontalAlign.Justify;
- ts.Fill (css, new TestResolutionService ());
- Assert.AreEqual (0, css.Count, "Count");
- }
- [Test]
- public void FillStyleAttributes_Css_WithoutResolution ()
- {
- CssStyleCollection css = GetCssCollection ();
- TestTableStyle ts = new TestTableStyle ();
- ts.BackImageUrl = "http://www.go-mono.com";
- ts.Fill (css, null);
- Assert.AreEqual (1, css.Count, "Count");
- Assert.AreEqual ("http://www.go-mono.com", css["background-image"], "css[string]");
- Assert.AreEqual ("http://www.go-mono.com", css[HtmlTextWriterStyle.BackgroundImage], "css[HtmlTextWriterStyle]");
- Assert.AreEqual ("background-image:url(http://www.go-mono.com);", css.Value, "css.Value");
- }
- [Test]
- public void FillStyleAttributes_Css_WithResolution ()
- {
- CssStyleCollection css = GetCssCollection ();
- TestTableStyle ts = new TestTableStyle ();
- ts.BackImageUrl = "http://www.go-mono.com";
- ts.Fill (css, new TestResolutionService ());
- Assert.AreEqual (1, css.Count, "Count");
- Assert.AreEqual ("http://www.mono-project.com", css["background-image"], "css[string]");
- Assert.AreEqual ("http://www.mono-project.com", css[HtmlTextWriterStyle.BackgroundImage], "css[HtmlTextWriterStyle]");
- Assert.AreEqual ("background-image:url(http://www.mono-project.com);", css.Value, "css.Value");
- Assert.AreEqual ("http://www.go-mono.com", ts.BackImageUrl, "BackImageUrl");
- }
- #endif
- }
- }
|