2 // Tests for System.Web.UI.WebControls.View.cs
5 // Yoni Klein (yonik@mainsoft.com)
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
35 using System.Globalization;
38 using System.Web.UI.WebControls;
40 namespace MonoTests.System.Web.UI.WebControls
43 class PokerView : View
50 public object SaveState ()
52 return SaveViewState ();
55 public void LoadState (object o)
60 public StateBag StateBag
62 get { return base.ViewState; }
65 public string Render ()
67 StringWriter sw = new StringWriter ();
68 HtmlTextWriter tw = new HtmlTextWriter (sw);
70 return sw.ToString ();
73 public void DoOnActivate (EventArgs e)
78 public void DoOnDeactivate (EventArgs e)
80 base.OnDeactivate (e);
90 public void View_DefaultProperties ()
92 PokerView b = new PokerView ();
93 Assert.AreEqual (0, b.StateBag.Count, "ViewState.Count");
94 Assert.AreEqual (true, b.EnableTheming, "ViewEnableTheming");
98 [Category ("NotWorking")] // View visible property bug in Mono: default is true instead of false
99 public void View_NotWorkingDefaultProperties ()
101 PokerView b = new PokerView ();
102 Assert.AreEqual (false, b.Visible, "ViewVisible");
106 public void View_AssignToDefaultProperties ()
108 PokerView b = new PokerView ();
109 b.EnableTheming = false;
110 Assert.AreEqual (false, b.EnableTheming, "ThemingValidation");
115 public void View_Defaults_Render ()
117 PokerView b = new PokerView ();
118 string html = b.Render ();
119 Assert.AreEqual (b.Render (), string.Empty, "RenderViewState");
123 public void View_RenderStateWithChilds ()
125 PokerView pv = new PokerView ();
126 Button btn = new Button ();
128 btn.Text = "MyTestButton";
129 pv.Controls.Add (btn);
130 string my = pv.Render ();
131 Assert.AreEqual (@"<input type=""submit"" name=""btn"" value=""MyTestButton"" id=""btn"" />", my, "RenderViewStateWithChilds");
137 private bool activated = false;
138 private bool deactivated = false;
140 private void ViewActivate (object sender, EventArgs e)
145 private void ViewDeActivate (object sender, EventArgs e)
150 private void ResetEvents ()
158 public void View_Events ()
160 PokerView pv = new PokerView ();
162 pv.Activate += new EventHandler (ViewActivate);
163 Assert.AreEqual (false, activated, "BeforeActivate");
164 pv.DoOnActivate (new EventArgs ());
165 Assert.AreEqual (true, activated, "AfterActivate");
167 pv.Deactivate += new EventHandler (ViewDeActivate);
168 Assert.AreEqual (false, deactivated, "BeforeDeactivate");
169 pv.DoOnDeactivate (new EventArgs ());
170 Assert.AreEqual (true, deactivated, "AfterDeactivate");
174 [Category ("NotWorking")] // On assigninging View visible property, an InvalidOperationException must be thrown: bug in Mono
175 [ExpectedException (typeof (InvalidOperationException))]
176 public void View_Visible_Assign ()
178 PokerView b = new PokerView ();