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