| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- //
- // Tests for System.Web.UI.AttributeCollection.cs and CssStyleCollection
- //
- // Author:
- // Gonzalo Paniagua Javier ([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 NUnit.Framework;
- using System;
- using System.IO;
- using System.Globalization;
- using System.Web;
- using System.Web.UI;
- using System.Collections;
- using AC = System.Web.UI.AttributeCollection;
- namespace MonoTests.System.Web.UI {
- [TestFixture]
- public class AttributeCollectionTest {
- [Test]
- public void InitialNoBag1 ()
- {
- AC ac = new AC (null);
- Assert.IsNotNull (ac.CssStyle, "style");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag2 ()
- {
- AC ac = new AC (null);
- int i = ac.Count;
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag3 ()
- {
- AC ac = new AC (null);
- ICollection coll = ac.Keys;
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag4 ()
- {
- AC ac = new AC (null);
- string k = ac ["hola"];
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag5 ()
- {
- AC ac = new AC (null);
- ac.Add ("att", "value");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag6 ()
- {
- AC ac = new AC (null);
- ac.Clear ();
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag7 ()
- {
- AC ac = new AC (null);
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- ac.AddAttributes (writer);
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag8 ()
- {
- AC ac = new AC (null);
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- ac.Render (writer);
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag9 ()
- {
- AC ac = new AC (null);
- ac.Remove ("hola");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag10 ()
- {
- AC ac = new AC (null);
- CssStyleCollection css = ac.CssStyle;
- int i = css.Count;
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag11 ()
- {
- AC ac = new AC (null);
- CssStyleCollection css = ac.CssStyle;
- ICollection coll = css.Keys;
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void InitialNoBag12 ()
- {
- AC ac = new AC (null);
- CssStyleCollection css = ac.CssStyle;
- string v = css ["hola"];
- }
- [Test]
- public void InitialBag1 ()
- {
- StateBag bag = new StateBag (true);
- AC ac = new AC (bag);
- Assert.AreEqual (0, ac.Count, "count");
- Assert.AreEqual (null, ac ["hola"], "item");
- Assert.AreEqual (0, ac.Keys.Count, "keys");
- ac.Add ("notexists", "invalid");
- ac.Remove ("notexists");
- ac.Remove ("notexists");
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- ac.AddAttributes (writer);
- ac.Render (writer);
- Assert.AreEqual (0, writer.InnerWriter.ToString().Length, "length");
- CssStyleCollection css = ac.CssStyle;
- Assert.AreEqual (0, css.Count, "csscount");
- Assert.AreEqual (null, css ["hola"], "cssitem");
- Assert.AreEqual (0, css.Keys.Count, "csskeys");
- css.Add ("notexists", "invalid");
- css.Remove ("notexists");
- css.Remove ("notexists");
- css.Add ("notexists", "invalid");
- css.Clear ();
- Assert.AreEqual (0, css.Keys.Count, "csskeys2");
- }
- [Test]
- public void NonStyleAttributes1 ()
- {
- StateBag bag = new StateBag (true);
- AC ac = new AC (bag);
- StringWriter sr = new StringWriter ();
- HtmlTextWriter writer = new HtmlTextWriter (sr);
- ac.Add ("notexists", "somevalue");
- ac.AddAttributes (writer);
- string str = sr.ToString ();
- Assert.AreEqual ("", str, "value1");
- Assert.AreEqual (1, bag.Count, "count1");
- writer = new HtmlTextWriter (sr);
- writer.RenderBeginTag (HtmlTextWriterTag.A);
- ac.AddAttributes (writer);
- writer.RenderEndTag ();
- Assert.AreEqual ("", str, "value2");
- Assert.AreEqual (1, bag.Count, "count2");
- }
- [Test]
- public void NonStyleAttributes2 ()
- {
- StateBag bag = new StateBag (true);
- AC ac = new AC (bag);
- StringWriter sr = new StringWriter ();
- HtmlTextWriter writer = new HtmlTextWriter (sr);
- ac.Add ("class", "classname");
- ac.AddAttributes (writer);
- string str = sr.ToString ();
- Assert.AreEqual ("", str, "value1");
- Assert.AreEqual (1, bag.Count, "count1");
- writer = new HtmlTextWriter (sr);
- writer.RenderBeginTag (HtmlTextWriterTag.A);
- ac.AddAttributes (writer);
- writer.RenderEndTag ();
- Assert.AreEqual ("", str, "value2");
- Assert.AreEqual (1, bag.Count, "count2");
- }
- }
- }
|