* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / ViewTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.View.cs
3 //
4 // Author:
5 //      Yoni Klein (yonik@mainsoft.com)
6 //
7 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28
29 #if NET_2_0
30
31
32 using NUnit.Framework;
33 using System;
34 using System.IO;
35 using System.Globalization;
36 using System.Web;
37 using System.Web.UI;
38 using System.Web.UI.WebControls;
39
40 namespace MonoTests.System.Web.UI.WebControls
41 {
42
43         class PokerView : View
44         {
45                 public PokerView ()
46                 {
47                         TrackViewState ();
48                 }
49
50                 public object SaveState ()
51                 {
52                         return SaveViewState ();
53                 }
54
55                 public void LoadState (object o)
56                 {
57                         LoadViewState (o);
58                 }
59
60                 public StateBag StateBag
61                 {
62                         get { return base.ViewState; }
63                 }
64
65                 public string Render ()
66                 {
67                         StringWriter sw = new StringWriter ();
68                         HtmlTextWriter tw = new HtmlTextWriter (sw);
69                         Render (tw);
70                         return sw.ToString ();
71                 }
72
73                 public void DoOnActivate (EventArgs e)
74                 {
75                         base.OnActivate (e);
76                 }
77
78                 public void DoOnDeactivate (EventArgs e)
79                 {
80                         base.OnDeactivate (e);
81                 }
82
83
84         }
85
86         [TestFixture]
87         public class ViewTest
88         {
89                 [Test]
90                 public void View_DefaultProperties ()
91                 {
92                         PokerView b = new PokerView ();
93                         Assert.AreEqual (0, b.StateBag.Count, "ViewState.Count");
94                         Assert.AreEqual (true, b.EnableTheming, "ViewEnableTheming");           
95                 }
96                                 
97                 [Test]
98                 [Category ("NotWorking")] // View visible property bug in Mono: default is true instead of false
99                 public void View_NotWorkingDefaultProperties ()
100                 {
101                         PokerView b = new PokerView ();
102                         Assert.AreEqual (false, b.Visible, "ViewVisible");
103                 }
104
105                 [Test]
106                 public void View_AssignToDefaultProperties ()
107                 {
108                         PokerView b = new PokerView ();                 
109                         b.EnableTheming = false;
110                         Assert.AreEqual (false, b.EnableTheming, "ThemingValidation");
111                 }
112
113
114                 [Test]
115                 public void View_Defaults_Render ()
116                 {
117                         PokerView b = new PokerView ();
118                         string html = b.Render ();
119                         Assert.AreEqual (b.Render (), string.Empty, "RenderViewState");
120                 }
121
122                 [Test]
123                 public void View_RenderStateWithChilds ()
124                 {
125                         PokerView pv = new PokerView ();
126                         Button btn = new Button ();
127                         btn.ID = "btn";
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");
132                 }
133
134
135
136                 // Events Stuff
137                 private bool activated = false;
138                 private bool deactivated = false;
139
140                 private void ViewActivate (object sender, EventArgs e)
141                 {
142                         activated = true;
143                 }
144
145                 private void ViewDeActivate (object sender, EventArgs e)
146                 {
147                         deactivated = true;
148                 }
149
150                 private void ResetEvents ()
151                 {
152                         activated = false;
153                         deactivated = false;
154                 }
155
156
157                 [Test]
158                 public void View_Events ()
159                 {
160                         PokerView pv = new PokerView ();
161                         ResetEvents ();
162                         pv.Activate += new EventHandler (ViewActivate);
163                         Assert.AreEqual (false, activated, "BeforeActivate");
164                         pv.DoOnActivate (new EventArgs ());
165                         Assert.AreEqual (true, activated, "AfterActivate");
166                         ResetEvents ();
167                         pv.Deactivate += new EventHandler (ViewDeActivate);
168                         Assert.AreEqual (false, deactivated, "BeforeDeactivate");
169                         pv.DoOnDeactivate (new EventArgs ());
170                         Assert.AreEqual (true, deactivated, "AfterDeactivate");
171                 }               
172
173                 [Test]
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 ()
177                 {
178                         PokerView b = new PokerView ();
179                         b.Visible = true;
180                 }
181         }
182 }
183
184 #endif
185