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");
66 Assert.AreEqual (fnf.GetType ().FullName + ": message",
67 fnf.ToString (), "#7");
71 public void Constructor2_Message_Empty ()
73 FileNotFoundException fnf = new FileNotFoundException (string.Empty);
76 Assert.IsNotNull (fnf.Data, "#1");
78 Assert.IsNull (fnf.FileName, "#2");
79 Assert.IsNull (fnf.InnerException, "#3");
80 Assert.IsNotNull (fnf.Message, "#4");
81 Assert.AreEqual (string.Empty, fnf.Message, "#5");
82 Assert.IsNull (fnf.FusionLog, "#6");
83 Assert.AreEqual (fnf.GetType ().FullName + ": ",
84 fnf.ToString (), "#7");
88 public void Constructor2_Message_Null ()
90 FileNotFoundException fnf = new FileNotFoundException ((string) null);
93 Assert.IsNotNull (fnf.Data, "#1");
95 Assert.IsNull (fnf.FileName, "#2");
96 Assert.IsNull (fnf.InnerException, "#3");
98 Assert.IsNull (fnf.Message, "#4");
100 Assert.IsNotNull (fnf.Message, "#4"); // File or assembly name (null), or ...
102 Assert.IsNull (fnf.FusionLog, "#5");
104 Assert.AreEqual (fnf.GetType ().FullName + ": ",
105 fnf.ToString (), "#6");
107 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#6");
112 public void Constructor3 ()
114 ArithmeticException ame = new ArithmeticException ("something");
115 FileNotFoundException fnf = new FileNotFoundException ("message",
119 Assert.IsNotNull (fnf.Data, "#1");
121 Assert.IsNull (fnf.FileName, "#2");
122 Assert.IsNotNull (fnf.InnerException, "#3");
123 Assert.AreSame (ame, fnf.InnerException, "#4");
124 Assert.IsNotNull (fnf.Message, "#5");
125 Assert.AreEqual ("message", fnf.Message, "#6");
126 Assert.IsNull (fnf.FusionLog, "#7");
127 Assert.AreEqual (fnf.GetType ().FullName + ": message ---> "
128 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
132 public void Constructor3_Message_Empty ()
134 ArithmeticException ame = new ArithmeticException ("something");
135 FileNotFoundException fnf = new FileNotFoundException (string.Empty, ame);
138 Assert.IsNotNull (fnf.Data, "#1");
140 Assert.IsNull (fnf.FileName, "#2");
141 Assert.IsNotNull (fnf.InnerException, "#3");
142 Assert.AreSame (ame, fnf.InnerException, "#4");
143 Assert.IsNotNull (fnf.Message, "#5");
144 Assert.AreEqual (string.Empty, fnf.Message, "#6");
145 Assert.IsNull (fnf.FusionLog, "#7");
146 Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
147 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
151 public void Constructor3_Message_Null ()
153 ArithmeticException ame = new ArithmeticException ("something");
154 FileNotFoundException fnf = new FileNotFoundException ((string) null, ame);
157 Assert.IsNotNull (fnf.Data, "#1");
159 Assert.IsNull (fnf.FileName, "#2");
160 Assert.IsNotNull (fnf.InnerException, "#3");
161 Assert.AreSame (ame, fnf.InnerException, "#4");
163 Assert.IsNull (fnf.Message, "#5");
165 Assert.IsNotNull (fnf.Message, "#5"); // File or assembly name (null), or ...
167 Assert.IsNull (fnf.FusionLog, "#6");
169 Assert.AreEqual (fnf.GetType ().FullName + ": ---> "
170 + ame.GetType ().FullName + ": something", fnf.ToString (), "#7");
172 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#7");
173 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#9");
178 public void Constructor3_InnerException_Null ()
180 FileNotFoundException fnf = new FileNotFoundException ("message",
184 Assert.IsNotNull (fnf.Data, "#1");
186 Assert.IsNull (fnf.FileName, "#2");
187 Assert.IsNull (fnf.InnerException, "#3");
188 Assert.IsNotNull (fnf.Message, "#4");
189 Assert.AreEqual ("message", fnf.Message, "#5");
190 Assert.IsNull (fnf.FusionLog, "#6");
191 Assert.AreEqual (fnf.GetType ().FullName + ": message",
192 fnf.ToString (), "#7");
196 public void Constructor4 ()
198 FileNotFoundException fnf = new FileNotFoundException ("message",
202 Assert.IsNotNull (fnf.Data, "#1");
204 Assert.IsNotNull (fnf.FileName, "#2");
205 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
206 Assert.IsNull (fnf.InnerException, "#4");
207 Assert.IsNotNull (fnf.Message, "#5");
208 Assert.AreEqual ("message", fnf.Message, "#6");
209 Assert.IsNull (fnf.FusionLog, "#7");
210 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
211 + ": message" + Environment.NewLine), "#8");
213 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
214 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
216 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
217 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
222 public void Constructor4_FileName_Empty ()
224 FileNotFoundException fnf = new FileNotFoundException ("message",
228 Assert.IsNotNull (fnf.Data, "#1");
230 Assert.IsNotNull (fnf.FileName, "#2");
231 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
232 Assert.IsNull (fnf.InnerException, "#4");
233 Assert.IsNotNull (fnf.Message, "#5");
234 Assert.AreEqual ("message", fnf.Message, "#6");
235 Assert.IsNull (fnf.FusionLog, "#7");
236 Assert.AreEqual (fnf.GetType ().FullName + ": message",
237 fnf.ToString (), "#8");
241 public void Constructor4_FileName_Null ()
243 FileNotFoundException fnf = new FileNotFoundException ("message",
247 Assert.IsNotNull (fnf.Data, "#A1");
249 Assert.IsNull (fnf.FileName, "#A2");
250 Assert.IsNull (fnf.InnerException, "#A3");
251 Assert.IsNotNull (fnf.Message, "#A4");
252 Assert.AreEqual ("message", fnf.Message, "#A5");
253 Assert.IsNull (fnf.FusionLog, "#A6");
254 Assert.AreEqual (fnf.GetType ().FullName + ": message",
255 fnf.ToString (), "#A7");
257 fnf = new FileNotFoundException (string.Empty, (string) null);
260 Assert.IsNotNull (fnf.Data, "#B1");
262 Assert.IsNull (fnf.FileName, "#B2");
263 Assert.IsNull (fnf.InnerException, "#B3");
264 Assert.IsNotNull (fnf.Message, "#B4");
265 Assert.AreEqual (string.Empty, fnf.Message, "#B5");
266 Assert.IsNull (fnf.FusionLog, "#B6");
267 Assert.AreEqual (fnf.GetType ().FullName + ": ",
268 fnf.ToString (), "#B7");
272 public void Constructor4_FileNameAndMessage_Empty ()
274 FileNotFoundException fnf = new FileNotFoundException (string.Empty,
278 Assert.IsNotNull (fnf.Data, "#1");
280 Assert.IsNotNull (fnf.FileName, "#2");
281 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
282 Assert.IsNull (fnf.InnerException, "#4");
283 Assert.IsNotNull (fnf.Message, "#5");
284 Assert.AreEqual (string.Empty, fnf.Message, "#6");
285 Assert.IsNull (fnf.FusionLog, "#7");
286 Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
290 public void Constructor4_FileNameAndMessage_Null ()
292 FileNotFoundException fnf = new FileNotFoundException ((string) null,
296 Assert.IsNotNull (fnf.Data, "#1");
298 Assert.IsNull (fnf.FileName, "#2");
299 Assert.IsNull (fnf.InnerException, "#3");
301 Assert.IsNull (fnf.Message, "#4");
303 Assert.IsNotNull (fnf.Message, "#4");
305 Assert.IsNull (fnf.FusionLog, "#5");
306 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
308 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
309 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
313 public void Constructor4_Message_Empty ()
315 FileNotFoundException fnf = null;
317 fnf = new FileNotFoundException (string.Empty, "file.txt");
320 Assert.IsNotNull (fnf.Data, "#1");
322 Assert.IsNotNull (fnf.FileName, "#2");
323 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
324 Assert.IsNull (fnf.InnerException, "#4");
325 Assert.IsNotNull (fnf.Message, "#5");
326 Assert.AreEqual (string.Empty, fnf.Message, "#6");
327 Assert.IsNull (fnf.FusionLog, "#7");
328 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
329 + ": " + Environment.NewLine), "#8");
331 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
332 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
334 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
335 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
340 public void Constructor4_Message_Null ()
342 FileNotFoundException fnf = null;
344 fnf = new FileNotFoundException ((string) null, "file.txt");
347 Assert.IsNotNull (fnf.Data, "#A1");
349 Assert.IsNotNull (fnf.FileName, "#A2");
350 Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
351 Assert.IsNull (fnf.InnerException, "#A4");
352 Assert.IsNotNull (fnf.Message, "#A5");
353 Assert.IsNull (fnf.FusionLog, "#A6");
354 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
356 Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
358 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
359 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
361 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
362 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
365 fnf = new FileNotFoundException ((string) null, string.Empty);
368 Assert.IsNotNull (fnf.Data, "#B1");
370 Assert.IsNotNull (fnf.FileName, "#B2");
371 Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
372 Assert.IsNull (fnf.InnerException, "#B4");
373 // .NET 1.1: File or assembly name , or one of its dependencies ...
374 // .NET 2.0: Could not load file or assembly '' or one of its ...
375 Assert.IsNotNull (fnf.Message, "#B5");
376 Assert.IsNull (fnf.FusionLog, "#B6");
377 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
379 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
381 Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");
383 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#B9");
384 Assert.IsFalse (fnf.ToString ().IndexOf ("\"\"") != -1, "#B10");