Another fix
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / AttributeCollectionTest.cs
1 //
2 // Tests for System.Web.UI.AttributeCollection.cs and CssStyleCollection
3 //
4 // Author:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.IO;
33 using System.Globalization;
34 using System.Web;
35 using System.Web.UI;
36 using System.Collections;
37 using AC = System.Web.UI.AttributeCollection;
38
39 namespace MonoTests.System.Web.UI {
40         [TestFixture]
41         public class AttributeCollectionTest {
42                 [Test]
43                 public void InitialNoBag1 ()
44                 {
45                         AC ac = new AC (null);
46                         Assert.IsNotNull (ac.CssStyle, "style");
47                 }
48
49                 [Test]
50                 [ExpectedException (typeof (NullReferenceException))]
51                 public void InitialNoBag2 ()
52                 {
53                         AC ac = new AC (null);
54                         int i = ac.Count;
55                 }
56
57                 [Test]
58                 [ExpectedException (typeof (NullReferenceException))]
59                 public void InitialNoBag3 ()
60                 {
61                         AC ac = new AC (null);
62                         ICollection coll = ac.Keys;
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (NullReferenceException))]
67                 public void InitialNoBag4 ()
68                 {
69                         AC ac = new AC (null);
70                         string k = ac ["hola"];
71                 }
72
73                 [Test]
74                 [ExpectedException (typeof (NullReferenceException))]
75                 public void InitialNoBag5 ()
76                 {
77                         AC ac = new AC (null);
78                         ac.Add ("att", "value");
79                 }
80
81                 [Test]
82                 [ExpectedException (typeof (NullReferenceException))]
83                 public void InitialNoBag6 ()
84                 {
85                         AC ac = new AC (null);
86                         ac.Clear ();
87                 }
88
89                 [Test]
90                 [ExpectedException (typeof (NullReferenceException))]
91                 public void InitialNoBag7 ()
92                 {
93                         AC ac = new AC (null);
94                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
95                         ac.AddAttributes (writer);
96                 }
97
98                 [Test]
99                 [ExpectedException (typeof (NullReferenceException))]
100                 public void InitialNoBag8 ()
101                 {
102                         AC ac = new AC (null);
103                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
104                         ac.Render (writer);
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (NullReferenceException))]
109                 public void InitialNoBag9 ()
110                 {
111                         AC ac = new AC (null);
112                         ac.Remove ("hola");
113                 }
114
115                 [Test]
116                 [Category("NotWorking")]
117                 public void InitialNoBag10()
118                 {
119                     AC ac = new AC(null);
120                     CssStyleCollection css = ac.CssStyle;
121                     int i = css.Count;
122                     Assert.AreEqual(0, i, "InitialNoBag10");
123                 }
124
125                 [Test]
126                 [Category("NotWorking")]
127                 public void InitialNoBag11()
128                 {
129                     AC ac = new AC(null);
130                     CssStyleCollection css = ac.CssStyle;
131                     ICollection coll = css.Keys;
132                     Assert.AreEqual(0, coll.Count, "InitialNoBag11");
133                 }
134
135                 [Test]
136                 [Category("NotWorking")]
137                 public void InitialNoBag12()
138                 {
139                     AC ac = new AC(null);
140                     CssStyleCollection css = ac.CssStyle;
141                     string v = css["hola"];
142                     Assert.AreEqual(null, v, "InitialNoBag12");
143                 }
144                         
145                 [Test]
146                 public void InitialBag1 ()
147                 {
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");
156
157                         HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
158                         ac.AddAttributes (writer);
159                         ac.Render (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");
169                         css.Clear ();
170                         Assert.AreEqual (0, css.Keys.Count, "csskeys2");
171                 }
172
173                 [Test]
174                 public void NonStyleAttributes1 ()
175                 {
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");
191                 }
192
193                 [Test]
194                 public void NonStyleAttributes2 ()
195                 {
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");
211                 }
212         }
213 }
214