New test.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / TemplateControlCas.cs
1 //
2 // TemplateControlCas.cs - CAS unit tests for System.Web.UI.TemplateControl
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.Security;
33 using System.IO;
34 using System.Security.Permissions;
35 using System.Web;
36 using System.Web.UI;
37
38 namespace MonoCasTests.System.Web.UI {
39
40         class NonAbstractTemplateControl : TemplateControl {
41
42                 public NonAbstractTemplateControl ()
43                 {
44                 }
45         }
46
47         [TestFixture]
48         [Category ("CAS")]
49         public class TemplateControlCas {
50
51                 [SetUp]
52                 public virtual void SetUp ()
53                 {
54                         if (!SecurityManager.SecurityEnabled)
55                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
56                 }
57
58                 [Test]
59                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
60 #if NET_2_0
61                 [ExpectedException (typeof (ArgumentNullException))]
62 #else
63                 [ExpectedException (typeof (HttpException))]
64 #endif
65                 public void LoadControl_Deny_Unrestricted ()
66                 {
67                         NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
68                         tc.LoadControl (null);
69                 }
70
71                 [Test]
72                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
73 #if NET_2_0
74                 [ExpectedException (typeof (ArgumentNullException))]
75 #else
76                 [ExpectedException (typeof (HttpException))]
77 #endif
78                 public void LoadTemplate_Deny_Unrestricted ()
79                 {
80                         NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
81                         tc.LoadTemplate (null);
82                 }
83
84                 [Test]
85                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
86                 [ExpectedException (typeof (ArgumentNullException))]
87                 public void ParseControl_Deny_Unrestricted ()
88                 {
89                         NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
90                         try {
91                                 tc.ParseControl (null);
92                         }
93                         catch (NullReferenceException) {
94 #if NET_2_0
95                                 throw;
96 #else
97                                 Assert.Ignore ("NRE");
98 #endif
99                         }
100                 }
101
102                 [Test]
103                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
104                 [ExpectedException (typeof (ArgumentNullException))]
105                 public void ReadStringResource_Deny_Unrestricted ()
106                 {
107                         try {
108                                 TemplateControl.ReadStringResource (null);
109                         }
110                         catch (TypeInitializationException) {
111 #if NET_2_0
112                                 Assert.Ignore ("exception during initialization");
113 #else
114                                 throw;
115 #endif
116                         }
117                 }
118
119                 private void Handler (object sender, EventArgs e)
120                 {
121                 }
122
123                 [Test]
124                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
125                 public void Events_Deny_Unrestricted ()
126                 {
127                         NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
128                         tc.AbortTransaction += new EventHandler (Handler);
129                         tc.CommitTransaction += new EventHandler (Handler);
130                         tc.Error += new EventHandler (Handler);
131
132                         tc.AbortTransaction -= new EventHandler (Handler);
133                         tc.CommitTransaction -= new EventHandler (Handler);
134                         tc.Error -= new EventHandler (Handler);
135                 }
136 #if NET_2_0
137                 [Test]
138                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
139                 [ExpectedException (typeof (TypeInitializationException))]
140                 public void IFilterResolutionService_Deny_Unrestricted ()
141                 {
142                         IFilterResolutionService frs = new NonAbstractTemplateControl ();
143                         try {
144                                 Assert.AreEqual (0, frs.CompareFilters (String.Empty, String.Empty), "CompareFilters");
145                         }
146                         catch (NotImplementedException) {
147                                 // mono
148                         }
149                         try {
150                                 Assert.IsFalse (frs.EvaluateFilter (String.Empty), "EvaluateFilter");
151                         }
152                         catch (NotImplementedException) {
153                                 // mono
154                         }
155                 }
156 #endif
157         }
158 }