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");
255 Assert.AreEqual (fnf.GetType ().FullName + ": message",
256 fnf.ToString (), "#A7");
258 fnf = new FileNotFoundException (string.Empty, (string) null);
261 Assert.IsNotNull (fnf.Data, "#B1");
263 Assert.IsNull (fnf.FileName, "#B2");
264 Assert.IsNull (fnf.InnerException, "#B3");
265 Assert.IsNotNull (fnf.Message, "#B4");
266 Assert.AreEqual (string.Empty, fnf.Message, "#B5");
267 Assert.IsNull (fnf.FusionLog, "#B6");
268 Assert.AreEqual (fnf.GetType ().FullName + ": ",
269 fnf.ToString (), "#B7");
273 public void Constructor4_FileNameAndMessage_Empty ()
275 FileNotFoundException fnf = new FileNotFoundException (string.Empty,
279 Assert.IsNotNull (fnf.Data, "#1");
281 Assert.IsNotNull (fnf.FileName, "#2");
282 Assert.AreEqual (string.Empty, fnf.FileName, "#3");
283 Assert.IsNull (fnf.InnerException, "#4");
284 Assert.IsNotNull (fnf.Message, "#5");
285 Assert.AreEqual (string.Empty, fnf.Message, "#6");
286 Assert.IsNull (fnf.FusionLog, "#7");
287 Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
291 public void Constructor4_FileNameAndMessage_Null ()
293 FileNotFoundException fnf = new FileNotFoundException ((string) null,
297 Assert.IsNotNull (fnf.Data, "#1");
299 Assert.IsNull (fnf.FileName, "#2");
300 Assert.IsNull (fnf.InnerException, "#3");
302 Assert.IsNull (fnf.Message, "#4");
304 Assert.IsNotNull (fnf.Message, "#4");
306 Assert.IsNull (fnf.FusionLog, "#5");
307 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
309 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
310 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
314 public void Constructor4_Message_Empty ()
316 FileNotFoundException fnf = null;
318 fnf = new FileNotFoundException (string.Empty, "file.txt");
321 Assert.IsNotNull (fnf.Data, "#1");
323 Assert.IsNotNull (fnf.FileName, "#2");
324 Assert.AreEqual ("file.txt", fnf.FileName, "#3");
325 Assert.IsNull (fnf.InnerException, "#4");
326 Assert.IsNotNull (fnf.Message, "#5");
327 Assert.AreEqual (string.Empty, fnf.Message, "#6");
328 Assert.IsNull (fnf.FusionLog, "#7");
329 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
330 + ": " + Environment.NewLine), "#8");
332 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
333 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
335 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
336 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
341 public void Constructor4_Message_Null ()
343 FileNotFoundException fnf = null;
345 fnf = new FileNotFoundException ((string) null, "file.txt");
348 Assert.IsNotNull (fnf.Data, "#A1");
350 Assert.IsNotNull (fnf.FileName, "#A2");
351 Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
352 Assert.IsNull (fnf.InnerException, "#A4");
353 Assert.IsNotNull (fnf.Message, "#A5");
354 Assert.IsNull (fnf.FusionLog, "#A6");
355 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
357 Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
359 Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
360 Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
362 Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
363 Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
366 fnf = new FileNotFoundException ((string) null, string.Empty);
369 Assert.IsNotNull (fnf.Data, "#B1");
371 Assert.IsNotNull (fnf.FileName, "#B2");
372 Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
373 Assert.IsNull (fnf.InnerException, "#B4");
374 // .NET 1.1: File or assembly name , or one of its dependencies ...
375 // .NET 2.0: Could not load file or assembly '' or one of its ...
376 Assert.IsNotNull (fnf.Message, "#B5");
377 Assert.IsNull (fnf.FusionLog, "#B6");
378 Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
380 Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
382 Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");
384 Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#B9");
385 Assert.IsFalse (fnf.ToString ().IndexOf ("\"\"") != -1, "#B10");