merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mcs / class / System.Web / Test / System.Web.SessionState / StateRuntimeCas.cs
1 //
2 // StateRuntimeCas.cs 
3 //      - CAS unit tests for System.Web.SessionState.StateRuntime
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31
32 using System;
33 using System.Reflection;
34 using System.Security;
35 using System.Security.Permissions;
36 using System.Web;
37 using System.Web.SessionState;
38
39 namespace MonoCasTests.System.Web.SessionState {
40
41         // note: the execution order (not user controlable) is very important 
42         // for the tests to execute properly. However the tests are protected 
43         // not to report errors if the order isn't repected.
44
45         [TestFixture]
46         [Category ("CAS")]
47         public class StateRuntimeCas : AspNetHostingMinimal {
48
49                 private StateRuntime runtime;
50
51                 [TestFixtureSetUp]
52                 public void FixtureSetUp ()
53                 {
54                         try {
55                                 // ensure that the static ctor has been called
56                                 runtime = new StateRuntime ();
57                         }
58                         catch {
59                         }
60                 }
61
62                 [Test]
63                 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
64                 [ExpectedException (typeof (SecurityException))]
65                 public void Constructor_Deny_UnmanagedCode ()
66                 {
67                         try {
68                                 new StateRuntime ();
69                         }
70                         catch (TypeInitializationException) {
71                                 Assert.Ignore ("fails on MS");
72                         }
73                 }
74
75                 [Test]
76                 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
77 #if NET_2_0
78                 [ExpectedException (typeof (SecurityException))]
79 #endif
80                 public void Constructor_Deny_Minimal ()
81                 {
82                         try {
83                                 new StateRuntime ();
84                         }
85                         catch (TypeInitializationException) {
86                                 Assert.Ignore ("fails on MS");
87                         }
88                 }
89
90                 [Test]
91 #if NET_2_0
92                 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Minimal)]
93 #endif
94                 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
95                 public void Constructor_PermitOnly_UnmanagedCodeMinimal ()
96                 {
97                         try {
98                                 new StateRuntime ();
99                         }
100                         catch (TypeInitializationException) {
101                                 Assert.Ignore ("fails on MS");
102                         }
103                 }
104
105                 [Test]
106                 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Medium)]
107                 public void ProcessRequest9_PermitOnly_Medium ()
108                 {
109                         if (runtime == null)
110                                 Assert.Ignore ("impossible to instantiate under MS");
111
112                         try {
113                                 runtime.ProcessRequest (IntPtr.Zero, 0, null, 0, 0, 0, 0, 0, IntPtr.Zero);
114                         }
115                         catch (NullReferenceException) {
116                                 // ms 1.x
117                         }
118                         catch (DllNotFoundException) {
119                                 // ms 2.0
120                         }
121                         catch (NotImplementedException) {
122                                 // mono
123                         }
124                 }
125
126                 [Test]
127                 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Medium)]
128                 [ExpectedException (typeof (SecurityException))]
129                 public void ProcessRequest9_Deny_Medium ()
130                 {
131                         if (runtime == null)
132                                 Assert.Ignore ("impossible to instantiate under MS");
133
134                         runtime.ProcessRequest (IntPtr.Zero, 0, null, 0, 0, 0, 0, 0, IntPtr.Zero);
135                 }
136 #if NET_2_0
137                 [Test]
138                 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Medium)]
139                 public void ProcessRequest10_PermitOnly_Medium ()
140                 {
141                         if (runtime == null)
142                                 Assert.Ignore ("impossible to instantiate under MS");
143
144                         try {
145                                 runtime.ProcessRequest (IntPtr.Zero, 0, null, 0, 0, 0, 0, 0, 0, IntPtr.Zero);
146                         }
147                         catch (DllNotFoundException) {
148                                 // ms
149                         }
150                         catch (NotImplementedException) {
151                                 // mono
152                         }
153                 }
154
155                 [Test]
156                 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Medium)]
157                 [ExpectedException (typeof (SecurityException))]
158                 public void ProcessRequest10_Deny_Medium ()
159                 {
160                         if (runtime == null)
161                                 Assert.Ignore ("impossible to instantiate under MS");
162
163                         runtime.ProcessRequest (IntPtr.Zero, 0, null, 0, 0, 0, 0, 0, 0, IntPtr.Zero);
164                 }
165 #endif
166
167                 [Test]
168                 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
169                 [Category ("NotDotNet")] // freeze
170                 public void StopProcessing_PermitOnly_UnmanagedCode ()
171                 {
172                         if (runtime == null)
173                                 Assert.Ignore ("impossible to instantiate under MS");
174
175                         try {
176                                 runtime.StopProcessing ();
177                         }
178                         catch (SecurityException se) {
179                                 Console.WriteLine (se);
180                         }
181                         catch (NotImplementedException) {
182                                 // mono
183                         }
184                 }
185
186                 [Test]
187                 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
188                 [ExpectedException (typeof (SecurityException))]
189                 public void StopProcessing_Deny_UnmanagedCode ()
190                 {
191                         if (runtime == null)
192                                 Assert.Ignore ("may not be possible to instantiate under MS (run-order)");
193
194                         runtime.StopProcessing ();
195                 }
196
197                 // LinkDemand
198
199                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
200                 public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
201                 {
202                         try {
203                                 return base.CreateControl (action, level);
204                         }
205                         catch (TypeInitializationException) {
206                                 // ctor can't be called more than once (else it throws TIE)
207                                 return String.Empty;
208                         }
209                 }
210
211                 public override Type Type {
212                         get { return typeof (StateRuntime); }
213                 }
214         }
215 }