2005-10-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / ImageButtonTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.ImageButton.cs
3 //
4 // Author:
5 //      Jordi Mas i Hernandez (jordi@ximian.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.IO;
34 using System.Globalization;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38
39 namespace MonoTests.System.Web.UI.WebControls
40 {
41         class PokerImageButton : ImageButton {
42                 public PokerImageButton ()
43                 {
44                         TrackViewState ();
45                 }
46
47                 public object SaveState ()
48                 {
49                         return SaveViewState ();
50                 }
51
52                 public void LoadState (object o)
53                 {
54                         LoadViewState (o);
55                 }
56         }
57
58         [TestFixture]
59         public class ImageButtonTest {
60                 
61                 [Test]
62                 public void ImageButton_DefaultValues ()
63                 {
64                         ImageButton b = new ImageButton ();
65                         Assert.AreEqual (true, b.CausesValidation, "CausesValidation");
66                         Assert.AreEqual (string.Empty, b.CommandArgument, "CommandArgument");
67                         Assert.AreEqual (string.Empty, b.CommandName, "CommandName");
68 #if NET_2_0
69                         Assert.AreEqual (string.Empty, b.ValidationGroup, "ValidationGroup");
70 #endif
71                 }
72
73                 
74                 [Test]
75                 public void ImageButton_Render ()
76                 {
77                         StringWriter sw = new StringWriter ();
78                         HtmlTextWriter tw = new HtmlTextWriter (sw);
79
80                         ImageButton b = new ImageButton ();                     
81                         b.RenderControl (tw);                           
82                         
83                         Assert.AreEqual (true, sw.ToString().IndexOf ("<input") != -1, "A1");
84                         Assert.AreEqual (true, sw.ToString().IndexOf ("type=\"image\"") != -1, "A2");
85                 }
86
87                 [Test]
88                 public void ImageButton_ViewState ()
89                 {
90                         PokerImageButton p = new PokerImageButton ();
91
92                         p.CommandArgument = "arg";
93                         Assert.AreEqual (p.CommandArgument, "arg", "A1");
94                         p.CommandName = "cmd";
95                         Assert.AreEqual (p.CommandName, "cmd", "A2");
96 #if NET_2_0
97                         p.ValidationGroup = "VG1";
98                         Assert.AreEqual (p.ValidationGroup, "VG1", "A3");
99 #endif
100
101                         object state = p.SaveState ();
102
103                         PokerImageButton copy = new PokerImageButton ();
104                         copy.LoadState (state);
105
106                         Assert.AreEqual (copy.CommandArgument, "arg", "A4");
107                         Assert.AreEqual (copy.CommandName, "cmd", "A5");
108 #if NET_2_0
109                         Assert.AreEqual (copy.ValidationGroup, "VG1", "A6");
110 #endif
111
112                 }
113
114                 [Test]
115                 public void RenderName ()
116                 {
117                         StringWriter sw = new StringWriter ();
118                         HtmlTextWriter tw = new HtmlTextWriter (sw);
119
120                         Page page = new Page ();
121                         ImageButton b = new ImageButton ();                     
122                         page.Controls.Add (b);
123                         page.RenderControl (tw);
124                         Assert.AreEqual (true, sw.ToString().IndexOf ("<input") != -1, "A1");
125                         Assert.AreEqual (true, sw.ToString().IndexOf ("type=\"image\"") != -1, "A2");
126                         Assert.AreEqual (true, sw.ToString().IndexOf ("name=\"") != -1, "A3");
127                 }
128
129         }
130 }
131
132