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