2 // Tests for System.Web.UI.AttributeCollection.cs and CssStyleCollection
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
33 using System.Globalization;
36 using System.Collections;
37 using AC = System.Web.UI.AttributeCollection;
39 namespace MonoTests.System.Web.UI {
41 public class AttributeCollectionTest {
43 public void InitialNoBag1 ()
45 AC ac = new AC (null);
46 Assert.IsNotNull (ac.CssStyle, "style");
50 [ExpectedException (typeof (NullReferenceException))]
51 public void InitialNoBag2 ()
53 AC ac = new AC (null);
58 [ExpectedException (typeof (NullReferenceException))]
59 public void InitialNoBag3 ()
61 AC ac = new AC (null);
62 ICollection coll = ac.Keys;
66 [ExpectedException (typeof (NullReferenceException))]
67 public void InitialNoBag4 ()
69 AC ac = new AC (null);
70 string k = ac ["hola"];
74 [ExpectedException (typeof (NullReferenceException))]
75 public void InitialNoBag5 ()
77 AC ac = new AC (null);
78 ac.Add ("att", "value");
82 [ExpectedException (typeof (NullReferenceException))]
83 public void InitialNoBag6 ()
85 AC ac = new AC (null);
90 [ExpectedException (typeof (NullReferenceException))]
91 public void InitialNoBag7 ()
93 AC ac = new AC (null);
94 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
95 ac.AddAttributes (writer);
99 [ExpectedException (typeof (NullReferenceException))]
100 public void InitialNoBag8 ()
102 AC ac = new AC (null);
103 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
108 [ExpectedException (typeof (NullReferenceException))]
109 public void InitialNoBag9 ()
111 AC ac = new AC (null);
116 [Category("NotWorking")]
117 public void InitialNoBag10()
119 AC ac = new AC(null);
120 CssStyleCollection css = ac.CssStyle;
122 Assert.AreEqual(0, i, "InitialNoBag10");
126 [Category("NotWorking")]
127 public void InitialNoBag11()
129 AC ac = new AC(null);
130 CssStyleCollection css = ac.CssStyle;
131 ICollection coll = css.Keys;
132 Assert.AreEqual(0, coll.Count, "InitialNoBag11");
136 [Category("NotWorking")]
137 public void InitialNoBag12()
139 AC ac = new AC(null);
140 CssStyleCollection css = ac.CssStyle;
141 string v = css["hola"];
142 Assert.AreEqual(null, v, "InitialNoBag12");
146 public void InitialBag1 ()
148 StateBag bag = new StateBag (true);
149 AC ac = new AC (bag);
150 Assert.AreEqual (0, ac.Count, "count");
151 Assert.AreEqual (null, ac ["hola"], "item");
152 Assert.AreEqual (0, ac.Keys.Count, "keys");
153 ac.Add ("notexists", "invalid");
154 ac.Remove ("notexists");
155 ac.Remove ("notexists");
157 HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
158 ac.AddAttributes (writer);
160 Assert.AreEqual (0, writer.InnerWriter.ToString().Length, "length");
161 CssStyleCollection css = ac.CssStyle;
162 Assert.AreEqual (0, css.Count, "csscount");
163 Assert.AreEqual (null, css ["hola"], "cssitem");
164 Assert.AreEqual (0, css.Keys.Count, "csskeys");
165 css.Add ("notexists", "invalid");
166 css.Remove ("notexists");
167 css.Remove ("notexists");
168 css.Add ("notexists", "invalid");
170 Assert.AreEqual (0, css.Keys.Count, "csskeys2");
174 public void NonStyleAttributes1 ()
176 StateBag bag = new StateBag (true);
177 AC ac = new AC (bag);
178 StringWriter sr = new StringWriter ();
179 HtmlTextWriter writer = new HtmlTextWriter (sr);
180 ac.Add ("notexists", "somevalue");
181 ac.AddAttributes (writer);
182 string str = sr.ToString ();
183 Assert.AreEqual ("", str, "value1");
184 Assert.AreEqual (1, bag.Count, "count1");
185 writer = new HtmlTextWriter (sr);
186 writer.RenderBeginTag (HtmlTextWriterTag.A);
187 ac.AddAttributes (writer);
188 writer.RenderEndTag ();
189 Assert.AreEqual ("", str, "value2");
190 Assert.AreEqual (1, bag.Count, "count2");
194 public void NonStyleAttributes2 ()
196 StateBag bag = new StateBag (true);
197 AC ac = new AC (bag);
198 StringWriter sr = new StringWriter ();
199 HtmlTextWriter writer = new HtmlTextWriter (sr);
200 ac.Add ("class", "classname");
201 ac.AddAttributes (writer);
202 string str = sr.ToString ();
203 Assert.AreEqual ("", str, "value1");
204 Assert.AreEqual (1, bag.Count, "count1");
205 writer = new HtmlTextWriter (sr);
206 writer.RenderBeginTag (HtmlTextWriterTag.A);
207 ac.AddAttributes (writer);
208 writer.RenderEndTag ();
209 Assert.AreEqual ("", str, "value2");
210 Assert.AreEqual (1, bag.Count, "count2");