ControlTest.cs added new tests and resources
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / ControlCas.cs
1 //
2 // ControlCas.cs - CAS unit tests for System.Web.UI.Control
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.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 using NUnit.Framework;
30
31 using System;
32 using System.IO;
33 using System.Reflection;
34 using System.Security;
35 using System.Security.Permissions;
36 using System.Web;
37 using System.Web.UI;
38 using System.Web.UI.WebControls;
39
40 namespace MonoCasTests.System.Web.UI {
41
42         [TestFixture]
43         [Category ("CAS")]
44         public class ControlCas : AspNetHostingMinimal {
45
46                 private Control control;
47                 private HtmlTextWriter writer;
48                 private Page page;
49
50                 [TestFixtureSetUp]
51                 public void FixtureSetUp ()
52                 {
53                         control = new Control ();
54                         writer = new HtmlTextWriter (new StringWriter ());
55                         page = new Page ();
56                 }
57
58                 [Test]
59                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
60                 public void Properties_Deny_Unrestricted ()
61                 {
62                         Control c = new Control ();
63                         Assert.IsNull (c.ClientID, "ClientID");
64                         Assert.IsNotNull (c.Controls, "Controls");
65                         c.EnableViewState = true;
66                         Assert.IsTrue (c.EnableViewState, "EnableViewState");
67                         c.ID = "mono";
68                         Assert.AreEqual ("mono", c.ID, "ID");
69                         Assert.IsNull (c.NamingContainer, "NamingContainer");
70                         Assert.IsNull (c.Page, "Page");
71                         Assert.IsNull (c.Parent, "Parent");
72                         Assert.IsNull (c.Site, "Site");
73                         Assert.AreEqual ("mono", c.UniqueID, "UniqueID");
74                         Assert.IsTrue (c.Visible, "Visible");
75 #if NET_2_0
76                         c.AppRelativeTemplateSourceDirectory = String.Empty;
77                         Assert.AreEqual (String.Empty, c.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory");
78                         c.EnableTheming = true;
79                         Assert.IsTrue (c.EnableTheming, "EnableTheming");
80                         c.SkinID = String.Empty;
81                         Assert.AreEqual (String.Empty, c.SkinID, "SkinID");
82                         c.TemplateControl = null;
83                         Assert.IsNull (c.TemplateControl, "TemplateControl");
84                         Assert.AreEqual (String.Empty, c.TemplateSourceDirectory, "TemplateSourceDirectory");
85 #endif
86                 }
87
88                 private void SetRenderMethodDelegate (HtmlTextWriter writer, Control control)
89                 {
90                 }
91
92                 [Test]
93                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
94                 public void Methods_Deny_Unrestricted ()
95                 {
96                         Control c = new Control ();
97
98                         c.DataBind ();
99                         Assert.IsNull (c.FindControl ("mono"), "FindControl");
100
101                         Assert.IsFalse (c.HasControls (), "HasControls");
102                         c.RenderControl (writer);
103                         Assert.IsNotNull (c.ResolveUrl (String.Empty), "ResolveUrl");
104                         c.SetRenderMethodDelegate (new RenderMethod (SetRenderMethodDelegate));
105 #if NET_2_0
106                         c.ApplyStyleSheetSkin (page);
107                         Assert.IsNotNull (c.ResolveClientUrl (String.Empty), "ResolveClientUrl");
108 #endif
109                         c.Dispose ();
110                 }
111
112 #if NET_2_0
113                 [Test]
114                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
115                 [ExpectedException (typeof (InvalidOperationException))]
116                 public void Focus_Deny_Unrestricted ()
117                 {
118                         Control c = new Control ();
119                         page.Controls.Add (c);
120                         c.Focus ();
121                         // normal, no forms on page
122                 }
123 #endif
124
125                 private void Handler (object sender, EventArgs e)
126                 {
127                 }
128
129                 [Test]
130                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
131                 public void Events_Deny_Unrestricted ()
132                 {
133                         Control c = new Control ();
134                         c.DataBinding += new EventHandler (Handler);
135                         c.Disposed += new EventHandler (Handler);
136                         c.Init += new EventHandler (Handler);
137                         c.Load += new EventHandler (Handler);
138                         c.PreRender += new EventHandler (Handler);
139                         c.Unload += new EventHandler (Handler);
140
141                         c.DataBinding -= new EventHandler (Handler);
142                         c.Disposed -= new EventHandler (Handler);
143                         c.Init -= new EventHandler (Handler);
144                         c.Load -= new EventHandler (Handler);
145                         c.PreRender -= new EventHandler (Handler);
146                         c.Unload -= new EventHandler (Handler);
147                 }
148
149                 // LinkDemand
150
151                 public override Type Type {
152                         get { return typeof (Control); }
153                 }
154         }
155 }