2 // FileNotFoundExceptionCas.cs - CAS unit tests for
3 // System.IO.FileNotFoundException
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
34 using System.Security;
35 using System.Security.Permissions;
37 namespace MonoCasTests.System.IO {
41 public class FileNotFoundExceptionCas {
46 if (!SecurityManager.SecurityEnabled)
47 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
52 public void NoRestriction ()
54 FileNotFoundException fle = new FileNotFoundException ("message", "filename",
55 new FileNotFoundException ("inner message", "inner filename"));
57 Assert.AreEqual ("message", fle.Message, "Message");
58 Assert.AreEqual ("filename", fle.FileName, "FileName");
59 Assert.IsNull (fle.FusionLog, "FusionLog");
60 Assert.IsNotNull (fle.ToString (), "ToString");
64 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
65 [ExpectedException (typeof (SecurityException))]
66 public void FullRestriction ()
68 FileNotFoundException fle = new FileNotFoundException ("message", "filename",
69 new FileNotFoundException ("inner message", "inner filename"));
71 Assert.AreEqual ("message", fle.Message, "Message");
72 Assert.AreEqual ("filename", fle.FileName, "FileName");
73 Assert.IsNull (fle.FusionLog, "FusionLog");
74 // ToString doesn't work in this case and strangely throws a FileNotFoundException
75 Assert.IsNotNull (fle.ToString (), "ToString");
79 [SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
80 public void GetFusionLog_Pass ()
82 FileNotFoundException fle = new FileNotFoundException ("message", "filename");
83 Assert.AreEqual ("message", fle.Message, "Message");
84 Assert.AreEqual ("filename", fle.FileName, "FileName");
85 Assert.IsNull (fle.FusionLog, "FusionLog");
86 // note: ToString doesn't work in this case
90 [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
91 [ExpectedException (typeof (SecurityException))]
92 public void GetFusionLog_Fail_ControlEvidence ()
94 FileNotFoundException fle = new FileNotFoundException ();
95 Assert.IsNull (fle.FusionLog, "FusionLog");
99 [SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
100 [ExpectedException (typeof (SecurityException))]
101 public void GetFusionLog_Fail_ControlPolicy ()
103 FileNotFoundException fle = new FileNotFoundException ();
104 Assert.IsNull (fle.FusionLog, "FusionLog");
105 // we don't have to throw the exception to have FusionLog
106 // informations restricted (even if there could be no
107 // data in this state).
112 public void Throw_NoRestriction ()
115 throw new FileNotFoundException ("message", "filename",
116 new FileNotFoundException ("inner message", "inner filename"));
118 catch (FileNotFoundException fle) {
119 Assert.AreEqual ("message", fle.Message, "Message");
120 Assert.AreEqual ("filename", fle.FileName, "FileName");
121 Assert.IsNull (fle.FusionLog, "FusionLog");
122 Assert.IsNotNull (fle.ToString (), "ToString");
127 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
129 [ExpectedException (typeof (FileNotFoundException))]
131 [ExpectedException (typeof (SecurityException))]
133 public void Throw_FullRestriction ()
136 throw new FileNotFoundException ("message", "filename",
137 new FileNotFoundException ("inner message", "inner filename"));
139 catch (FileNotFoundException fle) {
140 Assert.AreEqual ("message", fle.Message, "Message");
141 Assert.AreEqual ("filename", fle.FileName, "FileName");
142 // both FusionLog and ToString doesn't work in this case
143 // but strangely we get a FileNotFoundException
144 Assert.IsNull (fle.FusionLog, "FusionLog");
145 Assert.IsNotNull (fle.ToString (), "ToString");
150 [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
152 [ExpectedException (typeof (FileNotFoundException))]
154 [ExpectedException (typeof (SecurityException))]
156 public void Throw_GetFusionLog_Fail_ControlEvidence ()
159 throw new FileNotFoundException ("message", "filename",
160 new FileNotFoundException ("inner message", "inner filename"));
162 catch (FileNotFoundException fle) {
163 Assert.IsNull (fle.FusionLog, "FusionLog");
168 [SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
170 [ExpectedException (typeof (FileNotFoundException))]
172 [ExpectedException (typeof (SecurityException))]
174 public void Throw_GetFusionLog_Fail_ControlPolicy ()
177 throw new FileNotFoundException ("message", "filename",
178 new FileNotFoundException ("inner message", "inner filename"));
180 catch (FileNotFoundException fle) {
181 Assert.IsNull (fle.FusionLog, "FusionLog");