1 //
2 // SecurityExceptionTest.cs - NUnit Test Cases for SecurityException
3 //
4 // Author:
5 //	Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
8 //
9 
10 using NUnit.Framework;
11 using System;
12 using System.Security;
13 using System.Security.Permissions;
14 
15 namespace MonoTests.System.Security {
16 
17 	[TestFixture]
18 	public class SecurityExceptionTest {
19 
20 		[Test]
Constructor_Empty()21 		public void Constructor_Empty ()
22 		{
23 			SecurityException se = new SecurityException ();
24 #if ! NET_1_0
25 			Assert.IsNull (se.GrantedSet, "GrantedSet");
26 			Assert.IsNull (se.RefusedSet, "RefusedSet");
27 #endif
28 			Assert.IsNull (se.PermissionState, "PermissionState");
29 			Assert.IsNull (se.PermissionType, "PermissionType");
30 			Assert.IsTrue (se.ToString ().StartsWith ("System.Security.SecurityException: "), "ToString()");
31 		}
32 
33 		[Test]
Constructor_Message()34 		public void Constructor_Message ()
35 		{
36 			SecurityException se = new SecurityException ("message");
37 #if ! NET_1_0
38 			Assert.IsNull (se.GrantedSet, "GrantedSet");
39 			Assert.IsNull (se.RefusedSet, "RefusedSet");
40 #endif
41 			Assert.IsNull (se.PermissionState, "PermissionState");
42 			Assert.IsNull (se.PermissionType, "PermissionType");
43 			Assert.AreEqual ("System.Security.SecurityException: message", se.ToString (), "ToString()");
44 		}
45 
46 		[Test]
Constructor_MessageInner()47 		public void Constructor_MessageInner ()
48 		{
49 			SecurityException se = new SecurityException ("message", new Exception ());
50 #if ! NET_1_0
51 			Assert.IsNull (se.GrantedSet, "GrantedSet");
52 			Assert.IsNull (se.RefusedSet, "RefusedSet");
53 #endif
54 			Assert.IsNull (se.PermissionState, "PermissionState");
55 			Assert.IsNull (se.PermissionType, "PermissionType");
56 			Assert.IsTrue (se.ToString ().StartsWith ("System.Security.SecurityException: message"), "ToString().Starts");
57 			Assert.IsTrue ((se.ToString ().IndexOf ("System.Exception") > 0), "ToString().Include");
58 		}
59 
60 		[Test]
Constructor_MessageType()61 		public void Constructor_MessageType ()
62 		{
63 			SecurityException se = new SecurityException ("message", typeof (EnvironmentPermission));
64 #if ! NET_1_0
65 			Assert.IsNull (se.GrantedSet, "GrantedSet");
66 			Assert.IsNull (se.RefusedSet, "RefusedSet");
67 #endif
68 			Assert.IsNull (se.PermissionState, "PermissionState");
69 			Assert.AreEqual (typeof (EnvironmentPermission), se.PermissionType, "PermissionType");
70 
71 			Assert.IsTrue (se.ToString ().StartsWith ("System.Security.SecurityException: message"), "ToString().Starts");
72 			// note: can't check for PermissionType as it's not shown with MS class lib
73 		}
74 
75 		[Test]
Constructor_MessageTypeState()76 		public void Constructor_MessageTypeState ()
77 		{
78 			SecurityException se = new SecurityException ("message", typeof (EnvironmentPermission), "mono");
79 			Assert.IsNull (se.GrantedSet, "GrantedSet");
80 			Assert.IsNull (se.RefusedSet, "RefusedSet");
81 			Assert.AreEqual ("mono", se.PermissionState, "PermissionState");
82 			Assert.AreEqual (typeof (EnvironmentPermission), se.PermissionType, "PermissionType");
83 
84 #if !MOBILE
85 			Assert.IsTrue ((se.ToString ().IndexOf ("mono") > 0), "ToString().Include(mono)");
86 #endif
87 			// note: can't check for PermissionType as it's not shown with MS class lib
88 		}
89 	}
90 }
91