Merge pull request #944 from ermshiperete/bug-novell-496138
[mono.git] / mcs / class / corlib / Test / System.IO / FileTest.cs
1 //
2 // FileTest.cs: Test cases for System.IO.File
3 //
4 // Author: 
5 //     Duncan Mak (duncan@ximian.com)
6 //     Ville Palo (vi64pa@kolumbus.fi)
7 //
8 // (C) 2002 Ximian, Inc. http://www.ximian.com
9 //
10 // TODO: Find out why ArgumentOutOfRangeExceptions does not manage to close streams properly
11 //
12
13 using System;
14 using System.IO;
15 using System.Globalization;
16 using System.Threading;
17
18 using NUnit.Framework;
19
20 namespace MonoTests.System.IO
21 {
22         [TestFixture]
23         public class FileTest
24         {
25                 CultureInfo old_culture;
26                 static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
27
28                 [SetUp]
29                 public void SetUp ()
30                 {
31                         DeleteDirectory (TempFolder);
32                         Directory.CreateDirectory (TempFolder);
33                         old_culture = Thread.CurrentThread.CurrentCulture;
34                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false);
35                 }
36
37                 [TearDown]
38                 public void TearDown ()
39                 {
40                         DeleteDirectory (TempFolder);
41                         Thread.CurrentThread.CurrentCulture = old_culture;
42                 }
43
44                 string path;
45                 string testfile;
46
47                 [TestFixtureSetUp]
48                 public void FixtureSetUp ()
49                 {
50                         path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
51                         testfile = Path.Combine (path, "FileStreamTest.dat");
52                         File.WriteAllText (testfile, "1");
53                 }
54
55                 [TestFixtureTearDown]
56                 public void FixtureTearDown ()
57                 {
58                         if (File.Exists (testfile))
59                                 File.Delete (testfile);                 
60                 }
61
62                 [Test]
63                 public void TestExists ()
64                 {
65                         FileStream s = null;
66                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
67                         try {
68                                 Assert.IsFalse (File.Exists (null), "#1");
69                                 Assert.IsFalse (File.Exists (string.Empty), "#2");
70                                 Assert.IsFalse (File.Exists ("  \t\t  \t \n\t\n \n"), "#3");
71                                 DeleteFile (path);
72                                 s = File.Create (path);
73                                 s.Close ();
74                                 Assert.IsTrue (File.Exists (path), "#4");
75                                 Assert.IsFalse (File.Exists (TempFolder + Path.DirectorySeparatorChar + "doesnotexist"), "#5");
76                         } finally {
77                                 if (s != null)
78                                         s.Close ();
79                                 DeleteFile (path);
80                         }
81                 }
82
83                 [Test]
84                 public void Exists_InvalidFileName () 
85                 {
86                         Assert.IsFalse (File.Exists ("><|"), "#1");
87                         Assert.IsFalse (File.Exists ("?*"), "#2");
88                 }
89
90                 [Test]
91                 public void Exists_InvalidDirectory () 
92                 {
93                         Assert.IsFalse (File.Exists (Path.Combine ("does not exist", "file.txt")));
94                 }
95
96                 [Test]
97                 public void Create_Path_Null ()
98                 {
99                         try {
100                                 File.Create (null);
101                                 Assert.Fail ("#1");
102                         } catch (ArgumentNullException ex) {
103                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
104                                 Assert.IsNull (ex.InnerException, "#3");
105                                 Assert.IsNotNull (ex.Message, "#4");
106                                 Assert.AreEqual ("path", ex.ParamName, "#5");
107                         }
108                 }
109
110                 [Test]
111                 public void Create_Path_Directory ()
112                 {
113                         string path = Path.Combine (TempFolder, "foo");
114                         Directory.CreateDirectory (path);
115                         try {
116                                 File.Create (path);
117                                 Assert.Fail ("#1");
118                         } catch (UnauthorizedAccessException ex) {
119                                 // Access to the path '...' is denied
120                                 Assert.AreEqual (typeof (UnauthorizedAccessException), ex.GetType (), "#2");
121                                 Assert.IsNull (ex.InnerException, "#3");
122                                 Assert.IsNotNull (ex.Message, "#4");
123                                 Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
124                         } finally {
125                                 DeleteDirectory (path);
126                         }
127                 }
128
129                 [Test]
130                 public void Create_Path_Empty ()
131                 {
132                         try {
133                                 File.Create (string.Empty);
134                                 Assert.Fail ("#1");
135                         } catch (ArgumentException ex) {
136                                 // Empty file name is not legal
137                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
138                                 Assert.IsNull (ex.InnerException, "#3");
139                                 Assert.IsNotNull (ex.Message, "#4");
140                                 Assert.IsNull (ex.ParamName, "#5");
141                         }
142                 }
143
144                 [Test]
145                 public void Create_Path_ReadOnly ()
146                 {
147                         string path = Path.Combine (TempFolder, "foo");
148                         File.Create (path).Close ();
149                         File.SetAttributes (path, FileAttributes.ReadOnly);
150                         try {
151                                 File.Create (path);
152                                 Assert.Fail ("#1");
153                         } catch (UnauthorizedAccessException ex) {
154                                 // Access to the path '...' is denied
155                                 Assert.AreEqual (typeof (UnauthorizedAccessException), ex.GetType (), "#2");
156                                 Assert.IsNull (ex.InnerException, "#3");
157                                 Assert.IsNotNull (ex.Message, "#4");
158                                 Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
159                         } finally {
160                                 File.SetAttributes (path, FileAttributes.Normal);
161                         }
162                 }
163
164                 [Test]
165                 public void Create_Path_Whitespace ()
166                 {
167                         try {
168                                 File.Create (" ");
169                                 Assert.Fail ("#1");
170                         } catch (ArgumentException ex) {
171                                 // The path is not of a legal form
172                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
173                                 Assert.IsNull (ex.InnerException, "#3");
174                                 Assert.IsNotNull (ex.Message, "#4");
175                                 Assert.IsNull (ex.ParamName, "#5");
176                         }
177                 }
178
179                 [Test]
180                 public void Create_Directory_DoesNotExist ()
181                 {
182                         FileStream stream = null;
183                         string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
184                         
185                         try {
186                                 stream = File.Create (path);
187                                 Assert.Fail ("#1");
188                         } catch (DirectoryNotFoundException ex) {
189                                 // Could not find a part of the path "..."
190                                 Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
191                                 Assert.IsNull (ex.InnerException, "#3");
192                                 Assert.IsNotNull (ex.Message, "#4");
193                                 Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
194                         } finally {
195                                 if (stream != null)
196                                         stream.Close ();
197                                 DeleteFile (path);
198                         }
199                 }
200
201                 [Test]
202                 public void Create ()
203                 {
204                         FileStream stream = null;
205                         string path = null;
206
207                         /* positive test: create resources/foo */
208                         path = TempFolder + Path.DirectorySeparatorChar + "foo";
209                         try {
210
211                                 stream = File.Create (path);
212                                 Assert.IsTrue (File.Exists (path), "#1");
213                                 stream.Close ();
214                         } finally {
215                                 if (stream != null)
216                                         stream.Close ();
217                                 DeleteFile (path);
218                         }
219
220                         stream = null;
221
222                         /* positive test: repeat test above again to test for overwriting file */
223                         path = TempFolder + Path.DirectorySeparatorChar + "foo";
224                         try {
225                                 stream = File.Create (path);
226                                 Assert.IsTrue (File.Exists (path), "#2");
227                                 stream.Close ();
228                         } finally {
229                                 if (stream != null)
230                                         stream.Close ();
231                                 DeleteFile (path);
232                         }
233                 }
234
235                 [Test]
236                 public void Copy_SourceFileName_Null ()
237                 {
238                         try {
239                                 File.Copy (null, "b");
240                                 Assert.Fail ("#1");
241                         } catch (ArgumentNullException ex) {
242                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
243                                 Assert.IsNull (ex.InnerException, "#3");
244                                 Assert.IsNotNull (ex.Message, "#4");
245                                 Assert.AreEqual ("sourceFileName", ex.ParamName, "#5");
246                         }
247                 }
248
249                 [Test]
250                 public void Copy_DestFileName_Null ()
251                 {
252                         try {
253                                 File.Copy ("a", null);
254                                 Assert.Fail ("#1");
255                         } catch (ArgumentNullException ex) {
256                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
257                                 Assert.IsNull (ex.InnerException, "#3");
258                                 Assert.IsNotNull (ex.Message, "#4");
259                                 Assert.AreEqual ("destFileName", ex.ParamName, "#5");
260                         }
261                 }
262
263                 [Test]
264                 public void Copy_SourceFileName_Empty ()
265                 {
266                         try {
267                                 File.Copy (string.Empty, "b");
268                                 Assert.Fail ("#1");
269                         } catch (ArgumentException ex) {
270                                 // Empty file name is not legal
271                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
272                                 Assert.IsNull (ex.InnerException, "#3");
273                                 Assert.IsNotNull (ex.Message, "#4");
274                                 Assert.AreEqual ("sourceFileName", ex.ParamName, "#5");
275                         }
276                 }
277
278                 [Test]
279                 public void Copy_DestFileName_Empty ()
280                 {
281                         try {
282                                 File.Copy ("a", string.Empty);
283                                 Assert.Fail ("#1");
284                         } catch (ArgumentException ex) {
285                                 // Empty file name is not legal
286                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
287                                 Assert.IsNull (ex.InnerException, "#3");
288                                 Assert.IsNotNull (ex.Message, "#4");
289                                 Assert.AreEqual ("destFileName", ex.ParamName, "#5");
290                         }
291                 }
292
293                 [Test]
294                 public void Copy_SourceFileName_Whitespace ()
295                 {
296                         try {
297                                 File.Copy (" ", "b");
298                                 Assert.Fail ("#1");
299                         } catch (ArgumentException ex) {
300                                 // The path is not of a legal form
301                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
302                                 Assert.IsNull (ex.InnerException, "#3");
303                                 Assert.IsNotNull (ex.Message, "#4");
304                                 Assert.IsNull (ex.ParamName, "#5");
305                         }
306                 }
307
308                 [Test]
309                 public void Copy_DestFileName_Whitespace ()
310                 {
311                         try {
312                                 File.Copy ("a", " ");
313                                 Assert.Fail ("#1");
314                         } catch (ArgumentException ex) {
315                                 // The path is not of a legal form
316                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
317                                 Assert.IsNull (ex.InnerException, "#3");
318                                 Assert.IsNotNull (ex.Message, "#4");
319                                 Assert.IsNull (ex.ParamName, "#5");
320                         }
321                 }
322
323                 [Test]
324                 public void Copy_SourceFileName_DoesNotExist ()
325                 {
326                         try {
327                                 File.Copy ("doesnotexist", "b");
328                                 Assert.Fail ("#1");
329                         } catch (FileNotFoundException ex) {
330                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
331                                 Assert.AreEqual ("doesnotexist", ex.FileName, "#3");
332                                 Assert.IsNull (ex.InnerException, "#4");
333                                 Assert.IsNotNull (ex.Message, "#5");
334                         }
335                 }
336
337                 [Test]
338                 public void Copy_DestFileName_AlreadyExists ()
339                 {
340                         string source = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
341                         string dest = TempFolder + Path.DirectorySeparatorChar + "bar";
342                         DeleteFile (source);
343                         DeleteFile (dest);
344                         try {
345                                 File.Create (source).Close ();
346                                 File.Copy (source, dest);
347                                 try {
348                                         File.Copy (source, dest);
349                                         Assert.Fail ("#1");
350                                 } catch (IOException ex) {
351                                         // The file '...' already exists.
352                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
353                                         Assert.IsNull (ex.InnerException, "#3");
354                                         Assert.IsNotNull (ex.Message, "#4");
355                                         Assert.IsTrue (ex.Message.IndexOf (dest) != -1, "#5");
356                                 }
357                         } finally {
358                                 DeleteFile (dest);
359                                 DeleteFile (source);
360                         }
361                 }
362
363                 [Test]
364                 public void Copy_SourceFileName_DestFileName_Same ()
365                 {
366                         string source = TempFolder + Path.DirectorySeparatorChar + "SameFile.txt";
367                         DeleteFile (source);
368                         try {
369                                 // new empty file
370                                 File.Create (source).Close ();
371                                 try {
372                                         File.Copy (source, source, true);
373                                         Assert.Fail ("#1");
374                                 } catch (IOException ex) {
375                                         // process cannot access file ... because it is being used by another process
376                                         Assert.IsNull (ex.InnerException, "#2");
377                                         Assert.IsTrue (ex.Message.IndexOf (source) != -1, "#3");
378                                 }
379                         } finally {
380                                 DeleteFile (source);
381                         }
382                 }
383
384                 [Test]
385                 public void Copy ()
386                 {
387                         string path1 = TempFolder + Path.DirectorySeparatorChar + "bar";
388                         string path2 = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
389                         /* positive test: copy resources/AFile.txt to resources/bar */
390                         try {
391                                 DeleteFile (path1);
392                                 DeleteFile (path2);
393
394                                 File.Create (path2).Close ();
395                                 File.Copy (path2, path1);
396                                 Assert.IsTrue (File.Exists (path2), "#A1");
397                                 Assert.IsTrue (File.Exists (path1), "#A2");
398
399                                 Assert.IsTrue (File.Exists (path1), "#B1");
400                                 File.Copy (path2, path1, true);
401                                 Assert.IsTrue (File.Exists (path2), "#B2");
402                                 Assert.IsTrue (File.Exists (path1), "#B3");
403                         } finally {
404                                 DeleteFile (path1);
405                                 DeleteFile (path2);
406                         }
407                 }
408
409                 [Test]
410                 public void Delete_Path_Null ()
411                 {
412                         try {
413                                 File.Delete (null);
414                                 Assert.Fail ("#1");
415                         } catch (ArgumentNullException ex) {
416                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
417                                 Assert.IsNull (ex.InnerException, "#3");
418                                 Assert.IsNotNull (ex.Message, "#4");
419                                 Assert.AreEqual ("path", ex.ParamName, "#5");
420                         }
421                 }
422
423                 [Test]
424                 public void Delete_Path_Empty ()
425                 {
426                         try {
427                                 File.Delete (string.Empty);
428                                 Assert.Fail ("#1");
429                         } catch (ArgumentException ex) {
430                                 // Empty file name is not legal
431                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
432                                 Assert.IsNull (ex.InnerException, "#3");
433                                 Assert.IsNotNull (ex.Message, "#4");
434                                 Assert.IsNull (ex.ParamName, "#5");
435                         }
436                 }
437
438                 [Test]
439                 public void Delete_Path_Whitespace ()
440                 {
441                         try {
442                                 File.Delete (" ");
443                                 Assert.Fail ("#1");
444                         } catch (ArgumentException ex) {
445                                 // The path is not of a legal form
446                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
447                                 Assert.IsNull (ex.InnerException, "#3");
448                                 Assert.IsNotNull (ex.Message, "#4");
449                                 Assert.IsNull (ex.ParamName, "#5");
450                         }
451                 }
452
453                 [Test]
454                 public void Delete_Directory_DoesNotExist ()
455                 {
456                         string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
457                         if (Directory.Exists (path))
458                                 Directory.Delete (path, true);
459
460                         try {
461                                 File.Delete (path);
462                                 Assert.Fail ("#1");
463                         } catch (DirectoryNotFoundException ex) {
464                                 // Could not find a part of the path "..."
465                                 Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
466                                 Assert.IsNull (ex.InnerException, "#3");
467                                 Assert.IsNotNull (ex.Message, "#4");
468                                 Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
469                         }
470                 }
471
472                 [Test]
473                 public void Delete ()
474                 {
475                         string foopath = TempFolder + Path.DirectorySeparatorChar + "foo";
476                         DeleteFile (foopath);
477                         try {
478                                 File.Create (foopath).Close ();
479                                 File.Delete (foopath);
480                                 Assert.IsFalse (File.Exists (foopath));
481                                 File.Delete (foopath);
482                         } finally {
483                                 DeleteFile (foopath);
484                         }
485                 }
486
487                 [Test] // bug #323389
488                 [Category ("NotWorking")]
489                 public void Delete_FileLock ()
490                 {
491                         string path = TempFolder + Path.DirectorySeparatorChar + "DeleteOpenStreamException";
492                         DeleteFile (path);
493                         FileStream stream = null;
494                         try {
495                                 stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
496                                 try {
497                                         File.Delete (path);
498                                         Assert.Fail ("#1");
499                                 } catch (IOException ex) {
500                                         // The process cannot access the file '...'
501                                         // because it is being used by another process
502                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
503                                         Assert.IsNull (ex.InnerException, "#3");
504                                         Assert.IsNotNull (ex.Message, "#4");
505                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
506                                 }
507                         } finally {
508                                 if (stream != null)
509                                         stream.Close ();
510                                 DeleteFile (path);
511                         }
512                 }
513
514                 [Test]
515                 [ExpectedException (typeof(UnauthorizedAccessException))]
516                 public void Delete_File_ReadOnly ()
517                 {
518                         if (RunningOnUnix)
519                                 Assert.Ignore ("ReadOnly files can be deleted on unix since fdef50957f508627928c7876a905d5584da45748.");
520
521                         string path = TempFolder + Path.DirectorySeparatorChar + "DeleteReadOnly";
522                         DeleteFile (path);
523                         try {
524                                 File.Create (path).Close ();
525                                 File.SetAttributes (path, FileAttributes.ReadOnly);
526                                 File.Delete (path);
527                         } finally {
528                                 File.SetAttributes (path, FileAttributes.Normal);
529                                 DeleteFile (path);
530                         }
531                 }
532
533                 [Test]
534                 public void GetAttributes_Archive ()
535                 {
536                         if (RunningOnUnix)
537                                 Assert.Ignore ("bug #325181: FileAttributes.Archive has no effect on Unix.");
538
539                         FileAttributes attrs;
540
541                         string path = Path.Combine (TempFolder, "GetAttributes.tmp");
542                         File.Create (path).Close ();
543
544                         attrs = File.GetAttributes (path);
545                         Assert.IsTrue ((attrs & FileAttributes.Archive) != 0, "#1");
546
547                         attrs &= ~FileAttributes.Archive;
548                         File.SetAttributes (path, attrs);
549
550                         attrs = File.GetAttributes (path);
551                         Assert.IsFalse ((attrs & FileAttributes.Archive) != 0, "#2");
552                 }
553
554                 [Test]
555                 public void GetAttributes_Default_File ()
556                 {
557                         if (RunningOnUnix)
558                                 Assert.Ignore ("bug #325181: FileAttributes.Archive has no effect on Unix.");
559
560                         string path = Path.Combine (TempFolder, "GetAttributes.tmp");
561                         File.Create (path).Close ();
562
563                         FileAttributes attrs = File.GetAttributes (path);
564
565                         Assert.IsTrue ((attrs & FileAttributes.Archive) != 0, "#1");
566                         Assert.IsFalse ((attrs & FileAttributes.Directory) != 0, "#2");
567                         Assert.IsFalse ((attrs & FileAttributes.Hidden) != 0, "#3");
568                         Assert.IsFalse ((attrs & FileAttributes.Normal) != 0, "#4");
569                         Assert.IsFalse ((attrs & FileAttributes.ReadOnly) != 0, "#5");
570                         Assert.IsFalse ((attrs & FileAttributes.System) != 0, "#6");
571                 }
572
573                 [Test]
574                 public void GetAttributes_Default_Directory ()
575                 {
576                         FileAttributes attrs = File.GetAttributes (TempFolder);
577
578                         Assert.IsFalse ((attrs & FileAttributes.Archive) != 0, "#1");
579                         Assert.IsTrue ((attrs & FileAttributes.Directory) != 0, "#2");
580                         Assert.IsFalse ((attrs & FileAttributes.Hidden) != 0, "#3");
581                         Assert.IsFalse ((attrs & FileAttributes.Normal) != 0, "#4");
582                         Assert.IsFalse ((attrs & FileAttributes.ReadOnly) != 0, "#5");
583                         Assert.IsFalse ((attrs & FileAttributes.System) != 0, "#6");
584                 }
585
586                 [Test]
587                 public void GetAttributes_Directory ()
588                 {
589                         FileAttributes attrs = File.GetAttributes (TempFolder);
590
591                         Assert.IsTrue ((attrs & FileAttributes.Directory) != 0, "#1");
592
593                         attrs &= ~FileAttributes.Directory;
594                         File.SetAttributes (TempFolder, attrs);
595
596                         Assert.IsFalse ((attrs & FileAttributes.Directory) != 0, "#2");
597
598                         string path = Path.Combine (TempFolder, "GetAttributes.tmp");
599                         File.Create (path).Close ();
600
601                         attrs = File.GetAttributes (path);
602                         attrs |= FileAttributes.Directory;
603                         File.SetAttributes (path, attrs);
604
605                         Assert.IsTrue ((attrs & FileAttributes.Directory) != 0, "#3");
606                 }
607
608                 [Test]
609                 public void GetAttributes_ReadOnly ()
610                 {
611                         FileAttributes attrs;
612
613                         string path = Path.Combine (TempFolder, "GetAttributes.tmp");
614                         File.Create (path).Close ();
615
616                         attrs = File.GetAttributes (path);
617                         Assert.IsFalse ((attrs & FileAttributes.ReadOnly) != 0, "#1");
618
619                         try {
620                                 attrs |= FileAttributes.ReadOnly;
621                                 File.SetAttributes (path, attrs);
622
623                                 attrs = File.GetAttributes (path);
624                                 Assert.IsTrue ((attrs & FileAttributes.ReadOnly) != 0, "#2");
625                         } finally {
626                                 File.SetAttributes (path, FileAttributes.Normal);
627                         }
628                 }
629
630                 [Test]
631                 public void GetAttributes_System ()
632                 {
633                         if (RunningOnUnix)
634                                 Assert.Ignore ("FileAttributes.System is not supported on Unix.");
635
636                         FileAttributes attrs;
637
638                         string path = Path.Combine (TempFolder, "GetAttributes.tmp");
639                         File.Create (path).Close ();
640
641                         attrs = File.GetAttributes (path);
642                         Assert.IsFalse ((attrs & FileAttributes.System) != 0, "#1");
643
644                         attrs |= FileAttributes.System;
645                         File.SetAttributes (path, FileAttributes.System);
646
647                         attrs = File.GetAttributes (path);
648                         Assert.IsTrue ((attrs & FileAttributes.System) != 0, "#2");
649                 }
650
651                 [Test]
652                 public void GetAttributes_Path_DoesNotExist ()
653                 {
654                         string path = Path.Combine (TempFolder, "GetAttributes.tmp");
655                         try {
656                                 File.GetAttributes (path);
657                                 Assert.Fail ("#1");
658                         } catch (FileNotFoundException ex) {
659                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
660                                 Assert.AreEqual (path, ex.FileName, "#3");
661                                 Assert.IsNull (ex.InnerException, "#4");
662                                 Assert.IsNotNull (ex.Message, "#5");
663                         }
664                 }
665
666                 [Test]
667                 public void GetAttributes_Path_Empty ()
668                 {
669                         try {
670                                 File.GetAttributes (string.Empty);
671                                 Assert.Fail ("#1");
672                         } catch (ArgumentException ex) {
673                                 // Empty file name is not legal
674                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
675                                 Assert.IsNull (ex.InnerException, "#3");
676                                 Assert.IsNotNull (ex.Message, "#4");
677                                 Assert.IsNull (ex.ParamName, "#5");
678                         }
679                 }
680
681                 [Test]
682                 public void GetAttributes_Path_Null ()
683                 {
684                         try {
685                                 File.GetAttributes (null);
686                                 Assert.Fail ("#1");
687                         } catch (ArgumentNullException ex) {
688                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
689                                 Assert.IsNull (ex.InnerException, "#3");
690                                 Assert.IsNotNull (ex.Message, "#4");
691                                 Assert.AreEqual ("path", ex.ParamName, "#5");
692                         }
693                 }
694
695                 [Test]
696                 public void Move_SourceFileName_Null ()
697                 {
698                         try {
699                                 File.Move (null, "b");
700                                 Assert.Fail ("#1");
701                         } catch (ArgumentNullException ex) {
702                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
703                                 Assert.IsNull (ex.InnerException, "#3");
704                                 Assert.IsNotNull (ex.Message, "#4");
705                                 Assert.AreEqual ("sourceFileName", ex.ParamName, "#5");
706                         }
707                 }
708
709                 [Test]
710                 public void Move_DestFileName_Null ()
711                 {
712                         try {
713                                 File.Move ("a", null);
714                                 Assert.Fail ("#1");
715                         } catch (ArgumentNullException ex) {
716                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
717                                 Assert.IsNull (ex.InnerException, "#3");
718                                 Assert.IsNotNull (ex.Message, "#4");
719                                 Assert.AreEqual ("destFileName", ex.ParamName, "#5");
720                         }
721                 }
722
723                 [Test]
724                 public void Move_SourceFileName_Empty ()
725                 {
726                         try {
727                                 File.Move (string.Empty, "b");
728                                 Assert.Fail ("#1");
729                         } catch (ArgumentException ex) {
730                                 // Empty file name is not legal
731                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
732                                 Assert.IsNull (ex.InnerException, "#3");
733                                 Assert.IsNotNull (ex.Message, "#4");
734                                 Assert.AreEqual ("sourceFileName", ex.ParamName, "#5");
735                         }
736                 }
737
738                 [Test]
739                 public void Move_DestFileName_Empty ()
740                 {
741                         try {
742                                 File.Move ("a", string.Empty);
743                                 Assert.Fail ("#1");
744                         } catch (ArgumentException ex) {
745                                 // Empty file name is not legal
746                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
747                                 Assert.IsNull (ex.InnerException, "#3");
748                                 Assert.IsNotNull (ex.Message, "#4");
749                                 Assert.AreEqual ("destFileName", ex.ParamName, "#5");
750                         }
751                 }
752
753                 [Test]
754                 public void Move_SourceFileName_Whitespace ()
755                 {
756                         try {
757                                 File.Move (" ", "b");
758                                 Assert.Fail ("#1");
759                         } catch (ArgumentException ex) {
760                                 // The path is not of a legal form
761                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
762                                 Assert.IsNull (ex.InnerException, "#3");
763                                 Assert.IsNotNull (ex.Message, "#4");
764                                 Assert.IsNull (ex.ParamName, "#5");
765                         }
766                 }
767
768                 [Test]
769                 public void Move_DestFileName_Whitespace ()
770                 {
771                         try {
772                                 File.Move ("a", " ");
773                                 Assert.Fail ("#1");
774                         } catch (ArgumentException ex) {
775                                 // The path is not of a legal form
776                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
777                                 Assert.IsNull (ex.InnerException, "#3");
778                                 Assert.IsNotNull (ex.Message, "#4");
779                                 Assert.IsNull (ex.ParamName, "#5");
780                         }
781                 }
782
783                 [Test]
784                 public void Move_SourceFileName_DoesNotExist ()
785                 {
786                         string file = TempFolder + Path.DirectorySeparatorChar + "doesnotexist";
787                         DeleteFile (file);
788                         try {
789                                 File.Move (file, "b");
790                                 Assert.Fail ("#1");
791                         } catch (FileNotFoundException ex) {
792                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
793                                 Assert.AreEqual (file, ex.FileName, "#3");
794                                 Assert.IsNull (ex.InnerException, "#4");
795                                 Assert.IsNotNull (ex.Message, "#5");
796                         }
797                 }
798
799                 [Test]
800                 public void Move_DestFileName_DirectoryDoesNotExist ()
801                 {
802                         string sourceFile = TempFolder + Path.DirectorySeparatorChar + "foo";
803                         string destFile = Path.Combine (Path.Combine (TempFolder, "doesnotexist"), "b");
804                         DeleteFile (sourceFile);
805                         try {
806                                 File.Create (sourceFile).Close ();
807                                 try {
808                                         File.Move (sourceFile, destFile);
809                                         Assert.Fail ("#1");
810                                 } catch (DirectoryNotFoundException ex) {
811                                         // Could not find a part of the path
812                                         Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
813                                         Assert.IsNull (ex.InnerException, "#3");
814                                         Assert.IsNotNull (ex.Message, "#4");
815 #if NET_2_0
816                                         Assert.IsFalse (ex.Message.IndexOf (destFile) != -1, "#5");
817 #else
818                                         Assert.IsTrue (ex.Message.IndexOf (destFile) != -1, "#5");
819 #endif
820                                 }
821                         } finally {
822                                 DeleteFile (sourceFile);
823                         }
824                 }
825
826                 [Test]
827                 public void Move_DestFileName_AlreadyExists ()
828                 {
829                         string sourceFile = TempFolder + Path.DirectorySeparatorChar + "foo";
830                         string destFile;
831
832                         // move to same directory
833                         File.Create (sourceFile).Close ();
834                         try {
835                                 File.Move (sourceFile, TempFolder);
836                                 Assert.Fail ("#A1");
837                         } catch (IOException ex) {
838                                 // Cannot create a file when that file already exists
839                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
840                                 Assert.IsNull (ex.InnerException, "#A3");
841                                 Assert.IsNotNull (ex.Message, "#A4");
842                                 Assert.IsFalse (ex.Message.IndexOf (sourceFile) != -1, "#A5");
843                                 Assert.IsFalse (ex.Message.IndexOf (TempFolder) != -1, "#A6");
844                         } finally {
845                                 DeleteFile (sourceFile);
846                         }
847
848                         // move to exist file
849                         File.Create (sourceFile).Close ();
850                         destFile = TempFolder + Path.DirectorySeparatorChar + "bar";
851                         File.Create (destFile).Close ();
852                         try {
853                                 File.Move (sourceFile, destFile);
854                                 Assert.Fail ("#B1");
855                         } catch (IOException ex) {
856                                 // Cannot create a file when that file already exists
857                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#B2");
858                                 Assert.IsNull (ex.InnerException, "#B3");
859                                 Assert.IsNotNull (ex.Message, "#B4");
860                                 Assert.IsFalse (ex.Message.IndexOf (sourceFile) != -1, "#B5");
861                                 Assert.IsFalse (ex.Message.IndexOf (destFile) != -1, "#B6");
862                         } finally {
863                                 DeleteFile (sourceFile);
864                                 DeleteFile (destFile);
865                         }
866
867                         // move to existing directory
868                         File.Create (sourceFile).Close ();
869                         destFile = TempFolder + Path.DirectorySeparatorChar + "bar";
870                         Directory.CreateDirectory (destFile);
871                         try {
872                                 File.Move (sourceFile, destFile);
873                                 Assert.Fail ("#C1");
874                         } catch (IOException ex) {
875                                 // Cannot create a file when that file already exists
876                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#C2");
877                                 Assert.IsNull (ex.InnerException, "#C3");
878                                 Assert.IsNotNull (ex.Message, "#C4");
879                                 Assert.IsFalse (ex.Message.IndexOf (sourceFile) != -1, "#C5");
880                                 Assert.IsFalse (ex.Message.IndexOf (destFile) != -1, "#C6");
881                         } finally {
882                                 DeleteFile (sourceFile);
883                                 DeleteDirectory (destFile);
884                         }
885                 }
886
887                 [Test]
888                 public void Move ()
889                 {
890                         string bar = TempFolder + Path.DirectorySeparatorChar + "bar";
891                         string baz = TempFolder + Path.DirectorySeparatorChar + "baz";
892                         if (!File.Exists (bar)) {
893                                 FileStream f = File.Create(bar);
894                                 f.Close();
895                         }
896                         
897                         Assert.IsTrue (File.Exists (bar), "#1");
898                         File.Move (bar, baz);
899                         Assert.IsFalse (File.Exists (bar), "#2");
900                         Assert.IsTrue (File.Exists (baz), "#3");
901
902                         // Test moving of directories
903                         string dir = Path.Combine (TempFolder, "dir");
904                         string dir2 = Path.Combine (TempFolder, "dir2");
905                         string dir_foo = Path.Combine (dir, "foo");
906                         string dir2_foo = Path.Combine (dir2, "foo");
907
908                         if (Directory.Exists (dir))
909                                 Directory.Delete (dir, true);
910
911                         Directory.CreateDirectory (dir);
912                         Directory.CreateDirectory (dir2);
913                         File.Create (dir_foo).Close ();
914                         File.Move (dir_foo, dir2_foo);
915                         Assert.IsTrue (File.Exists (dir2_foo), "#4");
916                         
917                         Directory.Delete (dir, true);
918                         Directory.Delete (dir2, true);
919                         DeleteFile (dir_foo);
920                         DeleteFile (dir2_foo);
921                 }
922
923                 [Test]
924                 public void Move_FileLock ()
925                 {
926                         string sourceFile = Path.GetTempFileName ();
927                         string destFile = Path.GetTempFileName ();
928
929                         // source file locked
930                         using (File.Open (sourceFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) {
931                                 try {
932                                         File.Move (sourceFile, destFile);
933                                         Assert.Fail ("#A1");
934                                 } catch (IOException ex) {
935                                         // The process cannot access the file because
936                                         // it is being used by another process
937                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
938                                         Assert.IsNull (ex.InnerException, "#A3");
939                                         Assert.IsNotNull (ex.Message, "#A4");
940                                 }
941                         }
942
943                         // destination file locked
944                         using (File.Open (destFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) {
945                                 try {
946                                         File.Move (sourceFile, destFile);
947                                         Assert.Fail ("#B1");
948                                 } catch (IOException ex) {
949                                         // The process cannot access the file because
950                                         // it is being used by another process
951                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#B2");
952                                         Assert.IsNull (ex.InnerException, "#B3");
953                                         Assert.IsNotNull (ex.Message, "#B4");
954                                 }
955                         }
956                 }
957
958                 [Test]
959                 public void Open ()
960                 {
961                         string path = null;
962                         FileStream stream = null;
963
964                         path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
965                         try {
966                                 if (!File.Exists (path))
967                                         stream = File.Create (path);
968                                 stream.Close ();
969                                 stream = File.Open (path, FileMode.Open);
970                                 stream.Close ();
971                         } finally {
972                                 if (stream != null)
973                                         stream.Close ();
974                                 DeleteFile (path);
975                         }
976
977                         stream = null;
978
979                         if (!File.Exists (path))
980                                 File.Create (path).Close ();
981                         try {
982                                 stream = File.Open (path, FileMode.Open);
983                                 Assert.IsTrue (stream.CanRead, "#A1");
984                                 Assert.IsTrue (stream.CanSeek, "#A2");
985                                 Assert.IsTrue (stream.CanWrite, "#A3");
986                                 stream.Close ();
987
988                                 stream = File.Open (path, FileMode.Open, FileAccess.Write);
989                                 Assert.IsFalse (stream.CanRead, "#B1");
990                                 Assert.IsTrue (stream.CanSeek, "#B2");
991                                 Assert.IsTrue (stream.CanWrite, "#B3");
992                                 stream.Close ();
993
994                                 stream = File.Open (path, FileMode.Open, FileAccess.Read);
995                                 Assert.IsTrue (stream.CanRead, "#C1");
996                                 Assert.IsTrue (stream.CanSeek, "#C2");
997                                 Assert.IsFalse (stream.CanWrite, "#C3");
998                                 stream.Close ();
999                         } finally {
1000                                 if (stream != null)
1001                                         stream.Close ();
1002                                 DeleteFile (path);
1003                         }
1004
1005                         stream = null;
1006
1007                         /* Exception tests */
1008                         path = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
1009                         try {
1010                                 stream = File.Open (path, FileMode.Open);
1011                                 Assert.Fail ("#D1");
1012                         } catch (FileNotFoundException ex) {
1013                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#D2");
1014                                 Assert.AreEqual (path, ex.FileName, "#D3");
1015                                 Assert.IsNull (ex.InnerException, "#D4");
1016                                 Assert.IsNotNull (ex.Message, "#D5");
1017                         } finally {
1018                                 if (stream != null)
1019                                         stream.Close ();
1020                                 DeleteFile (path);
1021                         }
1022                 }
1023
1024                 [Test]
1025                 public void Open_CreateNewMode_ReadAccess ()
1026                 {
1027                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
1028                         FileStream stream = null;
1029                         try {
1030                                 stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.CreateNew, FileAccess.Read);
1031                                 Assert.Fail ("#1");
1032                         } catch (ArgumentException ex) {
1033                                 // Combining FileMode: CreateNew with FileAccess: Read is invalid
1034                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1035                                 Assert.IsNull (ex.InnerException, "#3");
1036                                 Assert.IsNotNull (ex.Message, "#4");
1037                                 Assert.IsNull (ex.ParamName, "#5");
1038                         } finally {
1039                                 if (stream != null)
1040                                         stream.Close ();
1041                                 DeleteFile (path);
1042                         }
1043                 }
1044
1045                 [Test]
1046                 public void Open_AppendMode_ReadAccess ()
1047                 {
1048                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
1049                         FileStream s = null;
1050                         if (!File.Exists (path))
1051                                 File.Create (path).Close ();
1052                         try {
1053                                 s = File.Open (path, FileMode.Append, FileAccess.Read);
1054                                 Assert.Fail ("#1");
1055                         } catch (ArgumentException ex) {
1056                                 // Combining FileMode: Append with FileAccess: Read is invalid
1057                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1058                                 Assert.IsNull (ex.InnerException, "#3");
1059                                 Assert.IsNotNull (ex.Message, "#4");
1060                                 Assert.IsNull (ex.ParamName, "#5");
1061                         } finally {
1062                                 if (s != null)
1063                                         s.Close ();
1064                                 DeleteFile (path);
1065                         }
1066                 }
1067
1068                 [Test]
1069                 public void OpenRead ()
1070                 {
1071                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
1072                         if (!File.Exists (path))
1073                                 File.Create (path).Close ();
1074                         FileStream stream = null;
1075                         
1076                         try {
1077                                 stream = File.OpenRead (path);
1078                                 Assert.IsTrue (stream.CanRead, "#1");
1079                                 Assert.IsTrue (stream.CanSeek, "#2");
1080                                 Assert.IsFalse (stream.CanWrite, "#3");
1081                         } finally {
1082                                 if (stream != null)
1083                                         stream.Close ();
1084                                 DeleteFile (path);
1085                         }
1086                 }
1087
1088                 [Test]
1089                 public void OpenWrite ()
1090                 {
1091                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
1092                         if (!File.Exists (path))
1093                                 File.Create (path).Close ();
1094                         FileStream stream = null;
1095
1096                         try {
1097                                 stream = File.OpenWrite (path);
1098                                 Assert.IsFalse (stream.CanRead, "#1");
1099                                 Assert.IsTrue (stream.CanSeek, "#2");
1100                                 Assert.IsTrue (stream.CanWrite, "#3");
1101                                 stream.Close ();
1102                         } finally {
1103                                 if (stream != null)
1104                                         stream.Close ();
1105                                 DeleteFile (path);
1106                         }
1107                 }
1108
1109                 [Test]
1110                 public void TestGetCreationTime ()
1111                 {
1112                         string path = TempFolder + Path.DirectorySeparatorChar + "baz";
1113                         DeleteFile (path);
1114
1115                         try {
1116                                 File.Create (path).Close();
1117                                 DateTime time = File.GetCreationTime (path);
1118                                 Assert.IsTrue ((DateTime.Now - time).TotalSeconds < 10);
1119                         } finally {
1120                                 DeleteFile (path);
1121                         }
1122                 }
1123
1124                 [Test]
1125                 public void CreationTime ()
1126                 {
1127                         if (RunningOnUnix)
1128                                 Assert.Ignore ("Setting the creation time on Unix is not possible.");
1129
1130                         string path = Path.GetTempFileName ();
1131                         try {
1132                                 File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
1133                                 DateTime time = File.GetCreationTime (path);
1134                                 Assert.AreEqual (2002, time.Year, "#A1");
1135                                 Assert.AreEqual (4, time.Month, "#A2");
1136                                 Assert.AreEqual (6, time.Day, "#A3");
1137                                 Assert.AreEqual (4, time.Hour, "#A4");
1138                                 Assert.AreEqual (4, time.Second, "#A5");
1139
1140                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
1141                                 Assert.AreEqual (2002, time.Year, "#B1");
1142                                 Assert.AreEqual (4, time.Month, "#B2");
1143                                 Assert.AreEqual (6, time.Day, "#B3");
1144                                 Assert.AreEqual (4, time.Hour, "#B4");
1145                                 Assert.AreEqual (4, time.Second, "#B5");
1146
1147                                 File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
1148                                 time = File.GetCreationTimeUtc (path);
1149                                 Assert.AreEqual (2002, time.Year, "#C1");
1150                                 Assert.AreEqual (4, time.Month, "#C2");
1151                                 Assert.AreEqual (6, time.Day, "#C3");
1152                                 Assert.AreEqual (4, time.Hour, "#C4");
1153                                 Assert.AreEqual (4, time.Second, "#C5");
1154
1155                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
1156                                 Assert.AreEqual (2002, time.Year, "#D1");
1157                                 Assert.AreEqual (4, time.Month, "#D2");
1158                                 Assert.AreEqual (6, time.Day, "#D3");
1159                                 Assert.AreEqual (4, time.Hour, "#D4");
1160                                 Assert.AreEqual (4, time.Second, "#D5");
1161                         } finally {
1162                                 DeleteFile (path);
1163                         }
1164                 }
1165
1166                 [Test]
1167                 public void LastAccessTime ()
1168                 {
1169                         string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";
1170                         if (File.Exists (path))
1171                                 File.Delete (path);
1172                         FileStream stream = null;
1173                         try {
1174                                 stream = File.Create (path);
1175                                 stream.Close ();
1176
1177                                 File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
1178                                 DateTime time = File.GetLastAccessTime (path);
1179                                 Assert.AreEqual (2002, time.Year, "#A1");
1180                                 Assert.AreEqual (4, time.Month, "#A2");
1181                                 Assert.AreEqual (6, time.Day, "#A3");
1182                                 Assert.AreEqual (4, time.Hour, "#A4");
1183                                 Assert.AreEqual (4, time.Second, "#A5");
1184
1185                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
1186                                 Assert.AreEqual (2002, time.Year, "#B1");
1187                                 Assert.AreEqual (4, time.Month, "#B2");
1188                                 Assert.AreEqual (6, time.Day, "#B3");
1189                                 Assert.AreEqual (4, time.Hour, "#B4");
1190                                 Assert.AreEqual (4, time.Second, "#B5");
1191
1192                                 File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
1193                                 time = File.GetLastAccessTimeUtc (path);
1194                                 Assert.AreEqual (2002, time.Year, "#C1");
1195                                 Assert.AreEqual (4, time.Month, "#C2");
1196                                 Assert.AreEqual (6, time.Day, "#C3");
1197                                 Assert.AreEqual (4, time.Hour, "#C4");
1198                                 Assert.AreEqual (4, time.Second, "#C5");
1199
1200                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
1201                                 Assert.AreEqual (2002, time.Year, "#D1");
1202                                 Assert.AreEqual (4, time.Month, "#D2");
1203                                 Assert.AreEqual (6, time.Day, "#D3");
1204                                 Assert.AreEqual (4, time.Hour, "#D4");
1205                                 Assert.AreEqual (4, time.Second, "#D5");
1206                         } finally {
1207                                 if (stream != null)
1208                                         stream.Close ();
1209                                 DeleteFile (path);
1210                         }
1211                 }
1212
1213                 [Test]
1214                 public void LastWriteTime ()
1215                 {
1216                         string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";
1217                         if (File.Exists (path))
1218                                 File.Delete (path);
1219                         FileStream stream = null;
1220                         try {
1221                                 stream = File.Create (path);
1222                                 stream.Close ();
1223
1224                                 File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
1225                                 DateTime time = File.GetLastWriteTime (path);
1226                                 Assert.AreEqual (2002, time.Year, "#A1");
1227                                 Assert.AreEqual (4, time.Month, "#A2");
1228                                 Assert.AreEqual (6, time.Day, "#A3");
1229                                 Assert.AreEqual (4, time.Hour, "#A4");
1230                                 Assert.AreEqual (4, time.Second, "#A5");
1231
1232                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
1233                                 Assert.AreEqual (2002, time.Year, "#B1");
1234                                 Assert.AreEqual (4, time.Month, "#B2");
1235                                 Assert.AreEqual (6, time.Day, "#B3");
1236                                 Assert.AreEqual (4, time.Hour, "#B4");
1237                                 Assert.AreEqual (4, time.Second, "#B5");
1238
1239                                 File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
1240                                 time = File.GetLastWriteTimeUtc (path);
1241                                 Assert.AreEqual (2002, time.Year, "#C1");
1242                                 Assert.AreEqual (4, time.Month, "#C2");
1243                                 Assert.AreEqual (6, time.Day, "#C3");
1244                                 Assert.AreEqual (4, time.Hour, "#C4");
1245                                 Assert.AreEqual (4, time.Second, "#C5");
1246
1247                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
1248                                 Assert.AreEqual (2002, time.Year, "#D1");
1249                                 Assert.AreEqual (4, time.Month, "#D2");
1250                                 Assert.AreEqual (6, time.Day, "#D3");
1251                                 Assert.AreEqual (4, time.Hour, "#D4");
1252                                 Assert.AreEqual (4, time.Second, "#D5");
1253                         } finally {
1254                                 if (stream != null)
1255                                         stream.Close ();
1256                                 DeleteFile (path);
1257                         }
1258                 }
1259
1260                 [Test]
1261                 public void GetCreationTime_Path_Null ()
1262                 {
1263                         try {
1264                                 File.GetCreationTime (null as string);
1265                                 Assert.Fail ("#1");
1266                         } catch (ArgumentNullException ex) {
1267                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1268                                 Assert.IsNull (ex.InnerException, "#3");
1269                                 Assert.IsNotNull (ex.Message, "#4");
1270                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1271                         }
1272                 }
1273
1274                 [Test]
1275                 public void GetCreationTime_Path_Empty ()
1276                 {
1277                         try {
1278                                 File.GetCreationTime (string.Empty);
1279                                 Assert.Fail ("#1");
1280                         } catch (ArgumentException ex) {
1281                                 // Empty file name is not legal
1282                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1283                                 Assert.IsNull (ex.InnerException, "#3");
1284                                 Assert.IsNotNull (ex.Message, "#4");
1285                                 Assert.IsNull (ex.ParamName, "#5");
1286                         }
1287                 }
1288         
1289                 [Test]
1290                 public void GetCreationTime_Path_DoesNotExist ()
1291                 {
1292                         string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
1293                         DeleteFile (path);
1294
1295 #if NET_2_0
1296                         DateTime time = File.GetCreationTime (path);
1297                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
1298                         Assert.AreEqual (expectedTime.Year, time.Year, "#1");
1299                         Assert.AreEqual (expectedTime.Month, time.Month, "#2");
1300                         Assert.AreEqual (expectedTime.Day, time.Day, "#3");
1301                         Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
1302                         Assert.AreEqual (expectedTime.Second, time.Second, "#5");
1303                         Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
1304 #else
1305                         try {
1306                                 File.GetCreationTime (path);
1307                                 Assert.Fail ("#1");
1308                         } catch (IOException ex) {
1309                                 // Could not find a part of the path "..."
1310                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1311                                 Assert.IsNull (ex.InnerException, "#3");
1312                                 Assert.IsNotNull (ex.Message, "#4");
1313                                 Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
1314                         }
1315 #endif
1316                 }
1317
1318                 [Test]
1319                 public void GetCreationTime_Path_Whitespace ()
1320                 {
1321                         try {
1322                                 File.GetCreationTime ("    ");
1323                                 Assert.Fail ("#1");
1324                         } catch (ArgumentException ex) {
1325                                 // The path is not of a legal form
1326                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1327                                 Assert.IsNull (ex.InnerException, "#3");
1328                                 Assert.IsNotNull (ex.Message, "#4");
1329                                 Assert.IsNull (ex.ParamName, "#5");
1330                         }
1331                 }
1332
1333                 [Test]
1334                 public void GetCreationTime_Path_InvalidPathChars ()
1335                 {
1336                         try {
1337                                 File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
1338                                 Assert.Fail ("#1");
1339                         } catch (ArgumentException ex) {
1340                                 // Illegal characters in path
1341                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1342                                 Assert.IsNull (ex.InnerException, "#3");
1343                                 Assert.IsNotNull (ex.Message, "#4");
1344                                 Assert.IsNull (ex.ParamName, "#5");
1345                         }
1346                 }
1347
1348                 [Test]
1349                 public void GetCreationTimeUtc_Path_Null ()
1350                 {
1351                         try {
1352                                 File.GetCreationTimeUtc (null as string);
1353                                 Assert.Fail ("#1");
1354                         } catch (ArgumentNullException ex) {
1355                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1356                                 Assert.IsNull (ex.InnerException, "#3");
1357                                 Assert.IsNotNull (ex.Message, "#4");
1358                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1359                         }
1360                 }
1361
1362                 [Test]
1363                 public void GetCreationTimeUtc_Path_Empty ()
1364                 {
1365                         try {
1366                                 File.GetCreationTimeUtc (string.Empty);
1367                                 Assert.Fail ("#1");
1368                         } catch (ArgumentException ex) {
1369                                 // Empty file name is not legal
1370                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1371                                 Assert.IsNull (ex.InnerException, "#3");
1372                                 Assert.IsNotNull (ex.Message, "#4");
1373                                 Assert.IsNull (ex.ParamName, "#5");
1374                         }
1375                 }
1376         
1377                 [Test]
1378                 public void GetCreationTimeUtc_Path_DoesNotExist ()
1379                 {
1380                         string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
1381                         DeleteFile (path);
1382
1383 #if NET_2_0
1384                         DateTime time = File.GetCreationTimeUtc (path);
1385                         Assert.AreEqual (1601, time.Year, "#1");
1386                         Assert.AreEqual (1, time.Month, "#2");
1387                         Assert.AreEqual (1, time.Day, "#3");
1388                         Assert.AreEqual (0, time.Hour, "#4");
1389                         Assert.AreEqual (0, time.Second, "#5");
1390                         Assert.AreEqual (0, time.Millisecond, "#6");
1391 #else
1392                         try {
1393                                 File.GetCreationTimeUtc (path);
1394                                 Assert.Fail ("#1");
1395                         } catch (IOException ex) {
1396                                 // Could not find a part of the path "..."
1397                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1398                                 Assert.IsNull (ex.InnerException, "#3");
1399                                 Assert.IsNotNull (ex.Message, "#4");
1400                                 Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
1401                         }
1402 #endif
1403                 }
1404
1405                 [Test]
1406                 public void GetCreationTimeUtc_Path_Whitespace ()
1407                 {
1408                         try {
1409                                 File.GetCreationTimeUtc ("    ");
1410                                 Assert.Fail ("#1");
1411                         } catch (ArgumentException ex) {
1412                                 // The path is not of a legal form
1413                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1414                                 Assert.IsNull (ex.InnerException, "#3");
1415                                 Assert.IsNotNull (ex.Message, "#4");
1416                                 Assert.IsNull (ex.ParamName, "#5");
1417                         }
1418                 }
1419
1420                 [Test]
1421                 public void GetCreationTimeUtc_Path_InvalidPathChars ()
1422                 {
1423                         try {
1424                                 File.GetCreationTimeUtc (Path.InvalidPathChars [0].ToString ());
1425                                 Assert.Fail ("#1");
1426                         } catch (ArgumentException ex) {
1427                                 // Illegal characters in path
1428                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1429                                 Assert.IsNull (ex.InnerException, "#3");
1430                                 Assert.IsNotNull (ex.Message, "#4");
1431                                 Assert.IsNull (ex.ParamName, "#5");
1432                         }
1433                 }
1434
1435                 [Test]
1436                 public void GetLastAccessTime_Path_Null ()
1437                 {
1438                         try {
1439                                 File.GetLastAccessTime (null as string);
1440                                 Assert.Fail ("#1");
1441                         } catch (ArgumentNullException ex) {
1442                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1443                                 Assert.IsNull (ex.InnerException, "#3");
1444                                 Assert.IsNotNull (ex.Message, "#4");
1445                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1446                         }
1447                 }
1448
1449                 [Test]
1450                 public void GetLastAccessTime_Path_Empty ()
1451                 {
1452                         try {
1453                                 File.GetLastAccessTime (string.Empty);
1454                                 Assert.Fail ("#1");
1455                         } catch (ArgumentException ex) {
1456                                 // Empty file name is not legal
1457                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1458                                 Assert.IsNull (ex.InnerException, "#3");
1459                                 Assert.IsNotNull (ex.Message, "#4");
1460                                 Assert.IsNull (ex.ParamName, "#5");
1461                         }
1462                 }
1463         
1464                 [Test]
1465                 public void GetLastAccessTime_Path_DoesNotExist ()
1466                 {
1467                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
1468                         DeleteFile (path);
1469
1470 #if NET_2_0
1471                         DateTime time = File.GetLastAccessTime (path);
1472                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
1473                         Assert.AreEqual (expectedTime.Year, time.Year, "#1");
1474                         Assert.AreEqual (expectedTime.Month, time.Month, "#2");
1475                         Assert.AreEqual (expectedTime.Day, time.Day, "#3");
1476                         Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
1477                         Assert.AreEqual (expectedTime.Second, time.Second, "#5");
1478                         Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
1479 #else
1480                         try {
1481                                 File.GetLastAccessTime (path);
1482                                 Assert.Fail ("#1");
1483                         } catch (IOException ex) {
1484                                 // Could not find a part of the path "..."
1485                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1486                                 Assert.IsNull (ex.InnerException, "#3");
1487                                 Assert.IsNotNull (ex.Message, "#4");
1488                                 Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
1489                         }
1490 #endif
1491                 }
1492
1493                 [Test]
1494                 public void GetLastAccessTime_Path_Whitespace ()
1495                 {
1496                         try {
1497                                 File.GetLastAccessTime ("    ");
1498                                 Assert.Fail ("#1");
1499                         } catch (ArgumentException ex) {
1500                                 // The path is not of a legal form
1501                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1502                                 Assert.IsNull (ex.InnerException, "#3");
1503                                 Assert.IsNotNull (ex.Message, "#4");
1504                                 Assert.IsNull (ex.ParamName, "#5");
1505                         }
1506                 }
1507
1508                 [Test]
1509                 public void GetLastAccessTime_Path_InvalidPathChars ()
1510                 {
1511                         try {
1512                                 File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
1513                                 Assert.Fail ("#1");
1514                         } catch (ArgumentException ex) {
1515                                 // Illegal characters in path
1516                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1517                                 Assert.IsNull (ex.InnerException, "#3");
1518                                 Assert.IsNotNull (ex.Message, "#4");
1519                                 Assert.IsNull (ex.ParamName, "#5");
1520                         }
1521                 }
1522
1523                 [Test]
1524                 public void GetLastAccessTimeUtc_Path_Null ()
1525                 {
1526                         try {
1527                                 File.GetLastAccessTimeUtc (null as string);
1528                                 Assert.Fail ("#1");
1529                         } catch (ArgumentNullException ex) {
1530                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1531                                 Assert.IsNull (ex.InnerException, "#3");
1532                                 Assert.IsNotNull (ex.Message, "#4");
1533                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1534                         }
1535                 }
1536
1537                 [Test]
1538                 public void GetLastAccessTimeUtc_Path_Empty ()
1539                 {
1540                         try {
1541                                 File.GetLastAccessTimeUtc (string.Empty);
1542                                 Assert.Fail ("#1");
1543                         } catch (ArgumentException ex) {
1544                                 // Empty file name is not legal
1545                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1546                                 Assert.IsNull (ex.InnerException, "#3");
1547                                 Assert.IsNotNull (ex.Message, "#4");
1548                                 Assert.IsNull (ex.ParamName, "#5");
1549                         }
1550                 }
1551         
1552                 [Test]
1553                 public void GetLastAccessTimeUtc_Path_DoesNotExist ()
1554                 {
1555                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
1556                         DeleteFile (path);
1557
1558 #if NET_2_0
1559                         DateTime time = File.GetLastAccessTimeUtc (path);
1560                         Assert.AreEqual (1601, time.Year, "#1");
1561                         Assert.AreEqual (1, time.Month, "#2");
1562                         Assert.AreEqual (1, time.Day, "#3");
1563                         Assert.AreEqual (0, time.Hour, "#4");
1564                         Assert.AreEqual (0, time.Second, "#5");
1565                         Assert.AreEqual (0, time.Millisecond, "#6");
1566 #else
1567                         try {
1568                                 File.GetLastAccessTimeUtc (path);
1569                                 Assert.Fail ("#1");
1570                         } catch (IOException ex) {
1571                                 // Could not find a part of the path "..."
1572                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1573                                 Assert.IsNull (ex.InnerException, "#3");
1574                                 Assert.IsNotNull (ex.Message, "#4");
1575                                 Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
1576                         }
1577 #endif
1578                 }
1579
1580                 [Test]
1581                 public void GetLastAccessTimeUtc_Path_Whitespace ()
1582                 {
1583                         try {
1584                                 File.GetLastAccessTimeUtc ("    ");
1585                                 Assert.Fail ("#1");
1586                         } catch (ArgumentException ex) {
1587                                 // The path is not of a legal form
1588                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1589                                 Assert.IsNull (ex.InnerException, "#3");
1590                                 Assert.IsNotNull (ex.Message, "#4");
1591                                 Assert.IsNull (ex.ParamName, "#5");
1592                         }
1593                 }
1594
1595                 [Test]
1596                 public void GetLastAccessTimeUtc_Path_InvalidPathChars ()
1597                 {
1598                         try {
1599                                 File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
1600                                 Assert.Fail ("#1");
1601                         } catch (ArgumentException ex) {
1602                                 // Illegal characters in path
1603                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1604                                 Assert.IsNull (ex.InnerException, "#3");
1605                                 Assert.IsNotNull (ex.Message, "#4");
1606                                 Assert.IsNull (ex.ParamName, "#5");
1607                         }
1608                 }
1609
1610                 [Test]
1611                 public void GetLastWriteTime_Path_Null ()
1612                 {
1613                         try {
1614                                 File.GetLastWriteTime (null as string);
1615                                 Assert.Fail ("#1");
1616                         } catch (ArgumentNullException ex) {
1617                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1618                                 Assert.IsNull (ex.InnerException, "#3");
1619                                 Assert.IsNotNull (ex.Message, "#4");
1620                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1621                         }
1622                 }
1623
1624                 [Test]
1625                 public void GetLastWriteTime_Path_Empty ()
1626                 {
1627                         try {
1628                                 File.GetLastWriteTime (string.Empty);
1629                                 Assert.Fail ("#1");
1630                         } catch (ArgumentException ex) {
1631                                 // Empty file name is not legal
1632                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1633                                 Assert.IsNull (ex.InnerException, "#3");
1634                                 Assert.IsNotNull (ex.Message, "#4");
1635                                 Assert.IsNull (ex.ParamName, "#5");
1636                         }
1637                 }
1638         
1639                 [Test]
1640                 public void GetLastWriteTime_Path_DoesNotExist ()
1641                 {
1642                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
1643                         DeleteFile (path);
1644
1645 #if NET_2_0
1646                         DateTime time = File.GetLastWriteTime (path);
1647                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
1648                         Assert.AreEqual (expectedTime.Year, time.Year, "#1");
1649                         Assert.AreEqual (expectedTime.Month, time.Month, "#2");
1650                         Assert.AreEqual (expectedTime.Day, time.Day, "#3");
1651                         Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
1652                         Assert.AreEqual (expectedTime.Second, time.Second, "#5");
1653                         Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
1654 #else
1655                         try {
1656                                 File.GetLastWriteTime (path);
1657                                 Assert.Fail ("#1");
1658                         } catch (IOException ex) {
1659                                 // Could not find a part of the path "..."
1660                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1661                                 Assert.IsNull (ex.InnerException, "#3");
1662                                 Assert.IsNotNull (ex.Message, "#4");
1663                                 Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
1664                         }
1665 #endif
1666                 }
1667
1668                 [Test]
1669                 public void GetLastWriteTime_Path_Whitespace ()
1670                 {
1671                         try {
1672                                 File.GetLastWriteTime ("    ");
1673                                 Assert.Fail ("#1");
1674                         } catch (ArgumentException ex) {
1675                                 // The path is not of a legal form
1676                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1677                                 Assert.IsNull (ex.InnerException, "#3");
1678                                 Assert.IsNotNull (ex.Message, "#4");
1679                                 Assert.IsNull (ex.ParamName, "#5");
1680                         }
1681                 }
1682
1683                 [Test]
1684                 public void GetLastWriteTime_Path_InvalidPathChars ()
1685                 {
1686                         try {
1687                                 File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
1688                                 Assert.Fail ("#1");
1689                         } catch (ArgumentException ex) {
1690                                 // Illegal characters in path
1691                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1692                                 Assert.IsNull (ex.InnerException, "#3");
1693                                 Assert.IsNotNull (ex.Message, "#4");
1694                                 Assert.IsNull (ex.ParamName, "#5");
1695                         }
1696                 }
1697
1698                 [Test]
1699                 public void GetLastWriteTimeUtc_Path_Null ()
1700                 {
1701                         try {
1702                                 File.GetLastWriteTimeUtc (null as string);
1703                                 Assert.Fail ("#1");
1704                         } catch (ArgumentNullException ex) {
1705                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1706                                 Assert.IsNull (ex.InnerException, "#3");
1707                                 Assert.IsNotNull (ex.Message, "#4");
1708                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1709                         }
1710                 }
1711
1712                 [Test]
1713                 public void GetLastWriteTimeUtc_Path_Empty ()
1714                 {
1715                         try {
1716                                 File.GetLastWriteTimeUtc (string.Empty);
1717                                 Assert.Fail ("#1");
1718                         } catch (ArgumentException ex) {
1719                                 // Empty file name is not legal
1720                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1721                                 Assert.IsNull (ex.InnerException, "#3");
1722                                 Assert.IsNotNull (ex.Message, "#4");
1723                                 Assert.IsNull (ex.ParamName, "#5");
1724                         }
1725                 }
1726         
1727                 [Test]
1728                 public void GetLastWriteTimeUtc_Path_DoesNotExist ()
1729                 {
1730                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
1731                         DeleteFile (path);
1732
1733 #if NET_2_0
1734                         DateTime time = File.GetLastWriteTimeUtc (path);
1735                         Assert.AreEqual (1601, time.Year, "#1");
1736                         Assert.AreEqual (1, time.Month, "#2");
1737                         Assert.AreEqual (1, time.Day, "#3");
1738                         Assert.AreEqual (0, time.Hour, "#4");
1739                         Assert.AreEqual (0, time.Second, "#5");
1740                         Assert.AreEqual (0, time.Millisecond, "#6");
1741 #else
1742                         try {
1743                                 File.GetLastWriteTimeUtc (path);
1744                                 Assert.Fail ("#1");
1745                         } catch (IOException ex) {
1746                                 // Could not find a part of the path "..."
1747                                 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1748                                 Assert.IsNull (ex.InnerException, "#3");
1749                                 Assert.IsNotNull (ex.Message, "#4");
1750                                 Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
1751                         }
1752 #endif
1753                 }
1754
1755                 [Test]
1756                 public void GetLastWriteTimeUtc_Path_Whitespace ()
1757                 {
1758                         try {
1759                                 File.GetLastWriteTimeUtc ("    ");
1760                                 Assert.Fail ("#1");
1761                         } catch (ArgumentException ex) {
1762                                 // The path is not of a legal form
1763                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1764                                 Assert.IsNull (ex.InnerException, "#3");
1765                                 Assert.IsNotNull (ex.Message, "#4");
1766                                 Assert.IsNull (ex.ParamName, "#5");
1767                         }
1768                 }
1769
1770                 [Test]
1771                 public void GetLastWriteTimeUtc_Path_InvalidPathChars ()
1772                 {
1773                         try {
1774                                 File.GetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString ());
1775                                 Assert.Fail ("#1");
1776                         } catch (ArgumentException ex) {
1777                                 // Illegal characters in path
1778                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1779                                 Assert.IsNull (ex.InnerException, "#3");
1780                                 Assert.IsNotNull (ex.Message, "#4");
1781                                 Assert.IsNull (ex.ParamName, "#5");
1782                         }
1783                 }
1784
1785                 [Test]
1786                 public void FileStreamClose ()
1787                 {
1788                         string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
1789                         FileStream stream = null;
1790                         try {
1791                                 stream = File.Create (path);
1792                                 stream.Close ();
1793                                 File.Delete (path);
1794                         } finally {
1795                                 if (stream != null)
1796                                         stream.Close ();
1797                                 DeleteFile (path);
1798                         }
1799                 }
1800                 
1801                 // SetCreationTime and SetCreationTimeUtc exceptions
1802
1803                 [Test]
1804                 public void SetCreationTime_Path_Null ()
1805                 {
1806                         try {
1807                                 File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1808                                 Assert.Fail ("#1");
1809                         } catch (ArgumentNullException ex) {
1810                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1811                                 Assert.IsNull (ex.InnerException, "#3");
1812                                 Assert.IsNotNull (ex.Message, "#4");
1813                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1814                         }
1815                 }
1816
1817                 [Test]
1818                 public void SetCreationTime_Path_Empty ()
1819                 {
1820                         try {
1821                                 File.SetCreationTime (string.Empty, new DateTime (2000, 12, 12, 11, 59, 59));
1822                                 Assert.Fail ("#1");
1823                         } catch (ArgumentException ex) {
1824                                 // Empty file name is not legal
1825                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1826                                 Assert.IsNull (ex.InnerException, "#3");
1827                                 Assert.IsNotNull (ex.Message, "#4");
1828                                 Assert.IsNull (ex.ParamName, "#5");
1829                         }
1830                 }
1831
1832                 [Test]
1833                 public void SetCreationTime_Path_Whitespace ()
1834                 {
1835                         try {
1836                                 File.SetCreationTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1837                                 Assert.Fail ("#1");
1838                         } catch (ArgumentException ex) {
1839                                 // The path is not of a legal form
1840                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1841                                 Assert.IsNull (ex.InnerException, "#3");
1842                                 Assert.IsNotNull (ex.Message, "#4");
1843                                 Assert.IsNull (ex.ParamName, "#5");
1844                         }
1845                 }
1846
1847                 [Test]
1848                 public void SetCreationTime_Path_InvalidPathChars ()
1849                 {
1850                         // On Unix there are no invalid path chars.
1851                         if (Path.InvalidPathChars.Length > 1) {
1852                                 try {
1853                                         File.SetCreationTime (Path.InvalidPathChars [1].ToString (),
1854                                                 new DateTime (2000, 12, 12, 11, 59, 59));
1855                                         Assert.Fail ("#1");
1856                                 } catch (ArgumentException ex) {
1857                                         // Illegal characters in path
1858                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1859                                         Assert.IsNull (ex.InnerException, "#3");
1860                                         Assert.IsNotNull (ex.Message, "#4");
1861                                         Assert.IsNull (ex.ParamName, "#5");
1862                                 }
1863                         }
1864                 }
1865
1866                 [Test]
1867                 public void SetCreationTime_Path_DoesNotExist ()
1868                 {
1869                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
1870                         DeleteFile (path);
1871                         
1872                         try {
1873                                 File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1874                                 Assert.Fail ("#1");
1875                         } catch (FileNotFoundException ex) {
1876                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
1877                                 Assert.AreEqual (path, ex.FileName, "#3");
1878                                 Assert.IsNull (ex.InnerException, "#4");
1879                                 Assert.IsNotNull (ex.Message, "#5");
1880                         }
1881                 }
1882
1883 //              [Test]
1884 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1885 //              public void SetCreationTimeArgumentOutOfRangeException1 ()
1886 //              {
1887 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
1888 //                      FileStream stream = null;
1889 //                      DeleteFile (path);
1890 //                      try {
1891 //                              stream = File.Create (path);
1892 //                              stream.Close ();
1893 //                              File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1894 //                      } finally {
1895 //                              if (stream != null)
1896 //                                      stream.Close ();
1897 //                              DeleteFile (path);
1898 //                      }
1899 //              }
1900
1901                 [Test]
1902                 public void SetCreationTime_FileLock ()
1903                 {
1904                         string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
1905                         DeleteFile (path);
1906                         FileStream stream = null;
1907                         try {
1908                                 stream = File.Create (path);
1909                                 try {
1910                                         File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1911                                         Assert.Fail ("#1");
1912                                 } catch (IOException ex) {
1913                                         // The process cannot access the file '...'
1914                                         // because it is being used by another process
1915                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
1916                                         Assert.IsNull (ex.InnerException, "#3");
1917                                         Assert.IsNotNull (ex.Message, "#4");
1918                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
1919                                 }
1920                         } finally {
1921                                 if (stream != null)
1922                                         stream.Close ();
1923                                 DeleteFile (path);
1924                         }
1925                 }
1926
1927                 [Test]
1928                 public void SetCreationTimeUtc_Path_Null ()
1929                 { 
1930                         try {
1931                                 File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1932                                 Assert.Fail ("#1");
1933                         } catch (ArgumentNullException ex) {
1934                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1935                                 Assert.IsNull (ex.InnerException, "#3");
1936                                 Assert.IsNotNull (ex.Message, "#4");
1937                                 Assert.AreEqual ("path", ex.ParamName, "#5");
1938                         }
1939                 }
1940
1941                 [Test]
1942                 public void SetCreationTimeUtc_Path_Empty ()
1943                 {
1944                         try {
1945                                 File.SetCreationTimeUtc (string.Empty, new DateTime (2000, 12, 12, 11, 59, 59));
1946                                 Assert.Fail ("#1");
1947                         } catch (ArgumentException ex) {
1948                                 // Empty file name is not legal
1949                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1950                                 Assert.IsNull (ex.InnerException, "#3");
1951                                 Assert.IsNotNull (ex.Message, "#4");
1952                                 Assert.IsNull (ex.ParamName, "#5");
1953                         }
1954                 }
1955
1956                 [Test]
1957                 public void SetCreationTimeUtc_Path_Whitespace ()
1958                 {
1959                         try {
1960                                 File.SetCreationTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1961                                 Assert.Fail ("#1");
1962                         } catch (ArgumentException ex) {
1963                                 // The path is not of a legal form
1964                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1965                                 Assert.IsNull (ex.InnerException, "#3");
1966                                 Assert.IsNotNull (ex.Message, "#4");
1967                                 Assert.IsNull (ex.ParamName, "#5");
1968                         }
1969                 }
1970
1971                 [Test]
1972                 public void SetCreationTimeUtc_Path_InvalidPathChars ()
1973                 {
1974                         // On Unix there are no invalid path chars.
1975                         if (Path.InvalidPathChars.Length > 1) {
1976                                 try {
1977                                         File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (),
1978                                                 new DateTime (2000, 12, 12, 11, 59, 59));
1979                                         Assert.Fail ("#1");
1980                                 } catch (ArgumentException ex) {
1981                                         // Illegal characters in path
1982                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1983                                         Assert.IsNull (ex.InnerException, "#3");
1984                                         Assert.IsNotNull (ex.Message, "#4");
1985                                         Assert.IsNull (ex.ParamName, "#5");
1986                                 }
1987                         }
1988                 }
1989
1990                 [Test]
1991                 public void SetCreationTimeUtc_Path_DoesNotExist ()
1992                 {
1993                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
1994                         DeleteFile (path);
1995
1996                         try {
1997                                 File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1998                                 Assert.Fail ("#1");
1999                         } catch (FileNotFoundException ex) {
2000                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
2001                                 Assert.AreEqual (path, ex.FileName, "#3");
2002                                 Assert.IsNull (ex.InnerException, "#3");
2003                                 Assert.IsNotNull (ex.Message, "#4");
2004                         }
2005                 }
2006
2007 //              [Test]
2008 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
2009 //              public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
2010 //              {
2011 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
2012 //                      DeleteFile (path);
2013 //                      FileStream stream = null;
2014 //                      try {
2015 //                              stream = File.Create (path);
2016 //                              stream.Close ();
2017 //                              File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
2018 //                      } finally {
2019 //                              if (stream != null)
2020 //                                      stream.Close();
2021 //                              DeleteFile (path);
2022 //                      }
2023 //              }
2024
2025                 [Test]
2026                 public void SetCreationTimeUtc_FileLock ()
2027                 {
2028                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
2029                         DeleteFile (path);
2030                         FileStream stream = null;
2031                         try {
2032                                 stream = File.Create (path);
2033                                 try {
2034                                         File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
2035                                         Assert.Fail ("#1");
2036                                 } catch (IOException ex) {
2037                                         // The process cannot access the file "..."
2038                                         // because it is being used by another process
2039                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
2040                                         Assert.IsNull (ex.InnerException, "#3");
2041                                         Assert.IsNotNull (ex.Message, "#4");
2042                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
2043                                 }
2044                         } finally {
2045                                 if (stream != null)
2046                                         stream.Close ();
2047                                 DeleteFile (path);
2048                         }
2049                 }
2050
2051                 // SetLastAccessTime and SetLastAccessTimeUtc exceptions
2052
2053                 [Test]
2054                 public void SetLastAccessTime_Path_Null ()
2055                 {
2056                         try {
2057                                 File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
2058                                 Assert.Fail ("#1");
2059                         } catch (ArgumentNullException ex) {
2060                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2061                                 Assert.IsNull (ex.InnerException, "#3");
2062                                 Assert.IsNotNull (ex.Message, "#4");
2063                                 Assert.AreEqual ("path", ex.ParamName, "#5");
2064                         }
2065                 }
2066
2067                 [Test]
2068                 public void SetLastAccessTime_Path_Empty ()
2069                 {
2070                         try {
2071                                 File.SetLastAccessTime (string.Empty, new DateTime (2000, 12, 12, 11, 59, 59));
2072                                 Assert.Fail ("#1");
2073                         } catch (ArgumentException ex) {
2074                                 // Empty file name is not legal
2075                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2076                                 Assert.IsNull (ex.InnerException, "#3");
2077                                 Assert.IsNotNull (ex.Message, "#4");
2078                                 Assert.IsNull (ex.ParamName, "#5");
2079                         }
2080                 }
2081
2082                 [Test]
2083                 public void SetLastAccessTime_Path_Whitespace ()
2084                 {
2085                         try {
2086                                 File.SetLastAccessTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
2087                                 Assert.Fail ("#1");
2088                         } catch (ArgumentException ex) {
2089                                 // The path is not of a legal form
2090                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2091                                 Assert.IsNull (ex.InnerException, "#3");
2092                                 Assert.IsNotNull (ex.Message, "#4");
2093                                 Assert.IsNull (ex.ParamName, "#5");
2094                         }
2095                 }
2096
2097                 [Test]
2098                 public void SetLastAccessTime_Path_InvalidPathChars ()
2099                 {
2100                         // On Unix there are no invalid path chars.
2101                         if (Path.InvalidPathChars.Length > 1) {
2102                                 try {
2103                                         File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (),
2104                                                 new DateTime (2000, 12, 12, 11, 59, 59));
2105                                         Assert.Fail ("#1");
2106                                 } catch (ArgumentException ex) {
2107                                         // Illegal characters in path
2108                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2109                                         Assert.IsNull (ex.InnerException, "#3");
2110                                         Assert.IsNotNull (ex.Message, "#4");
2111                                         Assert.IsNull (ex.ParamName, "#5");
2112                                 }
2113                         }
2114                 }
2115
2116                 [Test]
2117                 public void SetLastAccessTime_Path_DoesNotExist ()
2118                 {
2119                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
2120                         DeleteFile (path);
2121
2122                         try {
2123                                 File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
2124                                 Assert.Fail ("#1");
2125                         } catch (FileNotFoundException ex) {
2126                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
2127                                 Assert.AreEqual (path, ex.FileName, "#3");
2128                                 Assert.IsNull (ex.InnerException, "#4");
2129                                 Assert.IsNotNull (ex.Message, "#5");
2130                         }
2131                 }
2132
2133 //              [Test]
2134 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
2135 //              public void SetLastAccessTimeArgumentOutOfRangeException1 ()
2136 //              {
2137 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
2138 //                      DeleteFile (path);
2139 //                      FileStream stream = null;
2140 //                      try {
2141 //                              stream = File.Create (path);
2142 //                              stream.Close ();
2143 //                              File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
2144 //                      } finally {
2145 //                              if (stream != null)
2146 //                                      stream.Close ();
2147 //                              DeleteFile (path);
2148 //                      }
2149 //              }
2150
2151                 [Test]
2152                 public void SetLastAccessTime_FileLock ()
2153                 {
2154                         string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
2155                         DeleteFile (path);
2156                         FileStream stream = null;
2157                         try {
2158                                 stream = File.Create (path);
2159                                 try {
2160                                         File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
2161                                         Assert.Fail ("#1");
2162                                 } catch (IOException ex) {
2163                                         // The process cannot access the file "..."
2164                                         // because it is being used by another process
2165                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
2166                                         Assert.IsNull (ex.InnerException, "#3");
2167                                         Assert.IsNotNull (ex.Message, "#4");
2168                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
2169                                 }
2170                         } finally {
2171                                 if (stream != null)
2172                                         stream.Close ();
2173                                 DeleteFile (path);
2174                         }
2175                 }
2176
2177                 [Test]
2178                 public void SetLastAccessTimeUtc_Path_Null ()
2179                 {
2180                         try {
2181                                 File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
2182                                 Assert.Fail ("#1");
2183                         } catch (ArgumentNullException ex) {
2184                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2185                                 Assert.IsNull (ex.InnerException, "#3");
2186                                 Assert.IsNotNull (ex.Message, "#4");
2187                                 Assert.AreEqual ("path", ex.ParamName, "#5");
2188                         }
2189                 }
2190
2191                 [Test]
2192                 public void SetCLastAccessTimeUtc_Path_Empty ()
2193                 {
2194                         try {
2195                                 File.SetLastAccessTimeUtc (string.Empty, new DateTime (2000, 12, 12, 11, 59, 59));
2196                                 Assert.Fail ("#1");
2197                         } catch (ArgumentException ex) {
2198                                 // Empty file name is not legal
2199                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2200                                 Assert.IsNull (ex.InnerException, "#3");
2201                                 Assert.IsNotNull (ex.Message, "#4");
2202                                 Assert.IsNull (ex.ParamName, "#5");
2203                         }
2204                 }
2205
2206                 [Test]
2207                 public void SetLastAccessTimeUtc_Path_Whitespace ()
2208                 {
2209                         try {
2210                                 File.SetLastAccessTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
2211                                 Assert.Fail ("#1");
2212                         } catch (ArgumentException ex) {
2213                                 // The path is not of a legal form
2214                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2215                                 Assert.IsNull (ex.InnerException, "#3");
2216                                 Assert.IsNotNull (ex.Message, "#4");
2217                                 Assert.IsNull (ex.ParamName, "#5");
2218                         }
2219                 }
2220
2221                 [Test]
2222                 public void SetLastAccessTimeUtc_Path_InvalidPathChars ()
2223                 {
2224                         // On Unix there are no invalid path chars.
2225                         if (Path.InvalidPathChars.Length > 1) {
2226                                 try {
2227                                         File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (),
2228                                                 new DateTime (2000, 12, 12, 11, 59, 59));
2229                                         Assert.Fail ("#1");
2230                                 } catch (ArgumentException ex) {
2231                                         // Illegal characters in path
2232                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2233                                         Assert.IsNull (ex.InnerException, "#3");
2234                                         Assert.IsNotNull (ex.Message, "#4");
2235                                         Assert.IsNull (ex.ParamName, "#5");
2236                                 }
2237                         }
2238                 }
2239
2240                 [Test]
2241                 public void SetLastAccessTimeUtc_Path_DoesNotExist ()
2242                 {
2243                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
2244                         DeleteFile (path);
2245
2246                         try {
2247                                 File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
2248                                 Assert.Fail ("#1");
2249                         } catch (FileNotFoundException ex) {
2250                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
2251                                 Assert.AreEqual (path, ex.FileName, "#3");
2252                                 Assert.IsNull (ex.InnerException, "#4");
2253                                 Assert.IsNotNull (ex.Message, "#5");
2254                         }
2255                 }
2256
2257 //              [Test]
2258 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
2259 //              public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
2260 //              {
2261 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
2262 //                      DeleteFile (path);
2263 //                      FileStream stream = null;
2264 //                      try {
2265 //                              stream = File.Create (path);
2266 //                              stream.Close ();
2267 //                              File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
2268 //                      } finally {
2269 //                              if (stream != null)
2270 //                                      stream.Close ();
2271 //                              DeleteFile (path);
2272 //                      }
2273 //              }
2274
2275                 [Test]
2276                 public void SetLastAccessTimeUtc_FileLock ()
2277                 {
2278                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
2279                         DeleteFile (path);
2280                         FileStream stream = null;
2281                         try {
2282                                 stream = File.Create (path);
2283                                 try {
2284                                         File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
2285                                         Assert.Fail ("#1");
2286                                 } catch (IOException ex) {
2287                                         // The process cannot access the file "..."
2288                                         // because it is being used by another process
2289                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
2290                                         Assert.IsNull (ex.InnerException, "#3");
2291                                         Assert.IsNotNull (ex.Message, "#4");
2292                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
2293                                 }
2294                         } finally {
2295                                 if (stream != null)
2296                                         stream.Close ();
2297                                 DeleteFile (path);
2298                         }
2299                 }
2300
2301                 // SetLastWriteTime and SetLastWriteTimeUtc exceptions
2302
2303                 [Test]
2304                 public void SetLastWriteTime_Path_Null ()
2305                 {
2306                         try {
2307                                 File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
2308                                 Assert.Fail ("#1");
2309                         } catch (ArgumentNullException ex) {
2310                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2311                                 Assert.IsNull (ex.InnerException, "#3");
2312                                 Assert.IsNotNull (ex.Message, "#4");
2313                                 Assert.AreEqual ("path", ex.ParamName, "#5");
2314                         }
2315                 }
2316
2317                 [Test]
2318                 public void SetLastWriteTime_Path_Empty ()
2319                 {
2320                         try {
2321                                 File.SetLastWriteTime (string.Empty, new DateTime (2000, 12, 12, 11, 59, 59));
2322                                 Assert.Fail ("#1");
2323                         } catch (ArgumentException ex) {
2324                                 // Empty file name is not legal
2325                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2326                                 Assert.IsNull (ex.InnerException, "#3");
2327                                 Assert.IsNotNull (ex.Message, "#4");
2328                                 Assert.IsNull (ex.ParamName, "#5");
2329                         }
2330                 }
2331
2332                 [Test]
2333                 public void SetLastWriteTime_Path_Whitespace ()
2334                 {
2335                         try {
2336                                 File.SetLastWriteTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
2337                                 Assert.Fail ("#1");
2338                         } catch (ArgumentException ex) {
2339                                 // The path is not of a legal form
2340                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2341                                 Assert.IsNull (ex.InnerException, "#3");
2342                                 Assert.IsNotNull (ex.Message, "#4");
2343                                 Assert.IsNull (ex.ParamName, "#5");
2344                         }
2345                 }
2346
2347                 [Test]
2348                 public void SetLastWriteTime_Path_InvalidPathChars ()
2349                 {
2350                         // On Unix there are no invalid path chars.
2351                         if (Path.InvalidPathChars.Length > 1) {
2352                                 try {
2353                                         File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (),
2354                                                 new DateTime (2000, 12, 12, 11, 59, 59));
2355                                         Assert.Fail ("#1");
2356                                 } catch (ArgumentException ex) {
2357                                         // Illegal characters in path
2358                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2359                                         Assert.IsNull (ex.InnerException, "#3");
2360                                         Assert.IsNotNull (ex.Message, "#4");
2361                                         Assert.IsNull (ex.ParamName, "#5");
2362                                 }
2363                         }
2364                 }
2365
2366                 [Test]
2367                 public void SetLastWriteTime_Path_DoesNotExist ()
2368                 {
2369                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
2370                         DeleteFile (path);
2371
2372                         try {
2373                                 File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
2374                                 Assert.Fail ("#1");
2375                         } catch (FileNotFoundException ex) {
2376                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
2377                                 Assert.AreEqual (path, ex.FileName, "#3");
2378                                 Assert.IsNull (ex.InnerException, "#4");
2379                                 Assert.IsNotNull (ex.Message, "#5");
2380                         }
2381                 }
2382
2383 //              [Test]
2384 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
2385 //              public void SetLastWriteTimeArgumentOutOfRangeException1 ()
2386 //              {
2387 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
2388 //                      DeleteFile (path);
2389 //                      FileStream stream = null;
2390 //                      try {
2391 //                              stream = File.Create (path);
2392 //                              stream.Close ();
2393 //                              File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
2394 //                      } finally {
2395 //                              if (stream != null)
2396 //                                      stream.Close ();
2397 //                              DeleteFile (path);
2398 //                      }
2399 //              }
2400
2401                 [Test]
2402                 public void SetLastWriteTime_FileLock ()
2403                 {
2404                         string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
2405                         DeleteFile (path);
2406                         FileStream stream = null;
2407                         try {
2408                                 stream = File.Create (path);
2409                                 try {
2410                                         File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
2411                                         Assert.Fail ("#1");
2412                                 } catch (IOException ex) {
2413                                         // The process cannot access the file '...'
2414                                         // because it is being used by another process
2415                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
2416                                         Assert.IsNull (ex.InnerException, "#3");
2417                                         Assert.IsNotNull (ex.Message, "#4");
2418                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
2419                                 }
2420                         } finally {
2421                                 if (stream != null)
2422                                         stream.Close ();
2423                                 DeleteFile (path);
2424                         }
2425                 }
2426
2427                 [Test]
2428                 public void SetLastWriteTimeUtc_Path_Null ()
2429                 {
2430                         try {
2431                                 File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
2432                                 Assert.Fail ("#1");
2433                         } catch (ArgumentNullException ex) {
2434                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2435                                 Assert.IsNull (ex.InnerException, "#3");
2436                                 Assert.IsNotNull (ex.Message, "#4");
2437                                 Assert.AreEqual ("path", ex.ParamName, "#5");
2438                         }
2439                 }
2440
2441                 [Test]
2442                 public void SetLastWriteTimeUtc_Path_Empty ()
2443                 {
2444                         try {
2445                                 File.SetLastWriteTimeUtc (string.Empty, new DateTime (2000, 12, 12, 11, 59, 59));
2446                                 Assert.Fail ("#1");
2447                         } catch (ArgumentException ex) {
2448                                 // Empty file name is not legal
2449                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2450                                 Assert.IsNull (ex.InnerException, "#3");
2451                                 Assert.IsNotNull (ex.Message, "#4");
2452                                 Assert.IsNull (ex.ParamName, "#5");
2453                         }
2454                 }
2455
2456                 [Test]
2457                 public void SetLastWriteTimeUtc_Path_Whitespace ()
2458                 {
2459                         try {
2460                                 File.SetLastWriteTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
2461                                 Assert.Fail ("#1");
2462                         } catch (ArgumentException ex) {
2463                                 // The path is not of a legal form
2464                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2465                                 Assert.IsNull (ex.InnerException, "#3");
2466                                 Assert.IsNotNull (ex.Message, "#4");
2467                                 Assert.IsNull (ex.ParamName, "#5");
2468                         }
2469                 }
2470
2471                 [Test]
2472                 public void SetLastWriteTimeUtc_Path_InvalidPathChars ()
2473                 {
2474                         // On Unix there are no invalid path chars.
2475                         if (Path.InvalidPathChars.Length > 1) {
2476                                 try {
2477                                         File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (),
2478                                                 new DateTime (2000, 12, 12, 11, 59, 59));
2479                                         Assert.Fail ("#1");
2480                                 } catch (ArgumentException ex) {
2481                                         // Illegal characters in path
2482                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2483                                         Assert.IsNull (ex.InnerException, "#3");
2484                                         Assert.IsNotNull (ex.Message, "#4");
2485                                         Assert.IsNull (ex.ParamName, "#5");
2486                                 }
2487                         }
2488                 }
2489
2490                 [Test]
2491                 public void SetLastWriteTimeUtc_Path_DoesNotExist ()
2492                 {
2493                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
2494                         DeleteFile (path);
2495
2496                         try {
2497                                 File.SetLastWriteTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
2498                                 Assert.Fail ("#1");
2499                         } catch (FileNotFoundException ex) {
2500                                 Assert.AreEqual (typeof (FileNotFoundException), ex.GetType (), "#2");
2501                                 Assert.AreEqual (path, ex.FileName, "#3");
2502                                 Assert.IsNull (ex.InnerException, "#4");
2503                                 Assert.IsNotNull (ex.Message, "#5");
2504                         }
2505                 }
2506
2507 //              [Test]
2508 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
2509 //              public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
2510 //              {
2511 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
2512 //                      DeleteFile (path);
2513 //                      FileStream stream = null;
2514 //                      try {
2515 //                              stream = File.Create (path);
2516 //                              stream.Close ();
2517 //                              File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
2518 //                      } finally {
2519 //                              if (stream != null)
2520 //                                      stream.Close ();
2521 //                              DeleteFile (path);
2522 //                      }
2523 //              }
2524
2525                 [Test]
2526                 public void SetLastWriteTimeUtc_FileLock ()
2527                 {
2528                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
2529                         DeleteFile (path);
2530                         FileStream stream = null;
2531                         try {
2532                                 stream = File.Create (path);
2533                                 try {
2534                                         File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
2535                                         Assert.Fail ("#1");
2536                                 } catch (IOException ex) {
2537                                         // The process cannot access the file '...'
2538                                         // because it is being used by another process
2539                                         Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
2540                                         Assert.IsNull (ex.InnerException, "#3");
2541                                         Assert.IsNotNull (ex.Message, "#4");
2542                                         Assert.IsTrue (ex.Message.IndexOf (path) != -1, "#5");
2543                                 }
2544                         } finally {
2545                                 if (stream != null)
2546                                         stream.Close ();
2547                                 DeleteFile (path);
2548                         }
2549                 }
2550                 
2551                 [Test]
2552                 public void OpenAppend ()
2553                 {
2554                         string fn = Path.GetTempFileName ();
2555                         using (FileStream s = File.Open (fn, FileMode.Append)) {
2556                         }
2557                         DeleteFile (fn);
2558                 }
2559
2560                         void Position (long value)
2561                 {
2562                         using (FileStream fs = File.OpenRead (testfile)) {
2563                                 fs.Position = value;
2564                                 Assert.AreEqual (value, fs.Position, "Position");
2565                                 Assert.AreEqual (1, fs.Length, "Length");
2566                         }
2567                 }
2568                 
2569                 [Test]
2570                 public void Position_Small ()
2571                 {
2572                         Position (Int32.MaxValue);
2573                 }
2574
2575                 [Test]
2576                 public void Position_Large ()
2577                 {
2578                         // fails if HAVE_LARGE_FILE_SUPPORT is not enabled in device builds
2579                         Position ((long) Int32.MaxValue + 1);
2580                 }
2581                 
2582                 void Seek (long value)
2583                 {
2584                         using (FileStream fs = File.OpenRead (testfile)) {
2585                                 fs.Seek (value, SeekOrigin.Begin);
2586                                 Assert.AreEqual (value, fs.Position, "Position");
2587                                 Assert.AreEqual (1, fs.Length, "Length");
2588                         }
2589                 }
2590                 
2591                 [Test]
2592                 public void Seek_Small ()
2593                 {
2594                         Seek (Int32.MaxValue);
2595                 }
2596
2597                 [Test]
2598                 public void Seek_Large ()
2599                 {
2600                         // fails if HAVE_LARGE_FILE_SUPPORT is not enabled in device builds
2601                         Seek ((long) Int32.MaxValue + 1);
2602                 }
2603                 
2604                 void LockUnlock (long value)
2605                 {
2606                         using (FileStream fs = new FileStream (testfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
2607                                 fs.Lock (value - 1, 1);
2608                                 fs.Unlock (value - 1, 1);
2609                                 
2610                                 fs.Lock (0, value);
2611                                 fs.Unlock (0, value);
2612                         }
2613                 }
2614                 
2615                 [Test]
2616                 public void Lock_Small ()
2617                 {
2618                         LockUnlock ((long) Int32.MaxValue);
2619                 }
2620
2621                 [Test]
2622                 public void Lock_Large ()
2623                 {
2624                         // note: already worked without HAVE_LARGE_FILE_SUPPORT
2625                         LockUnlock ((long) Int32.MaxValue + 1);
2626                 }
2627         
2628 #if NET_2_0
2629                 [Test]
2630                 public void ReadWriteAllText ()
2631                 {
2632                         // The MSDN docs said something about
2633                         // not including a final new line. it looks
2634                         // like that was not true. I'm not sure what
2635                         // that was talking about
2636                         read_all (string.Empty);
2637                         read_all ("\r");
2638                         read_all ("\n");
2639                         read_all ("\r\n");
2640                         read_all ("a\r");
2641                         read_all ("a\n");
2642                         read_all ("a\r\n");
2643                         read_all ("a\ra");
2644                         read_all ("a\na");
2645                         read_all ("a\r\na");
2646                         read_all ("a");
2647                         read_all ("\r\r");
2648                         read_all ("\n\n");
2649                         read_all ("\r\n\r\n");
2650                 }
2651
2652                 [Test]
2653                 public void ReplaceTest ()
2654                 {
2655                         string tmp = Path.Combine (TempFolder, "ReplaceTest");
2656                         Directory.CreateDirectory (tmp);
2657                         string origFile = Path.Combine (tmp, "origFile");
2658                         string replaceFile = Path.Combine (tmp, "replaceFile");
2659                         string backupFile = Path.Combine (tmp, "backupFile");
2660
2661                         using (StreamWriter sw = File.CreateText (origFile)) {
2662                                 sw.WriteLine ("origFile");
2663                         }
2664                         using (StreamWriter sw = File.CreateText (replaceFile)) {
2665                                 sw.WriteLine ("replaceFile");
2666                         }
2667                         using (StreamWriter sw = File.CreateText (backupFile)) {
2668                                 sw.WriteLine ("backupFile");
2669                         }
2670
2671                         File.Replace (origFile, replaceFile, backupFile);
2672                         Assert.IsFalse (File.Exists (origFile), "#1");
2673                         using (StreamReader sr = File.OpenText (replaceFile)) {
2674                                 string txt = sr.ReadLine ();
2675                                 Assert.AreEqual ("origFile", txt, "#2");
2676                         }
2677                         using (StreamReader sr = File.OpenText (backupFile)) {
2678                                 string txt = sr.ReadLine ();
2679                                 Assert.AreEqual ("replaceFile", txt, "#3");
2680                         }
2681                 }
2682 #endif
2683
2684                 static bool RunningOnUnix {
2685                         get {
2686                                 int p = (int) Environment.OSVersion.Platform;
2687                                 return ((p == 4) || (p == 128) || (p == 6));
2688                         }
2689                 }
2690
2691                 void DeleteFile (string path)
2692                 {
2693                         if (File.Exists (path))
2694                                 File.Delete (path);
2695                 }
2696
2697                 void DeleteDirectory (string path)
2698                 {
2699                         if (Directory.Exists (path))
2700                                 Directory.Delete (path, true);
2701                 }
2702
2703 #if NET_2_0
2704                 void read_all (string s)
2705                 {
2706                         string f = Path.GetTempFileName ();
2707                         try {
2708                                 File.WriteAllText (f, s);
2709                                 string r = File.ReadAllText (f);
2710                                 Assert.AreEqual (s, r);
2711                         } finally {
2712                                 DeleteFile (f);
2713                         }
2714                 }
2715 #endif
2716
2717                 void MoveTest (FileAccess acc, FileShare share, bool works)
2718                 {
2719                         // use TEMP so since the default location (right along with the assemblies) 
2720                         // will get access denied when running under some environment (e.g. iOS devices)
2721                         var file = Path.Combine (Path.GetTempPath (), "kk597rfdnllh89");
2722
2723                         File.Delete (file + ".old");
2724                         using (var v = File.Create (file)) { }
2725
2726                         using (var stream = new FileStream(file, FileMode.Open, acc, share, 4096, FileOptions.SequentialScan)) {
2727                                 try {
2728                                         File.Move(file, file + ".old");
2729                                         if (!works)
2730                                                 Assert.Fail ("Move with ({0}) and  ({1}) did not fail", acc, share);
2731                                 } catch (IOException) {
2732                                         if (works)
2733                                                 Assert.Fail ("Move with ({0}) and  ({1}) did fail", acc, share);
2734                                 }
2735                         }
2736                 }
2737
2738                 [Test]
2739                 public void MoveTest ()
2740                 {
2741                         MoveTest (FileAccess.Read, FileShare.None, false);
2742                         MoveTest (FileAccess.Read, FileShare.Read, false);
2743                         MoveTest (FileAccess.Read, FileShare.Write, false);
2744                         MoveTest (FileAccess.Read, FileShare.ReadWrite, false);
2745                         MoveTest (FileAccess.Read, FileShare.Delete, true);
2746                         MoveTest (FileAccess.Read, FileShare.Read | FileShare.Delete, true);
2747                         MoveTest (FileAccess.Read, FileShare.Write | FileShare.Delete, true);
2748                         MoveTest (FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, true);
2749                         MoveTest (FileAccess.Write, FileShare.None, false);
2750                         MoveTest (FileAccess.Write, FileShare.Read, false);
2751                         MoveTest (FileAccess.Write, FileShare.Write, false);
2752                         MoveTest (FileAccess.Write, FileShare.ReadWrite, false);
2753                         MoveTest (FileAccess.Write, FileShare.Delete, true);
2754                         MoveTest (FileAccess.Write, FileShare.Read | FileShare.Delete, true);
2755                         MoveTest (FileAccess.Write, FileShare.Write | FileShare.Delete, true);
2756                         MoveTest (FileAccess.Write, FileShare.ReadWrite | FileShare.Delete, true);
2757                         MoveTest (FileAccess.ReadWrite, FileShare.None, false);
2758                         MoveTest (FileAccess.ReadWrite, FileShare.Read, false);
2759                         MoveTest (FileAccess.ReadWrite, FileShare.Write, false);
2760                         MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite, false);
2761                         MoveTest (FileAccess.ReadWrite, FileShare.Delete, true);
2762                         MoveTest (FileAccess.ReadWrite, FileShare.Read | FileShare.Delete, true);
2763                         MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true);
2764                         MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true);
2765                 }
2766         }
2767 }