[asp.net] Do nothing if null SessionStateStoreData is passed to SessionStateServerHan...
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.HtmlControls / HtmlImageTest.cs
1 //
2 // HtmlImageTest.cs
3 //      - Unit tests for System.Web.UI.HtmlControls.HtmlImage
4 //
5 // Author:
6 //      Dick Porter  <dick@ximian.com>
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 System;
31 using System.IO;
32 using System.Web.UI;
33 using System.Web.UI.HtmlControls;
34
35 using NUnit.Framework;
36 using MonoTests.SystemWeb.Framework;
37 using MonoTests.stand_alone.WebHarness; 
38
39 namespace MonoTests.System.Web.UI.HtmlControls {
40
41         public class TestHtmlImage : HtmlImage {
42
43                 public HtmlTextWriter GetWriter ()
44                 {
45                         StringWriter text = new StringWriter ();
46                         HtmlTextWriter writer = new HtmlTextWriter (text);
47                         base.RenderAttributes (writer);
48                         return writer;
49                 }
50         }
51
52         [TestFixture]
53         public class HtmlImageTest {
54
55                 [Test]
56                 public void DefaultProperties ()
57                 {
58                         HtmlImage img = new HtmlImage ();
59                         Assert.AreEqual (0, img.Attributes.Count, "Attributes.Count");
60
61                         Assert.AreEqual (String.Empty, img.Align, "Align");
62                         Assert.AreEqual (String.Empty, img.Alt, "Alt");
63                         Assert.AreEqual (-1, img.Border, "Border");
64                         Assert.AreEqual (-1, img.Height, "Height");
65                         Assert.AreEqual (String.Empty, img.Src, "Src");
66                         Assert.AreEqual (-1, img.Width, "Width");
67
68                         Assert.AreEqual ("img", img.TagName, "TagName");
69                 }
70
71                 [Test]
72                 public void NullProperties ()
73                 {
74                         HtmlImage img = new HtmlImage ();
75
76                         img.Align = null;
77                         Assert.AreEqual (String.Empty, img.Align, "Align");
78                         img.Alt = null;
79                         Assert.AreEqual (String.Empty, img.Alt, "Alt");
80                         img.Border = -1;
81                         Assert.AreEqual (-1, img.Border, "Border");
82                         img.Height = -1;
83                         Assert.AreEqual (-1, img.Height, "Height");
84                         img.Src = null;
85                         Assert.AreEqual (String.Empty, img.Src, "Src");
86                         img.Width = -1;
87                         Assert.AreEqual (-1, img.Width, "Width");
88
89                         Assert.AreEqual (0, img.Attributes.Count, "Attributes.Count");
90                 }
91
92                 [Test]
93                 public void Negative ()
94                 {
95                         HtmlImage img = new HtmlImage ();
96
97                         img.Border = 10;
98                         img.Height = 20;
99                         img.Width = 30;
100
101                         Assert.AreEqual (3, img.Attributes.Count, "First Attributes Count");
102
103                         img.Border = -10;
104                         img.Height = -20;
105                         img.Width = -30;
106
107                         Assert.AreEqual (-10, img.Border, "Border");
108                         Assert.AreEqual (-20, img.Height, "Height");
109                         Assert.AreEqual (-30, img.Width, "Width");
110
111                         Assert.AreEqual (3, img.Attributes.Count, "Second Attributes Count");
112                 }
113
114                 [Test]
115                 public void EmptySrc ()
116                 {
117                         TestHtmlImage img = new TestHtmlImage ();
118
119                         img.Src = String.Empty;
120
121                         HtmlTextWriter writer = img.GetWriter ();
122                         Assert.AreEqual (" /", writer.InnerWriter.ToString ());
123                 }
124
125                 [Test]
126                 [Category ("NunitWeb")]
127                 public void RenderAttributes ()
128                 {
129                         new WebTest (PageInvoker.CreateOnLoad (new PageDelegate (DoRenderAttributes))).Run ();
130                 }
131
132                 public static void DoRenderAttributes (Page p)
133                 {
134                         TestHtmlImage img = new TestHtmlImage ();
135
136                         img.Align = "*1*";
137                         img.Alt = "*2*";
138                         img.Border = 3;
139                         img.Height = 4;
140                         img.Src = "*5<&*";
141                         img.Width = 6;
142                         
143                         Assert.AreEqual (6, img.Attributes.Count, "Attributes.Count");
144
145                         HtmlTextWriter writer = img.GetWriter ();
146                         Assert.AreEqual (" src=\"*5<&*\" align=\"*1*\" alt=\"*2*\" border=\"3\" height=\"4\" width=\"6\" /", writer.InnerWriter.ToString ());
147                 }
148         }
149 }