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 ();
44 Assert.IsNotNull (fnf.Data, "#1");
46 Assert.IsNull (fnf.FileName, "#2");
47 Assert.IsNull (fnf.InnerException, "#3");
48 Assert.IsNotNull (fnf.Message, "#4"); // Unable to find the specified file
49 Assert.IsNull (fnf.FusionLog, "#5");
50 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType().FullName), "#6");
54 public void Constructor2 ()
56 FileNotFoundException fnf = new FileNotFoundException ("message");
59 Assert.IsNotNull (fnf.Data, "#1");
61 Assert.IsNull (fnf.FileName, "#2");
62 Assert.IsNull (fnf.InnerException, "#3");
63 Assert.IsNotNull (fnf.Message, "#4");
64 Assert.AreEqual ("message", fnf.Message, "#5");
65 Assert.IsNull (fnf.FusionLog, "#6");
67 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"),"#7");
69 Assert.AreEqual (fnf.GetType ().FullName + ": message",
70 fnf.ToString (), "#7");
75 public void Constructor2_Message_Empty ()
77 FileNotFoundException fnf = new FileNotFoundException (string.Empty);
80 Assert.IsNotNull (fnf.Data, "#1");
82 Assert.IsNull (fnf.FileName, "#2");
83 Assert.IsNull (fnf.InnerException, "#3");
84 Assert.IsNotNull (fnf.Message, "#4");
85 Assert.AreEqual (string.Empty, fnf.Message, "#5");
86 Assert.IsNull (fnf.FusionLog, "#6");
88 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#7");
90 Assert.AreEqual (fnf.GetType ().FullName + ": ",
91 fnf.ToString (), "#7");
96 public void Constructor2_Message_Null ()
98 FileNotFoundException fnf = new FileNotFoundException ((string) null);
101 Assert.IsNotNull (fnf.Data, "#1");
103 Assert.IsNull (fnf.FileName, "#2");
104 Assert.IsNull (fnf.InnerException, "#3");
106 Assert.IsNull (fnf.Message, "#4");
108 Assert.IsNotNull (fnf.Message, "#4"); // File or assembly name (null), or ...
110 Assert.IsNull (fnf.FusionLog, "#5");
111 #if NET_2_0 && !TARGET_JVM
112 Assert.AreEqual (fnf.GetType ().FullName + ": ",
113 fnf.ToString (), "#6");
115 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#6");
120 public void Constructor3 ()
122 ArithmeticException ame = new ArithmeticException ("something");
123 FileNotFoundException fnf = new FileNotFoundException ("message",
127 Assert.IsNotNull (fnf.Data, "#1");
129 Assert.IsNull (fnf.FileName, "#2");
130 Assert.IsNotNull (fnf.InnerException, "#3");
131 Assert.AreSame (ame, fnf.InnerException, "#4");
132 Assert.IsNotNull (fnf.Message, "#5");
133 Assert.AreEqual ("message", fnf.Message, "#6");
134 Assert.IsNull (fnf.FusionLog, "#7");
136 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message ---> "
137 + ame.GetType().FullName + ": something"), "#8");
139 Assert.AreEqual (fnf.GetType ().FullName + ": message ---> "
140 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
145 public void Constructor3_Message_Empty ()
147 ArithmeticException ame = new ArithmeticException ("something");
148 FileNotFoundException fnf = new FileNotFoundException (string.Empty, ame);
151 Assert.IsNotNull (fnf.Data, "#1");
153 Assert.IsNull (fnf.FileName, "#2");
154 Assert.IsNotNull (fnf.InnerException, "#3");
155 Assert.AreSame (ame, fnf.InnerException, "#4");
156 Assert.IsNotNull (fnf.Message, "#5");
157 Assert.AreEqual (string.Empty, fnf.Message, "#6");
158 Assert.IsNull (fnf.FusionLog, "#7");
160 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": ---> "
161 + ame.GetType().FullName + ": something"), "#8");
163 Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
164 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
169 public void Constructor3_Message_Null ()
171 ArithmeticException ame = new ArithmeticException ("something");
172 FileNotFoundException fnf = new FileNotFoundException ((string) null, ame);
175 Assert.IsNotNull (fnf.Data, "#1");
177 Assert.IsNull (fnf.FileName, "#2");
178 Assert.IsNotNull (fnf.InnerException, "#3");
179 Assert.AreSame (ame, fnf.InnerException, "#4");
181 Assert.IsNull (fnf.Message, "#5");
183 Assert.IsNotNull (fnf.Message, "#5"); // File or assembly name (null), or ...
185 Assert.IsNull (fnf.FusionLog, "#6");
188 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": ---> "
189 + ame.GetType().FullName + ": something"), "#7");
191 Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
192 + ame.GetType ().FullName + ": something", fnf.ToString (), "#7");
195 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#7");
196 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#9");
201 public void Constructor3_InnerException_Null ()
203 FileNotFoundException fnf = new FileNotFoundException ("message",
207 Assert.IsNotNull (fnf.Data, "#1");
209 Assert.IsNull (fnf.FileName, "#2");
210 Assert.IsNull (fnf.InnerException, "#3");
211 Assert.IsNotNull (fnf.Message, "#4");
212 Assert.AreEqual ("message", fnf.Message, "#5");
213 Assert.IsNull (fnf.FusionLog, "#6");
215 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#7");
217 Assert.AreEqual (fnf.GetType ().FullName + ": message",
218 fnf.ToString (), "#7");
223 public void Constructor4 ()
225 FileNotFoundException fnf = new FileNotFoundException ("message",
229 Assert.IsNotNull (fnf.Data, "#1");
231 Assert.IsNotNull (fnf.FileName, "#2");
232 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
233 Assert.IsNull (fnf.InnerException, "#4");
234 Assert.IsNotNull (fnf.Message, "#5");
235 Assert.AreEqual ("message", fnf.Message, "#6");
236 Assert.IsNull (fnf.FusionLog, "#7");
237 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
238 + ": message" + Environment.NewLine), "#8");
240 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
241 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
243 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
244 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
249 public void Constructor4_FileName_Empty ()
251 FileNotFoundException fnf = new FileNotFoundException ("message",
255 Assert.IsNotNull (fnf.Data, "#1");
257 Assert.IsNotNull (fnf.FileName, "#2");
258 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
259 Assert.IsNull (fnf.InnerException, "#4");
260 Assert.IsNotNull (fnf.Message, "#5");
261 Assert.AreEqual ("message", fnf.Message, "#6");
262 Assert.IsNull (fnf.FusionLog, "#7");
264 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#8");
266 Assert.AreEqual (fnf.GetType ().FullName + ": message",
267 fnf.ToString (), "#8");
272 public void Constructor4_FileName_Null ()
274 FileNotFoundException fnf = new FileNotFoundException ("message",
278 Assert.IsNotNull (fnf.Data, "#A1");
280 Assert.IsNull (fnf.FileName, "#A2");
281 Assert.IsNull (fnf.InnerException, "#A3");
282 Assert.IsNotNull (fnf.Message, "#A4");
283 Assert.AreEqual ("message", fnf.Message, "#A5");
284 Assert.IsNull (fnf.FusionLog, "#A6");
286 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#A7");
289 Assert.AreEqual (fnf.GetType ().FullName + ": message",
290 fnf.ToString (), "#A7");
293 fnf = new FileNotFoundException (string.Empty, (string) null);
296 Assert.IsNotNull (fnf.Data, "#B1");
298 Assert.IsNull (fnf.FileName, "#B2");
299 Assert.IsNull (fnf.InnerException, "#B3");
300 Assert.IsNotNull (fnf.Message, "#B4");
301 Assert.AreEqual (string.Empty, fnf.Message, "#B5");
302 Assert.IsNull (fnf.FusionLog, "#B6");
304 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#B7");
306 Assert.AreEqual (fnf.GetType ().FullName + ": ",
307 fnf.ToString (), "#B7");
312 public void Constructor4_FileNameAndMessage_Empty ()
314 FileNotFoundException fnf = new FileNotFoundException (string.Empty,
318 Assert.IsNotNull (fnf.Data, "#1");
320 Assert.IsNotNull (fnf.FileName, "#2");
321 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
322 Assert.IsNull (fnf.InnerException, "#4");
323 Assert.IsNotNull (fnf.Message, "#5");
324 Assert.AreEqual (string.Empty, fnf.Message, "#6");
325 Assert.IsNull (fnf.FusionLog, "#7");
327 Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#8");
329 Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
334 public void Constructor4_FileNameAndMessage_Null ()
336 FileNotFoundException fnf = new FileNotFoundException ((string) null,
340 Assert.IsNotNull (fnf.Data, "#1");
342 Assert.IsNull (fnf.FileName, "#2");
343 Assert.IsNull (fnf.InnerException, "#3");
345 Assert.IsNull (fnf.Message, "#4");
347 Assert.IsNotNull (fnf.Message, "#4");
349 Assert.IsNull (fnf.FusionLog, "#5");
350 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
353 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
355 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
359 public void Constructor4_Message_Empty ()
361 FileNotFoundException fnf = null;
363 fnf = new FileNotFoundException (string.Empty, "file.txt");
366 Assert.IsNotNull (fnf.Data, "#1");
368 Assert.IsNotNull (fnf.FileName, "#2");
369 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
370 Assert.IsNull (fnf.InnerException, "#4");
371 Assert.IsNotNull (fnf.Message, "#5");
372 Assert.AreEqual (string.Empty, fnf.Message, "#6");
373 Assert.IsNull (fnf.FusionLog, "#7");
374 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
375 + ": " + Environment.NewLine), "#8");
377 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
378 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
380 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
381 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
386 public void Constructor4_Message_Null ()
388 FileNotFoundException fnf = null;
390 fnf = new FileNotFoundException ((string) null, "file.txt");
393 Assert.IsNotNull (fnf.Data, "#A1");
395 Assert.IsNotNull (fnf.FileName, "#A2");
396 Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
397 Assert.IsNull (fnf.InnerException, "#A4");
398 Assert.IsNotNull (fnf.Message, "#A5");
399 Assert.IsNull (fnf.FusionLog, "#A6");
400 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
402 Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
404 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
405 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
407 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
408 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
411 fnf = new FileNotFoundException ((string) null, string.Empty);
414 Assert.IsNotNull (fnf.Data, "#B1");
416 Assert.IsNotNull (fnf.FileName, "#B2");
417 Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
418 Assert.IsNull (fnf.InnerException, "#B4");
419 // .NET 1.1: File or assembly name , or one of its dependencies ...
420 // .NET 2.0: Could not load file or assembly '' or one of its ...
421 Assert.IsNotNull (fnf.Message, "#B5");
422 Assert.IsNull (fnf.FusionLog, "#B6");
423 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
426 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
429 Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");
431 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#B9");
432 Assert.IsFalse (fnf.ToString ().IndexOf ("\"\"") != -1, "#B10");