2 // Tests for System.Web.UI.WebControls.ImageButton.cs
5 // Jordi Mas i Hernandez (jordi@ximian.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using NUnit.Framework;
34 using System.Globalization;
37 using System.Web.UI.WebControls;
39 namespace MonoTests.System.Web.UI.WebControls
41 class PokerImageButton : ImageButton {
42 public PokerImageButton ()
47 public object SaveState ()
49 return SaveViewState ();
52 public void LoadState (object o)
59 public class ImageButtonTest {
62 public void ImageButton_DefaultValues ()
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");
69 Assert.AreEqual (string.Empty, b.ValidationGroup, "ValidationGroup");
75 public void ImageButton_Render ()
77 StringWriter sw = new StringWriter ();
78 HtmlTextWriter tw = new HtmlTextWriter (sw);
80 ImageButton b = new ImageButton ();
83 Assert.AreEqual (true, sw.ToString().IndexOf ("<input") != -1, "A1");
84 Assert.AreEqual (true, sw.ToString().IndexOf ("type=\"image\"") != -1, "A2");
88 public void ImageButton_ViewState ()
90 PokerImageButton p = new PokerImageButton ();
92 p.CommandArgument = "arg";
93 Assert.AreEqual (p.CommandArgument, "arg", "A1");
94 p.CommandName = "cmd";
95 Assert.AreEqual (p.CommandName, "cmd", "A2");
97 p.ValidationGroup = "VG1";
98 Assert.AreEqual (p.ValidationGroup, "VG1", "A3");
101 object state = p.SaveState ();
103 PokerImageButton copy = new PokerImageButton ();
104 copy.LoadState (state);
106 Assert.AreEqual (copy.CommandArgument, "arg", "A4");
107 Assert.AreEqual (copy.CommandName, "cmd", "A5");
109 Assert.AreEqual (copy.ValidationGroup, "VG1", "A6");
115 public void RenderName ()
117 StringWriter sw = new StringWriter ();
118 HtmlTextWriter tw = new HtmlTextWriter (sw);
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");