2 // FileNotFoundExceptionTest.cs - Unit tests for
3 // System.IO.FileNotFoundException
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2006 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.
33 using NUnit.Framework;
35 namespace MonoTests.System.IO {
37 public class FileNotFoundExceptionTest {
39 public void Constructor1 ()
41 FileNotFoundException fnf = new FileNotFoundException ();
43 Assert.IsNotNull (fnf.Data, "#1");
44 Assert.IsNull (fnf.FileName, "#2");
45 Assert.IsNull (fnf.InnerException, "#3");
46 Assert.IsNotNull (fnf.Message, "#4"); // Unable to find the specified file
47 Assert.IsNull (fnf.FusionLog, "#5");
48 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType().FullName), "#6");
52 public void Constructor2 ()
54 FileNotFoundException fnf = new FileNotFoundException ("message");
56 Assert.IsNotNull (fnf.Data, "#1");
57 Assert.IsNull (fnf.FileName, "#2");
58 Assert.IsNull (fnf.InnerException, "#3");
59 Assert.IsNotNull (fnf.Message, "#4");
60 Assert.AreEqual ("message", fnf.Message, "#5");
61 Assert.IsNull (fnf.FusionLog, "#6");
62 Assert.AreEqual (fnf.GetType ().FullName + ": message",
63 fnf.ToString (), "#7");
67 public void Constructor2_Message_Empty ()
69 FileNotFoundException fnf = new FileNotFoundException (string.Empty);
71 Assert.IsNotNull (fnf.Data, "#1");
72 Assert.IsNull (fnf.FileName, "#2");
73 Assert.IsNull (fnf.InnerException, "#3");
74 Assert.IsNotNull (fnf.Message, "#4");
75 Assert.AreEqual (string.Empty, fnf.Message, "#5");
76 Assert.IsNull (fnf.FusionLog, "#6");
77 Assert.AreEqual (fnf.GetType ().FullName + ": ",
78 fnf.ToString (), "#7");
82 public void Constructor2_Message_Null ()
84 FileNotFoundException fnf = new FileNotFoundException ((string) null);
86 Assert.IsNotNull (fnf.Data, "#1");
87 Assert.IsNull (fnf.FileName, "#2");
88 Assert.IsNull (fnf.InnerException, "#3");
89 Assert.IsNull (fnf.Message, "#4");
90 Assert.IsNull (fnf.FusionLog, "#5");
91 Assert.AreEqual (fnf.GetType ().FullName + ": ",
92 fnf.ToString (), "#6");
96 public void Constructor3 ()
98 ArithmeticException ame = new ArithmeticException ("something");
99 FileNotFoundException fnf = new FileNotFoundException ("message",
102 Assert.IsNotNull (fnf.Data, "#1");
103 Assert.IsNull (fnf.FileName, "#2");
104 Assert.IsNotNull (fnf.InnerException, "#3");
105 Assert.AreSame (ame, fnf.InnerException, "#4");
106 Assert.IsNotNull (fnf.Message, "#5");
107 Assert.AreEqual ("message", fnf.Message, "#6");
108 Assert.IsNull (fnf.FusionLog, "#7");
109 Assert.AreEqual (fnf.GetType ().FullName + ": message ---> "
110 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
114 public void Constructor3_Message_Empty ()
116 ArithmeticException ame = new ArithmeticException ("something");
117 FileNotFoundException fnf = new FileNotFoundException (string.Empty, ame);
119 Assert.IsNotNull (fnf.Data, "#1");
120 Assert.IsNull (fnf.FileName, "#2");
121 Assert.IsNotNull (fnf.InnerException, "#3");
122 Assert.AreSame (ame, fnf.InnerException, "#4");
123 Assert.IsNotNull (fnf.Message, "#5");
124 Assert.AreEqual (string.Empty, fnf.Message, "#6");
125 Assert.IsNull (fnf.FusionLog, "#7");
126 Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
127 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
131 public void Constructor3_Message_Null ()
133 ArithmeticException ame = new ArithmeticException ("something");
134 FileNotFoundException fnf = new FileNotFoundException ((string) null, ame);
136 Assert.IsNotNull (fnf.Data, "#1");
137 Assert.IsNull (fnf.FileName, "#2");
138 Assert.IsNotNull (fnf.InnerException, "#3");
139 Assert.AreSame (ame, fnf.InnerException, "#4");
140 Assert.IsNull (fnf.Message, "#5");
141 Assert.IsNull (fnf.FusionLog, "#6");
142 Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
143 + ame.GetType ().FullName + ": something", fnf.ToString (), "#7");
147 public void Constructor3_InnerException_Null ()
149 FileNotFoundException fnf = new FileNotFoundException ("message",
152 Assert.IsNotNull (fnf.Data, "#1");
153 Assert.IsNull (fnf.FileName, "#2");
154 Assert.IsNull (fnf.InnerException, "#3");
155 Assert.IsNotNull (fnf.Message, "#4");
156 Assert.AreEqual ("message", fnf.Message, "#5");
157 Assert.IsNull (fnf.FusionLog, "#6");
158 Assert.AreEqual (fnf.GetType ().FullName + ": message",
159 fnf.ToString (), "#7");
163 public void Constructor4 ()
165 FileNotFoundException fnf = new FileNotFoundException ("message",
168 Assert.IsNotNull (fnf.Data, "#1");
169 Assert.IsNotNull (fnf.FileName, "#2");
170 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
171 Assert.IsNull (fnf.InnerException, "#4");
172 Assert.IsNotNull (fnf.Message, "#5");
173 Assert.AreEqual ("message", fnf.Message, "#6");
174 Assert.IsNull (fnf.FusionLog, "#7");
175 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
176 + ": message" + Environment.NewLine), "#8");
177 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
178 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
182 public void Constructor4_FileName_Empty ()
184 FileNotFoundException fnf = new FileNotFoundException ("message",
187 Assert.IsNotNull (fnf.Data, "#1");
188 Assert.IsNotNull (fnf.FileName, "#2");
189 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
190 Assert.IsNull (fnf.InnerException, "#4");
191 Assert.IsNotNull (fnf.Message, "#5");
192 Assert.AreEqual ("message", fnf.Message, "#6");
193 Assert.IsNull (fnf.FusionLog, "#7");
194 Assert.AreEqual (fnf.GetType ().FullName + ": message",
195 fnf.ToString (), "#8");
199 public void Constructor4_FileName_Null ()
201 FileNotFoundException fnf = new FileNotFoundException ("message",
204 Assert.IsNotNull (fnf.Data, "#A1");
205 Assert.IsNull (fnf.FileName, "#A2");
206 Assert.IsNull (fnf.InnerException, "#A3");
207 Assert.IsNotNull (fnf.Message, "#A4");
208 Assert.AreEqual ("message", fnf.Message, "#A5");
209 Assert.IsNull (fnf.FusionLog, "#A6");
211 Assert.AreEqual (fnf.GetType ().FullName + ": message",
212 fnf.ToString (), "#A7");
214 fnf = new FileNotFoundException (string.Empty, (string) null);
216 Assert.IsNotNull (fnf.Data, "#B1");
217 Assert.IsNull (fnf.FileName, "#B2");
218 Assert.IsNull (fnf.InnerException, "#B3");
219 Assert.IsNotNull (fnf.Message, "#B4");
220 Assert.AreEqual (string.Empty, fnf.Message, "#B5");
221 Assert.IsNull (fnf.FusionLog, "#B6");
222 Assert.AreEqual (fnf.GetType ().FullName + ": ",
223 fnf.ToString (), "#B7");
227 public void Constructor4_FileNameAndMessage_Empty ()
229 FileNotFoundException fnf = new FileNotFoundException (string.Empty,
232 Assert.IsNotNull (fnf.Data, "#1");
233 Assert.IsNotNull (fnf.FileName, "#2");
234 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
235 Assert.IsNull (fnf.InnerException, "#4");
236 Assert.IsNotNull (fnf.Message, "#5");
237 Assert.AreEqual (string.Empty, fnf.Message, "#6");
238 Assert.IsNull (fnf.FusionLog, "#7");
239 Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
243 public void Constructor4_FileNameAndMessage_Null ()
245 FileNotFoundException fnf = new FileNotFoundException ((string) null,
248 Assert.IsNotNull (fnf.Data, "#1");
249 Assert.IsNull (fnf.FileName, "#2");
250 Assert.IsNull (fnf.InnerException, "#3");
251 Assert.IsNull (fnf.Message, "#4");
252 Assert.IsNull (fnf.FusionLog, "#5");
253 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
255 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
256 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
260 public void Constructor4_Message_Empty ()
262 FileNotFoundException fnf = null;
264 fnf = new FileNotFoundException (string.Empty, "file.txt");
266 Assert.IsNotNull (fnf.Data, "#1");
267 Assert.IsNotNull (fnf.FileName, "#2");
268 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
269 Assert.IsNull (fnf.InnerException, "#4");
270 Assert.IsNotNull (fnf.Message, "#5");
271 Assert.AreEqual (string.Empty, fnf.Message, "#6");
272 Assert.IsNull (fnf.FusionLog, "#7");
273 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
274 + ": " + Environment.NewLine), "#8");
275 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
276 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
280 public void Constructor4_Message_Null ()
282 FileNotFoundException fnf = null;
284 fnf = new FileNotFoundException ((string) null, "file.txt");
286 Assert.IsNotNull (fnf.Data, "#A1");
287 Assert.IsNotNull (fnf.FileName, "#A2");
288 Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
289 Assert.IsNull (fnf.InnerException, "#A4");
290 Assert.IsNotNull (fnf.Message, "#A5");
291 Assert.IsNull (fnf.FusionLog, "#A6");
292 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
294 Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
295 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
296 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
298 fnf = new FileNotFoundException ((string) null, string.Empty);
300 Assert.IsNotNull (fnf.Data, "#B1");
301 Assert.IsNotNull (fnf.FileName, "#B2");
302 Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
303 Assert.IsNull (fnf.InnerException, "#B4");
304 // .NET 1.1: File or assembly name , or one of its dependencies ...
305 // .NET 2.0: Could not load file or assembly '' or one of its ...
306 Assert.IsNotNull (fnf.Message, "#B5");
307 Assert.IsNull (fnf.FusionLog, "#B6");
308 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
310 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
311 Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");