Mark tests as not working under TARGET_JVM
[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 using NUnit.Framework;
13 using System;
14 using System.IO;
15 using System.Globalization;
16 using System.Threading;
17
18 namespace MonoTests.System.IO
19 {
20         [TestFixture]
21         public class FileTest : Assertion
22         {
23                 static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
24
25                 [SetUp]
26                 public void SetUp ()
27                 {
28                         if (Directory.Exists (TempFolder))
29                                 Directory.Delete (TempFolder, true);
30                         Directory.CreateDirectory (TempFolder);
31                 
32                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("EN-us");
33                 }
34
35                 [TearDown]
36                 public void TearDown ()
37                 {
38                         if (Directory.Exists (TempFolder))
39                                 Directory.Delete (TempFolder, true);
40                 }
41
42                 [Test]
43                 public void TestExists ()
44                 {
45                         int i = 0;
46                         FileStream s = null;
47                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
48                         try {
49                                 Assert ("null filename should not exist", !File.Exists (null));
50                                 i++;
51                                 Assert ("empty filename should not exist", !File.Exists (""));
52                                 i++;
53                                 Assert ("whitespace filename should not exist", !File.Exists ("  \t\t  \t \n\t\n \n"));
54                                 i++;                            
55                                 DeleteFile (path);
56                                 s = File.Create (path);
57                                 s.Close ();
58                                 Assert ("File " + path + " should exists", File.Exists (path));
59                                 i++;
60                                 Assert ("File resources" + Path.DirectorySeparatorChar + "doesnotexist should not exist", !File.Exists (TempFolder + Path.DirectorySeparatorChar + "doesnotexist"));
61                         } catch (Exception e) {
62                                 Fail ("Unexpected exception at i = " + i + ". e=" + e);
63                         } finally {
64                                 if (s != null)
65                                         s.Close ();
66                                 DeleteFile (path);
67                         }
68                 }
69
70                 [Test]
71                 public void Exists_InvalidFileName () 
72                 {
73                         Assert ("><|", !File.Exists ("><|"));
74                         Assert ("?*", !File.Exists ("?*"));
75                 }
76
77                 [Test]
78                 public void Exists_InvalidDirectory () 
79                 {
80                         Assert ("InvalidDirectory", !File.Exists (Path.Combine ("does not exist", "file.txt")));
81                 }
82
83                 [Test]
84                 [ExpectedException(typeof (ArgumentNullException))]
85                 public void CtorArgumentNullException1 ()
86                 {       
87                         FileStream stream = File.Create (null);
88                 }
89
90                 [Test]
91                 [ExpectedException(typeof (ArgumentException))]
92                 public void CtorArgumentException1 ()
93                 {       
94                         FileStream stream = File.Create ("");
95                 }
96
97                 [Test]
98                 [ExpectedException(typeof (ArgumentException))]
99                 public void CtorArgumentException2 ()
100                 {       
101                         FileStream stream = File.Create (" ");
102                 }
103
104                 [Test]
105                 [ExpectedException(typeof (DirectoryNotFoundException))]
106                 public void CtorDirectoryNotFoundException ()
107                 {       
108                         FileStream stream = null;
109                         string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
110                         
111                         try {
112                                 stream = File.Create (path);
113                         } finally {
114                                 if (stream != null)
115                                         stream.Close ();
116                                 DeleteFile (path);
117                         }
118                 }
119
120                 [Test]
121                 public void TestCreate ()
122                 {
123                         FileStream stream = null;
124                         string path = "";
125                         /* positive test: create resources/foo */
126                         try {
127                                 path = TempFolder + Path.DirectorySeparatorChar + "foo";
128                                 stream = File.Create (path);
129                                 Assert ("File should exist", File.Exists (path));
130                                 stream.Close ();
131                         } catch (Exception e) {
132                                 Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
133                         } finally {
134                                 if (stream != null)
135                                         stream.Close ();
136                                 DeleteFile (path);
137                         }
138                         
139                         path = "";
140                         stream = null;
141
142                         /* positive test: repeat test above again to test for overwriting file */
143                         try {
144                                 path = TempFolder + Path.DirectorySeparatorChar + "foo";
145                                 stream = File.Create (path);
146                                 Assert ("File should exist", File.Exists (path));
147                                 stream.Close ();
148                         } catch (Exception e) {
149                                 Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString()); 
150                         } finally {
151                                 if (stream != null)
152                                         stream.Close ();
153                                 DeleteFile (path);
154                         }
155                 }
156
157                 [Test]
158                 [ExpectedException(typeof(ArgumentNullException))]
159                 public void CopyArgumentNullException1 ()
160                 {
161                         File.Copy (null, "b");
162                 }
163
164                 [Test]
165                 [ExpectedException(typeof(ArgumentNullException))]
166                 public void CopyArgumentNullException2 ()
167                 {
168                         File.Copy ("a", null);
169                 }
170
171                 [Test]
172                 [ExpectedException(typeof(ArgumentException))]
173                 public void CopyArgumentException1 ()
174                 {
175                         File.Copy ("", "b");
176                 }
177
178                 [Test]
179                 [ExpectedException(typeof(ArgumentException))]
180                 public void CopyArgumentException2 ()
181                 {
182                         File.Copy ("a", "");
183                 }
184
185                 [Test]
186                 [ExpectedException(typeof(ArgumentException))]
187                 public void CopyArgumentException3 ()
188                 {
189                         File.Copy (" ", "b");
190                 }
191
192                 [Test]
193                 [ExpectedException(typeof(ArgumentException))]
194                 public void CopyArgumentException4 ()
195                 {
196                         File.Copy ("a", " ");
197                 }
198
199                 [Test]
200                 [ExpectedException(typeof(FileNotFoundException))]
201                 public void CopyFileNotFoundException ()
202                 {
203                         File.Copy ("doesnotexist", "b");
204                 }
205
206                 [ExpectedException(typeof(IOException))]
207                 public void CopyIOException ()
208                 {
209                         DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
210                         DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
211                         try {
212                                 File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
213                                 File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar");
214                                 File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar");
215                         } finally {
216                                 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
217                                 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");                            
218                         }
219                 }
220
221                 [Test]
222                 public void TestCopy ()
223                 {
224                         string path1 = TempFolder + Path.DirectorySeparatorChar + "bar";
225                         string path2 = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
226                         /* positive test: copy resources/AFile.txt to resources/bar */
227                         try {
228                                 try {
229                                         DeleteFile (path1);
230                                         DeleteFile (path2);
231
232                                         File.Create (path2).Close ();
233                                         File.Copy (path2, path1);
234                                         Assert ("File AFile.txt should still exist", File.Exists (path2));
235                                         Assert ("File bar should exist after File.Copy", File.Exists (path1));
236                                 } catch (Exception e) {
237                                         Fail ("#1 File.Copy('resources/AFile.txt', 'resources/bar') unexpected exception caught: e=" + e.ToString());
238                                 }
239
240                                 /* positive test: copy resources/AFile.txt to resources/bar, overwrite */
241                                 try {
242                                         Assert ("File bar should exist before File.Copy", File.Exists (path1));
243                                         File.Copy (path2, path1, true);
244                                         Assert ("File AFile.txt should still exist", File.Exists (path2));
245                                         Assert ("File bar should exist after File.Copy", File.Exists (path1));
246                                 } catch (Exception e) {
247                                         Fail ("File.Copy('resources/AFile.txt', 'resources/bar', true) unexpected exception caught: e=" + e.ToString());
248                                 }
249                         }finally {
250                                 DeleteFile (path1);
251                                 DeleteFile (path2);
252                         }                       
253                 }
254
255                 [Test]
256                 [ExpectedException (typeof (ArgumentNullException))]
257                 public void DeleteArgumentNullException ()
258                 {
259                         File.Delete (null);
260                 }
261
262                 [Test]
263                 [ExpectedException (typeof (ArgumentException))]
264                 public void DeleteArgumentException1 ()
265                 {
266                         File.Delete ("");
267                 }
268
269                 [Test]
270                 [ExpectedException (typeof (ArgumentException))]
271                 public void DeleteArgumentException2 ()
272                 {
273                         File.Delete (" ");
274                 }
275
276                 [Test]
277                 [ExpectedException (typeof (DirectoryNotFoundException))]
278                 public void DeleteDirectoryNotFoundException ()
279                 {
280                         string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
281                         if (Directory.Exists (path))
282                                 Directory.Delete (path, true);
283                         File.Delete (path);                     
284                 }
285
286
287                 [Test]
288                 public void TestDelete ()
289                 {
290                         string foopath = TempFolder + Path.DirectorySeparatorChar + "foo";
291                         DeleteFile (foopath);
292                         try {
293                                 File.Create (foopath).Close ();
294
295                                 try {
296                                         File.Delete (foopath);
297                                 } catch (Exception e) {
298                                         Fail ("Unable to delete " + foopath + " e=" + e.ToString());
299                                 } 
300                                 Assert ("File " + foopath + " should not exist after File.Delete", !File.Exists (foopath));
301                         } finally {
302                                 DeleteFile (foopath);
303                         }
304                 }
305
306                 [Test]
307                 [ExpectedException(typeof (IOException))]
308                 [Category("NotWorking")]
309                 public void DeleteOpenStreamException ()
310                 {
311                         string path = TempFolder + Path.DirectorySeparatorChar + "DeleteOpenStreamException";
312                         DeleteFile (path);                      
313                         FileStream stream = null;
314                         try {
315                                 stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
316                                 File.Delete (path);
317                         } finally {
318                                 if (stream != null)
319                                         stream.Close ();
320                                 DeleteFile (path);
321                         }
322                 }
323                 
324                 [Test]
325                 [ExpectedException(typeof (ArgumentNullException))]
326                 public void MoveException1 ()
327                 {
328                         File.Move (null, "b");
329                 }
330
331                 [Test]
332                 [ExpectedException(typeof (ArgumentNullException))]
333                 public void MoveException2 ()
334                 {
335                         File.Move ("a", null);
336                 }
337
338                 [Test]
339                 [ExpectedException(typeof (ArgumentException))]
340                 public void MoveException3 ()
341                 {
342                         File.Move ("", "b");
343                 }
344
345                 [Test]
346                 [ExpectedException(typeof (ArgumentException))]
347                 public void MoveException4 ()
348                 {
349                         File.Move ("a", "");
350                 }
351
352                 [Test]
353                 [ExpectedException(typeof (ArgumentException))]
354                 public void MoveException5 ()
355                 {
356                         File.Move (" ", "b");                   
357                 }
358
359                 [Test]
360                 [ExpectedException(typeof (ArgumentException))]
361                 public void MoveException6 ()
362                 {
363                         File.Move ("a", " ");
364                 }
365
366                 [Test]
367                 [ExpectedException(typeof (FileNotFoundException))]
368                 public void MoveException7 ()
369                 {
370                         DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist");                 
371                         File.Move (TempFolder + Path.DirectorySeparatorChar + "doesnotexist", "b");
372                 }
373
374                 [Test]
375                 [ExpectedException(typeof (DirectoryNotFoundException))]
376                 public void MoveException8 ()
377                 {
378                         string path = TempFolder + Path.DirectorySeparatorChar + "foo";
379                         DeleteFile (path);
380                         try {
381                                 File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
382                                 File.Copy(TempFolder + Path.DirectorySeparatorChar + "AFile.txt", path, true);
383                                 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
384                                 File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
385                         } finally {
386                                 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
387                                 DeleteFile (path);
388                         }
389                 }
390
391                 [Test]
392                 [ExpectedException(typeof (IOException))]
393                 public void MoveException9 ()
394                 {
395                         File.Create (TempFolder + Path.DirectorySeparatorChar + "foo").Close ();
396                         try {
397                                 File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder);               
398                         } finally {
399                                 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "foo");
400                         }
401                 }
402
403                 [Test]
404                 public void TestMove ()
405                 {
406                         string bar = TempFolder + Path.DirectorySeparatorChar + "bar";
407                         string baz = TempFolder + Path.DirectorySeparatorChar + "baz";
408                         if (!File.Exists (bar)) {
409                                 FileStream f = File.Create(bar);
410                                 f.Close();
411                         }
412                         
413                         Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should exist", File.Exists (bar));
414                         File.Move (bar, baz);
415                         Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should not exist", !File.Exists (bar));
416                         Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "baz should exist", File.Exists (baz));
417
418                         // Test moving of directories
419                         string dir = Path.Combine (TempFolder, "dir");
420                         string dir2 = Path.Combine (TempFolder, "dir2");
421                         string dir_foo = Path.Combine (dir, "foo");
422                         string dir2_foo = Path.Combine (dir2, "foo");
423
424                         if (Directory.Exists (dir))
425                                 Directory.Delete (dir, true);
426                                                 
427                         Directory.CreateDirectory (dir);
428                         Directory.CreateDirectory (dir2);
429                         File.Create (dir_foo).Close ();
430                         File.Move (dir_foo, dir2_foo);
431                         Assert (File.Exists (dir2_foo));
432                         
433                         Directory.Delete (dir, true);
434                         Directory.Delete (dir2, true);
435                         DeleteFile (dir_foo);
436                         DeleteFile (dir2_foo);
437                 }
438
439                 [Test]
440                 public void TestOpen ()
441                 {
442                         string path = "";
443                         FileStream stream = null;
444                         try {
445                                 path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
446                                 if (!File.Exists (path))
447                                         stream = File.Create (path);
448                                 stream.Close ();
449                                 stream = File.Open (path, FileMode.Open);
450                                 stream.Close ();
451                         } catch (Exception e) {
452                                 Fail ("Unable to open " + TempFolder + Path.DirectorySeparatorChar + "AFile.txt: e=" + e.ToString());
453                         } finally {
454                                 if (stream != null)
455                                         stream.Close ();
456                                 DeleteFile (path);
457                         }
458                         
459                         path = "";
460                         stream = null;
461                         /* Exception tests */
462                         try {
463                                 path = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
464                                 stream = File.Open (path, FileMode.Open);
465                                 Fail ("File 'filedoesnotexist' should not exist");
466                         } catch (FileNotFoundException) {
467                                 // do nothing, this is what we expect
468                         } catch (Exception e) {
469                                 Fail ("Unexpect exception caught: e=" + e.ToString());
470                         } finally {
471                                 if (stream != null)
472                                         stream.Close ();
473                                 DeleteFile (path);
474                         }
475                 }
476
477                 [Test]
478                 public void Open () 
479                 {
480                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
481                         if (!File.Exists (path))
482                                 File.Create (path).Close ();
483                         FileStream stream = null;
484                         try {
485                         
486                                 stream = File.Open (path, FileMode.Open);
487                         
488                                 Assertion.AssertEquals ("test#01", true, stream.CanRead);
489                                 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
490                                 Assertion.AssertEquals ("test#03", true, stream.CanWrite);
491                                 stream.Close ();
492                         
493                                 stream = File.Open (path, FileMode.Open, FileAccess.Write);
494                                 Assertion.AssertEquals ("test#04", false, stream.CanRead);
495                                 Assertion.AssertEquals ("test#05", true, stream.CanSeek);
496                                 Assertion.AssertEquals ("test#06", true, stream.CanWrite);
497                                 stream.Close ();
498                                         
499                                 stream = File.Open (path, FileMode.Open, FileAccess.Read);
500                                 Assertion.AssertEquals ("test#04", true, stream.CanRead);
501                                 Assertion.AssertEquals ("test#05", true, stream.CanSeek);
502                                 Assertion.AssertEquals ("test#06", false, stream.CanWrite);
503                                 stream.Close ();
504                                 
505                         } finally {
506                                 if (stream != null)
507                                         stream.Close ();
508                                 DeleteFile (path);
509                         }
510                 }
511                 
512                 [Test]
513                 [ExpectedException(typeof(ArgumentException))]
514                 public void OpenException1 ()
515                 {
516                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
517                         FileStream stream = null;
518                         // CreateNew + Read throws an exceptoin
519                         try {
520                                 stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.CreateNew, FileAccess.Read);
521                         } finally {
522                                 if (stream != null)
523                                         stream.Close ();
524                                 DeleteFile (path);
525                         }
526                 }
527
528                 [Test]
529                 [ExpectedException(typeof(ArgumentException))]
530                 public void OpenException2 ()
531                 {
532                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
533                         FileStream s = null;
534                         // Append + Read throws an exceptoin
535                         if (!File.Exists (path))
536                                 File.Create (path).Close ();
537                         try {
538                                 s = File.Open (path, FileMode.Append, FileAccess.Read);
539                         } finally {
540                                 if (s != null)
541                                         s.Close ();
542                                 DeleteFile (path);
543                         }
544                 }
545                 
546                 [Test]
547                 public void OpenRead ()
548                 {
549                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
550                         if (!File.Exists (path))
551                                 File.Create (path).Close ();
552                         FileStream stream = null;
553                         
554                         try {
555                                 stream = File.OpenRead (path);
556                         
557                                 Assertion.AssertEquals ("test#01", true, stream.CanRead);
558                                 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
559                                 Assertion.AssertEquals ("test#03", false, stream.CanWrite);
560                                 
561                         } finally {
562                                 if (stream != null)
563                                         stream.Close ();
564                                 DeleteFile (path);
565                         }
566                 }
567
568                 [Test]
569                 public void OpenWrite ()
570                 {
571                         string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
572                         if (!File.Exists (path))
573                                 File.Create (path).Close ();
574                         FileStream stream = null;
575                         
576                         try {
577                                 stream = File.OpenWrite (path);
578                                 Assertion.AssertEquals ("test#01", false, stream.CanRead);
579                                 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
580                                 Assertion.AssertEquals ("test#03", true, stream.CanWrite);
581                                 stream.Close ();                                                                        
582                         } finally {
583                                 if (stream != null)
584                                         stream.Close ();
585                                 DeleteFile (path);
586                         }
587                 }
588
589                 [Test]
590                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
591                 public void TestGetCreationTime ()
592                 {
593                         string path = TempFolder + Path.DirectorySeparatorChar + "baz";
594                         DeleteFile (path);
595                         
596                         try {
597                                 File.Create (path).Close();
598                                 DateTime time = File.GetCreationTime (path);
599                                 Assert ("GetCreationTime incorrect", (DateTime.Now - time).TotalSeconds < 10);
600                         } finally {
601                                 DeleteFile (path);
602                         }
603                 }
604
605                 // Setting the creation time on Unix is not possible
606                 [Test]
607                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
608                 public void CreationTime ()
609                 {
610                         int platform = (int) Environment.OSVersion.Platform;
611                         if ((platform == 4) || (platform == 128))
612                                 return;
613
614                         string path = Path.GetTempFileName ();  
615                         
616                         try {
617                                 File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
618                                 DateTime time = File.GetCreationTime (path);
619                                 Assertion.AssertEquals ("test#01", 2002, time.Year);
620                                 Assertion.AssertEquals ("test#02", 4, time.Month);
621                                 Assertion.AssertEquals ("test#03", 6, time.Day);
622                                 Assertion.AssertEquals ("test#04", 4, time.Hour);
623                                 Assertion.AssertEquals ("test#05", 4, time.Second);
624                         
625                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
626                                 Assertion.AssertEquals ("test#06", 2002, time.Year);
627                                 Assertion.AssertEquals ("test#07", 4, time.Month);
628                                 Assertion.AssertEquals ("test#08", 6, time.Day);
629                                 Assertion.AssertEquals ("test#09", 4, time.Hour);
630                                 Assertion.AssertEquals ("test#10", 4, time.Second);                     
631
632                                 File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
633                                 time = File.GetCreationTimeUtc (path);
634                                 Assertion.AssertEquals ("test#11", 2002, time.Year);
635                                 Assertion.AssertEquals ("test#12", 4, time.Month);
636                                 Assertion.AssertEquals ("test#13", 6, time.Day);
637                                 Assertion.AssertEquals ("test#14", 4, time.Hour);
638                                 Assertion.AssertEquals ("test#15", 4, time.Second);
639                         
640                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
641                                 Assertion.AssertEquals ("test#16", 2002, time.Year);
642                                 Assertion.AssertEquals ("test#17", 4, time.Month);
643                                 Assertion.AssertEquals ("test#18", 6, time.Day);
644                                 Assertion.AssertEquals ("test#19", 4, time.Hour);
645                                 Assertion.AssertEquals ("test#20", 4, time.Second);
646                         } finally {
647                                 DeleteFile (path);
648                         }
649                 }
650
651                 [Test]
652                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
653                 public void LastAccessTime ()
654                 {
655                         string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";                      
656                         if (File.Exists (path))
657                                 File.Delete (path);
658                         FileStream stream = null;
659                         try {
660                                 stream = File.Create (path);
661                                 stream.Close ();                        
662                         
663                                 File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
664                                 DateTime time = File.GetLastAccessTime (path);
665                                 Assertion.AssertEquals ("test#01", 2002, time.Year);
666                                 Assertion.AssertEquals ("test#02", 4, time.Month);
667                                 Assertion.AssertEquals ("test#03", 6, time.Day);
668                                 Assertion.AssertEquals ("test#04", 4, time.Hour);
669                                 Assertion.AssertEquals ("test#05", 4, time.Second);
670                         
671                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
672                                 Assertion.AssertEquals ("test#06", 2002, time.Year);
673                                 Assertion.AssertEquals ("test#07", 4, time.Month);
674                                 Assertion.AssertEquals ("test#08", 6, time.Day);
675                                 Assertion.AssertEquals ("test#09", 4, time.Hour);
676                                 Assertion.AssertEquals ("test#10", 4, time.Second);                     
677         
678                                 File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
679                                 time = File.GetLastAccessTimeUtc (path);
680                                 Assertion.AssertEquals ("test#11", 2002, time.Year);
681                                 Assertion.AssertEquals ("test#12", 4, time.Month);
682                                 Assertion.AssertEquals ("test#13", 6, time.Day);
683                                 Assertion.AssertEquals ("test#14", 4, time.Hour);
684                                 Assertion.AssertEquals ("test#15", 4, time.Second);
685                         
686                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
687                                 Assertion.AssertEquals ("test#16", 2002, time.Year);
688                                 Assertion.AssertEquals ("test#17", 4, time.Month);
689                                 Assertion.AssertEquals ("test#18", 6, time.Day);
690                                 Assertion.AssertEquals ("test#19", 4, time.Hour);
691                                 Assertion.AssertEquals ("test#20", 4, time.Second);
692                         } finally {
693                                 if (stream != null)
694                                         stream.Close ();
695                                 DeleteFile (path);                                      
696                         }
697                 }
698                 
699                 [Test]
700                 public void LastWriteTime ()
701                 {
702                         string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";                       
703                         if (File.Exists (path))
704                                 File.Delete (path);
705                         FileStream stream = null;
706                         try {
707                                 stream = File.Create (path);
708                                 stream.Close ();                        
709                         
710                                 File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
711                                 DateTime time = File.GetLastWriteTime (path);
712                                 Assertion.AssertEquals ("test#01", 2002, time.Year);
713                                 Assertion.AssertEquals ("test#02", 4, time.Month);
714                                 Assertion.AssertEquals ("test#03", 6, time.Day);
715                                 Assertion.AssertEquals ("test#04", 4, time.Hour);
716                                 Assertion.AssertEquals ("test#05", 4, time.Second);
717                                 
718                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
719                                 Assertion.AssertEquals ("test#06", 2002, time.Year);
720                                 Assertion.AssertEquals ("test#07", 4, time.Month);
721                                 Assertion.AssertEquals ("test#08", 6, time.Day);
722                                 Assertion.AssertEquals ("test#09", 4, time.Hour);
723                                 Assertion.AssertEquals ("test#10", 4, time.Second);                     
724         
725                                 File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
726                                 time = File.GetLastWriteTimeUtc (path);
727                                 Assertion.AssertEquals ("test#11", 2002, time.Year);
728                                 Assertion.AssertEquals ("test#12", 4, time.Month);
729                                 Assertion.AssertEquals ("test#13", 6, time.Day);
730                                 Assertion.AssertEquals ("test#14", 4, time.Hour);
731                                 Assertion.AssertEquals ("test#15", 4, time.Second);
732                                 
733                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
734                                 Assertion.AssertEquals ("test#16", 2002, time.Year);
735                                 Assertion.AssertEquals ("test#17", 4, time.Month);
736                                 Assertion.AssertEquals ("test#18", 6, time.Day);
737                                 Assertion.AssertEquals ("test#19", 4, time.Hour);
738                                 Assertion.AssertEquals ("test#20", 4, time.Second);
739                         } finally {
740                                 if (stream != null)
741                                         stream.Close ();
742                                 DeleteFile (path);
743                         }
744                 }
745
746                 [Test]
747                 [ExpectedException(typeof(ArgumentNullException))]      
748                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
749                 public void GetCreationTimeException1 ()
750                 {
751                         File.GetCreationTime (null as string);
752                 }
753
754                 [Test]
755                 [ExpectedException(typeof(ArgumentException))]  
756                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
757                 public void GetCreationTimeException2 ()
758                 {
759                         File.GetCreationTime ("");
760                 }
761         
762                 [Test]
763 #if !NET_2_0
764                 [ExpectedException(typeof(IOException))]
765 #endif
766                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
767                 public void GetCreationTime_NonExistingPath ()
768                 {
769                         string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
770                         DeleteFile (path);
771                         DateTime time = File.GetCreationTime (path);
772
773 #if NET_2_0
774                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
775                         Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
776                         Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
777                         Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
778                         Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
779                         Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
780                         Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
781 #endif
782                 }
783
784                 [Test]
785                 [ExpectedException(typeof(ArgumentException))]
786                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
787                 public void GetCreationTimeException4 ()
788                 {
789                         File.GetCreationTime ("    ");
790                 }
791
792                 [Test]
793                 [ExpectedException(typeof(ArgumentException))]
794                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
795                 public void GetCreationTimeException5 ()
796                 {
797                         File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
798                 }
799
800                 [Test]
801                 [ExpectedException(typeof(ArgumentNullException))]
802                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
803                 public void GetCreationTimeUtcException1 ()
804                 {
805                         File.GetCreationTimeUtc (null as string);
806                 }
807
808                 [Test]
809                 [ExpectedException(typeof(ArgumentException))]
810                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
811                 public void GetCreationTimeUtcException2 ()
812                 {
813                         File.GetCreationTimeUtc ("");
814                 }
815         
816                 [Test]
817 #if !NET_2_0
818                 [ExpectedException (typeof (IOException))]
819 #endif
820                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
821                 public void GetCreationTimeUtc_NonExistingPath ()
822                 {
823                         string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
824                         DeleteFile (path);
825                         DateTime time = File.GetCreationTimeUtc (path);
826
827 #if NET_2_0
828                         Assertion.AssertEquals ("#1", 1601, time.Year);
829                         Assertion.AssertEquals ("#2", 1, time.Month);
830                         Assertion.AssertEquals ("#3", 1, time.Day);
831                         Assertion.AssertEquals ("#4", 0, time.Hour);
832                         Assertion.AssertEquals ("#5", 0, time.Second);
833                         Assertion.AssertEquals ("#6", 0, time.Millisecond);
834 #endif
835                 }
836
837                 [Test]
838                 [ExpectedException(typeof(ArgumentException))]
839                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
840                 public void GetCreationTimeUtcException4 ()
841                 {
842                         File.GetCreationTimeUtc ("    ");
843                 }
844
845                 [Test]
846                 [ExpectedException(typeof(ArgumentException))]
847                 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
848                 public void GetCreationTimeUtcException5 ()
849                 {
850                         File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
851                 }
852
853                 [Test]
854                 [ExpectedException(typeof(ArgumentNullException))]
855                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
856                 public void GetLastAccessTimeException1 ()
857                 {
858                         File.GetLastAccessTime (null as string);
859                 }
860
861                 [Test]
862                 [ExpectedException(typeof(ArgumentException))]
863                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
864                 public void GetLastAccessTimeException2 ()
865                 {
866                         File.GetLastAccessTime ("");
867                 }
868         
869                 [Test]
870 #if !NET_2_0
871                 [ExpectedException (typeof (IOException))]
872 #endif
873                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
874                 public void GetLastAccessTime_NonExistingPath ()
875                 {
876                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
877                         DeleteFile (path);
878                         DateTime time = File.GetLastAccessTime (path);
879
880 #if NET_2_0
881                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
882                         Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
883                         Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
884                         Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
885                         Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
886                         Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
887                         Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
888 #endif
889                 }
890
891                 [Test]
892                 [ExpectedException(typeof(ArgumentException))]
893                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
894                 public void GetLastAccessTimeException4 ()
895                 {
896                         File.GetLastAccessTime ("    ");
897                 }
898
899                 [Test]
900                 [ExpectedException(typeof(ArgumentException))]
901                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
902                 public void GetLastAccessTimeException5 ()
903                 {
904                         File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
905                 }
906
907                 [Test]
908                 [ExpectedException(typeof(ArgumentNullException))]
909                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
910                 public void GetLastAccessTimeUtcException1 ()
911                 {
912                         File.GetLastAccessTimeUtc (null as string);
913                 }
914
915                 [Test]
916                 [ExpectedException(typeof(ArgumentException))]
917                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
918                 public void GetLastAccessTimeUtcException2 ()
919                 {
920                         File.GetLastAccessTimeUtc ("");
921                 }
922         
923                 [Test]
924 #if !NET_2_0
925                 [ExpectedException (typeof (IOException))]
926 #endif
927                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
928                 public void GetLastAccessTimeUtc_NonExistingPath ()
929                 {
930                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
931                         DeleteFile (path);
932                         DateTime time = File.GetLastAccessTimeUtc (path);
933
934 #if NET_2_0
935                         Assertion.AssertEquals ("#1", 1601, time.Year);
936                         Assertion.AssertEquals ("#2", 1, time.Month);
937                         Assertion.AssertEquals ("#3", 1, time.Day);
938                         Assertion.AssertEquals ("#4", 0, time.Hour);
939                         Assertion.AssertEquals ("#5", 0, time.Second);
940                         Assertion.AssertEquals ("#6", 0, time.Millisecond);
941 #endif
942                 }
943
944                 [Test]
945                 [ExpectedException(typeof(ArgumentException))]
946                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
947                 public void GetLastAccessTimeUtcException4 ()
948                 {
949                         File.GetLastAccessTimeUtc ("    ");
950                 }
951
952                 [Test]
953                 [ExpectedException(typeof(ArgumentException))]
954                 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
955                 public void GetLastAccessTimeUtcException5 ()
956                 {
957                         File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
958                 }
959
960                 [Test]
961                 [ExpectedException(typeof(ArgumentNullException))]
962                 public void GetLastWriteTimeException1 ()
963                 {
964                         File.GetLastWriteTime (null as string);
965                 }
966
967                 [Test]
968                 [ExpectedException(typeof(ArgumentException))]
969                 public void GetLastWriteTimeException2 ()
970                 {
971                         File.GetLastWriteTime ("");
972                 }
973         
974                 [Test]
975 #if !NET_2_0
976                 [ExpectedException (typeof (IOException))]
977 #endif
978                 public void GetLastWriteTime_NonExistingPath ()
979                 {
980                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
981                         DeleteFile (path);
982                         DateTime time = File.GetLastWriteTime (path);
983
984 #if NET_2_0
985                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
986                         Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
987                         Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
988                         Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
989                         Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
990                         Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
991                         Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
992 #endif
993                 }
994
995                 [Test]
996                 [ExpectedException(typeof(ArgumentException))]
997                 public void GetLastWriteTimeException4 ()
998                 {
999                         File.GetLastWriteTime ("    ");
1000                 }
1001
1002                 [Test]
1003                 [ExpectedException(typeof(ArgumentException))]
1004                 public void GetLastWriteTimeException5 ()
1005                 {
1006                         File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
1007                 }
1008
1009                 [Test]
1010                 [ExpectedException(typeof(ArgumentNullException))]
1011                 public void GetLastWriteTimeUtcException1 ()
1012                 {
1013                         File.GetLastWriteTimeUtc (null as string);
1014                 }
1015
1016                 [Test]
1017                 [ExpectedException(typeof(ArgumentException))]
1018                 public void GetLastWriteTimeUtcException2 ()
1019                 {
1020                         File.GetLastWriteTimeUtc ("");
1021                 }
1022         
1023                 [Test]
1024 #if !NET_2_0
1025                 [ExpectedException (typeof (IOException))]
1026 #endif
1027                 public void GetLastWriteTimeUtc_NonExistingPath ()
1028                 {
1029                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
1030                         DeleteFile (path);
1031                         DateTime time = File.GetLastWriteTimeUtc (path);
1032
1033 #if NET_2_0
1034                         Assertion.AssertEquals ("#1", 1601, time.Year);
1035                         Assertion.AssertEquals ("#2", 1, time.Month);
1036                         Assertion.AssertEquals ("#3", 1, time.Day);
1037                         Assertion.AssertEquals ("#4", 0, time.Hour);
1038                         Assertion.AssertEquals ("#5", 0, time.Second);
1039                         Assertion.AssertEquals ("#6", 0, time.Millisecond);
1040 #endif
1041                 }
1042
1043                 [Test]
1044                 [ExpectedException(typeof(ArgumentException))]
1045                 public void GetLastWriteTimeUtcException4 ()
1046                 {
1047                         File.GetLastWriteTimeUtc ("    ");
1048                 }
1049
1050                 [Test]
1051                 [ExpectedException(typeof(ArgumentException))]
1052                 public void GetLastWriteTimeUtcException5 ()
1053                 {
1054                         File.GetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString ());
1055                 }               
1056
1057                 [Test]
1058                 public void FileStreamClose ()
1059                 {
1060                         string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
1061                         FileStream stream = null;
1062                         try {
1063                                 stream = File.Create (path);
1064                                 stream.Close ();
1065                                 File.Delete (path);
1066                         } finally {
1067                                 if (stream != null)
1068                                         stream.Close ();
1069                                 DeleteFile (path);
1070                         }
1071                 }
1072                 
1073                 // SetCreationTime and SetCreationTimeUtc exceptions
1074
1075                 [Test]
1076                 [ExpectedException(typeof (ArgumentNullException))]
1077                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1078                 public void SetCreationTimeArgumentNullException1 ()
1079                 {
1080                         File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1081                 }
1082
1083                 [Test]
1084                 [ExpectedException(typeof (ArgumentException))]
1085                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1086                 public void SetCreationTimeArgumenException1 ()
1087                 {
1088                         File.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1089                 }
1090
1091                 [Test]
1092                 [ExpectedException(typeof (ArgumentException))]
1093                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1094                 public void SetCreationTimeArgumenException2 ()
1095                 {
1096                         File.SetCreationTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1097                 }
1098
1099                 [Test]
1100                 // On Unix there are no invalid path chars.
1101                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1102                 public void SetCreationTimeArgumenException3 ()
1103                 {
1104                         if (Path.InvalidPathChars.Length > 1) {
1105                                 bool pass = false;
1106                                 try {
1107                                         File.SetCreationTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1108                                 } catch (ArgumentException) {
1109                                         pass = true;
1110                                 }
1111
1112                                 Assertion.Assert ("#01", pass);
1113                         }
1114                 }
1115
1116                 [Test]
1117                 [ExpectedException(typeof (FileNotFoundException))]
1118                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1119                 public void SetCreationTimeFileNotFoundException1 ()
1120                 {
1121                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
1122                         DeleteFile (path);
1123                         
1124                         File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1125                 }
1126
1127 //              [Test]
1128 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1129 //              public void SetCreationTimeArgumentOutOfRangeException1 ()
1130 //              {
1131 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
1132 //                      FileStream stream = null;
1133 //                      DeleteFile (path);
1134 //                      try {
1135 //                              stream = File.Create (path);
1136 //                              stream.Close ();
1137 //                              File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1138 //                      } finally {
1139 //                              if (stream != null)
1140 //                                      stream.Close ();
1141 //                              DeleteFile (path);
1142 //                      }
1143 //              }
1144
1145                 [Test]
1146                 [ExpectedException(typeof (IOException))]
1147                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1148                 public void SetCreationTimeIOException1 ()
1149                 {
1150                         string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
1151                         DeleteFile (path);
1152                         FileStream stream = null;
1153                         try {
1154                                 stream = File.Create (path);
1155                                 File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1156                         } finally {
1157                                 if (stream != null)
1158                                         stream.Close ();
1159                                 DeleteFile (path);
1160                         }
1161                 }
1162
1163                 [Test]
1164                 [ExpectedException(typeof (ArgumentNullException))]
1165                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1166                 public void SetCreationTimeUtcArgumentNullException1 ()
1167                 { 
1168                         File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1169                 }
1170
1171                 [Test]
1172                 [ExpectedException(typeof (ArgumentException))]
1173                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1174                 public void SetCreationTimeUtcArgumenException1 ()
1175                 {
1176                         File.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1177                 }
1178
1179                 [Test]
1180                 [ExpectedException(typeof (ArgumentException))]
1181                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1182                 public void SetCreationTimeUtcArgumenException2 ()
1183                 {
1184                         File.SetCreationTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1185                 }
1186
1187                 [Test]
1188                 // On Unix there are no invalid path chars.
1189                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1190                 public void SetCreationTimeUtcArgumentException3 ()
1191                 {
1192                         if (Path.InvalidPathChars.Length > 1) {
1193                                 bool pass = false;
1194                                 try {
1195                                         File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1196                                 } catch (ArgumentException) {
1197                                         pass = true;
1198                                 }
1199
1200                                 Assertion.Assert ("#01", pass);
1201                         }
1202                 }
1203
1204                 [Test]
1205                 [ExpectedException(typeof (FileNotFoundException))]
1206                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1207                 public void SetCreationTimeUtcFileNotFoundException1 ()
1208                 {
1209                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
1210                         DeleteFile (path);
1211                         
1212                         File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1213                 }
1214
1215 //              [Test]
1216 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1217 //              public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
1218 //              {
1219 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
1220 //                      DeleteFile (path);
1221 //                      FileStream stream = null;
1222 //                      try {                           
1223 //                              stream = File.Create (path);
1224 //                              stream.Close ();
1225 //                              File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1226 //                      } finally {
1227 //                              if (stream != null)
1228 //                                      stream.Close();
1229 //                              DeleteFile (path);
1230 //                      }
1231 //              }
1232
1233                 [Test]
1234                 [ExpectedException(typeof (IOException))]
1235                 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
1236                 public void SetCreationTimeUtcIOException1 ()
1237                 {
1238                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
1239                         DeleteFile (path);
1240                         FileStream stream = null;
1241                         try {
1242                                 stream = File.Create (path);
1243                                 File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1244                         } finally {
1245                                 if (stream != null)
1246                                         stream.Close ();
1247                                 DeleteFile (path);
1248                         }
1249                 }
1250
1251                 // SetLastAccessTime and SetLastAccessTimeUtc exceptions
1252
1253                 [Test]
1254                 [ExpectedException(typeof (ArgumentNullException))]
1255                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1256                 public void SetLastAccessTimeArgumentNullException1 ()
1257                 {
1258                         File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1259                 }
1260
1261                 [Test]
1262                 [ExpectedException(typeof (ArgumentException))]
1263                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1264                 public void SetLastAccessTimeArgumenException1 ()
1265                 {
1266                         File.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1267                 }
1268
1269                 [Test]
1270                 [ExpectedException(typeof (ArgumentException))]
1271                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1272                 public void SetLastAccessTimeArgumenException2 ()
1273                 {
1274                         File.SetLastAccessTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1275                 }
1276
1277                 [Test]
1278                 // On Unix there are no invalid path chars.
1279                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1280                 public void SetLastAccessTimeArgumenException3 ()
1281                 {
1282                         if (Path.InvalidPathChars.Length > 1) {
1283                                 bool pass = false;
1284                                 try {
1285                                         File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1286                                 } catch (ArgumentException) {
1287                                         pass = true;
1288                                 }
1289
1290                                 Assertion.Assert ("#01", pass);
1291                         }
1292                 }
1293
1294                 [Test]
1295                 [ExpectedException(typeof (FileNotFoundException))]
1296                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1297                 public void SetLastAccessTimeFileNotFoundException1 ()
1298                 {
1299                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
1300                         DeleteFile (path);
1301                         
1302                         File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1303                 }
1304
1305 //              [Test]
1306 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1307 //              public void SetLastAccessTimeArgumentOutOfRangeException1 ()
1308 //              {
1309 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
1310 //                      DeleteFile (path);
1311 //                      FileStream stream = null;
1312 //                      try {
1313 //                              stream = File.Create (path);
1314 //                              stream.Close ();
1315 //                              File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1316 //                      } finally {
1317 //                              if (stream != null)
1318 //                                      stream.Close ();
1319 //                              DeleteFile (path);
1320 //                      }
1321 //              }
1322
1323                 [Test]
1324                 [ExpectedException(typeof (IOException))]
1325                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1326                 public void SetLastAccessTimeIOException1 ()
1327                 {
1328                         string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
1329                         DeleteFile (path);
1330                         FileStream stream = null;
1331                         try {
1332                                 stream = File.Create (path);
1333                                 File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1334                         } finally {
1335                                 if (stream != null)
1336                                         stream.Close ();
1337                                 DeleteFile (path);
1338                         }
1339                 }
1340
1341                 [Test]
1342                 [ExpectedException(typeof (ArgumentNullException))]
1343                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1344                 public void SetLastAccessTimeUtcArgumentNullException1 ()
1345                 {
1346                         File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1347                 }
1348
1349                 [Test]
1350                 [ExpectedException(typeof (ArgumentException))]
1351                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1352                 public void SetCLastAccessTimeUtcArgumenException1 ()
1353                 {
1354                         File.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1355                 }
1356
1357                 [Test]
1358                 [ExpectedException(typeof (ArgumentException))]
1359                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1360                 public void SetLastAccessTimeUtcArgumenException2 ()
1361                 {
1362                         File.SetLastAccessTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1363                 }
1364
1365                 [Test]
1366                 // On Unix there are no invalid path chars.
1367                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1368                 public void SetLastAccessTimeUtcArgumenException3 ()
1369                 {
1370                         if (Path.InvalidPathChars.Length > 1) {
1371                                 bool pass = false;
1372                                 try {
1373                                         File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1374                                 } catch (ArgumentException) {
1375                                         pass = true;
1376                                 }
1377
1378                                 Assertion.Assert ("#01", pass);
1379                         }
1380                 }
1381
1382                 [Test]
1383                 [ExpectedException(typeof (FileNotFoundException))]
1384                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1385                 public void SetLastAccessTimeUtcFileNotFoundException1 ()
1386                 {
1387                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
1388                         DeleteFile (path);
1389                         
1390                         File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1391                 }
1392
1393 //              [Test]
1394 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1395 //              public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
1396 //              {
1397 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
1398 //                      DeleteFile (path);
1399 //                      FileStream stream = null;
1400 //                      try {
1401 //                              stream = File.Create (path);
1402 //                              stream.Close ();
1403 //                              File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1404 //                      } finally {
1405 //                              if (stream != null)
1406 //                                      stream.Close ();
1407 //                              DeleteFile (path);
1408 //                      }
1409 //              }
1410
1411                 [Test]
1412                 [ExpectedException(typeof (IOException))]
1413                 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
1414                 public void SetLastAccessTimeUtcIOException1 ()
1415                 {
1416                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
1417                         DeleteFile (path);
1418                         FileStream stream = null;
1419                         try {
1420                                 stream = File.Create (path);
1421                                 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1422                         } finally {
1423                                 if (stream != null)
1424                                         stream.Close ();
1425                                 DeleteFile (path);
1426                         }
1427                 }
1428
1429                 // SetLastWriteTime and SetLastWriteTimeUtc exceptions
1430
1431                 [Test]
1432                 [ExpectedException(typeof (ArgumentNullException))]
1433                 public void SetLastWriteTimeArgumentNullException1 ()
1434                 {
1435                         File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1436                 }
1437
1438                 [Test]
1439                 [ExpectedException(typeof (ArgumentException))]
1440                 public void SetLastWriteTimeArgumenException1 ()
1441                 {
1442                         File.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1443                 }
1444
1445                 [Test]
1446                 [ExpectedException(typeof (ArgumentException))]
1447                 public void SetLastWriteTimeArgumenException2 ()
1448                 {
1449                         File.SetLastWriteTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1450                 }
1451
1452                 [Test]
1453                 // On Unix there are no invalid path chars.
1454                 public void SetLastWriteTimeArgumenException3 ()
1455                 {
1456                         if (Path.InvalidPathChars.Length > 1) {
1457                                 bool pass = false;
1458                                 try {
1459                                         File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1460                                 } catch (ArgumentException) {
1461                                         pass = true;
1462                                 }
1463
1464                                 Assertion.Assert ("#01", pass);
1465                         }
1466                 }
1467
1468                 [Test]
1469                 [ExpectedException(typeof (FileNotFoundException))]
1470                 public void SetLastWriteTimeFileNotFoundException1 ()
1471                 {
1472                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
1473                         DeleteFile (path);
1474                         
1475                         File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1476                 }
1477
1478 //              [Test]
1479 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1480 //              public void SetLastWriteTimeArgumentOutOfRangeException1 ()
1481 //              {
1482 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
1483 //                      DeleteFile (path);
1484 //                      FileStream stream = null;
1485 //                      try {
1486 //                              stream = File.Create (path);
1487 //                              stream.Close ();
1488 //                              File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1489 //                      } finally {
1490 //                              if (stream != null)
1491 //                                      stream.Close ();
1492 //                              DeleteFile (path);
1493 //                      }
1494 //              }
1495
1496                 [Test]
1497                 [ExpectedException(typeof (IOException))]
1498                 public void SetLastWriteTimeIOException1 ()
1499                 {
1500                         string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
1501                         DeleteFile (path);
1502                         FileStream stream = null;
1503                         try {
1504                                 stream = File.Create (path);
1505                                 File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1506                         } finally {
1507                                 if (stream != null)
1508                                         stream.Close ();
1509                                 DeleteFile (path);
1510                         }
1511                 }
1512
1513                 [Test]
1514                 [ExpectedException(typeof (ArgumentNullException))]
1515                 public void SetLastWriteTimeUtcArgumentNullException1 ()
1516                 {
1517                         File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1518                 }
1519
1520                 [Test]
1521                 [ExpectedException(typeof (ArgumentException))]
1522                 public void SetCLastWriteTimeUtcArgumenException1 ()
1523                 {
1524                         File.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1525                 }
1526
1527                 [Test]
1528                 [ExpectedException(typeof (ArgumentException))]
1529                 public void SetLastWriteTimeUtcArgumenException2 ()
1530                 {
1531                         File.SetLastWriteTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1532                 }
1533
1534                 [Test]
1535                 // On Unix there are no invalid path chars.
1536                 public void SetLastWriteTimeUtcArgumenException3 ()
1537                 {
1538                         if (Path.InvalidPathChars.Length > 1) {
1539                                 bool pass = false;
1540                                 try {
1541                                         File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1542                                 } catch (ArgumentException) {
1543                                         pass = true;
1544                                 }
1545
1546                                 Assertion.Assert ("#01", pass);
1547                         }
1548                 }
1549
1550                 [Test]
1551                 [ExpectedException(typeof (FileNotFoundException))]
1552                 public void SetLastWriteTimeUtcFileNotFoundException1 ()
1553                 {
1554                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
1555                         DeleteFile (path);
1556                         
1557                         File.SetLastWriteTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1558                 }
1559
1560 //              [Test]
1561 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1562 //              public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
1563 //              {
1564 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
1565 //                      DeleteFile (path);
1566 //                      FileStream stream = null;
1567 //                      try {
1568 //                              stream = File.Create (path);
1569 //                              stream.Close ();
1570 //                              File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1571 //                      } finally {
1572 //                              if (stream != null)
1573 //                                      stream.Close ();
1574 //                              DeleteFile (path);
1575 //                      }
1576 //              }
1577 //
1578                 [Test]
1579                 [ExpectedException(typeof (IOException))]
1580                 public void SetLastWriteTimeUtcIOException1 ()
1581                 {
1582                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
1583                         DeleteFile (path);
1584                         FileStream stream = null;
1585                         try {
1586                                 stream = File.Create (path);
1587                                 File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1588                         } finally {
1589                                 if (stream != null)
1590                                         stream.Close ();
1591                                 DeleteFile (path);
1592                         }
1593                 }
1594                 
1595                 [Test]
1596                 public void OpenAppend ()
1597                 {
1598                         string fn = Path.GetTempFileName ();
1599                         using (FileStream s = File.Open (fn, FileMode.Append))
1600                                 ;
1601                         
1602                         DeleteFile (fn);
1603                 }
1604
1605 #if NET_2_0
1606                 void TestRWAT (string s)
1607                 {
1608                         string f = Path.GetTempFileName ();
1609                         try {
1610                                 File.WriteAllText (f, s);
1611                                 string r = File.ReadAllText (f);
1612                                 AssertEquals (r, s);
1613                         } finally {
1614                                 DeleteFile (f);
1615                         }
1616                 }
1617                 [Test]
1618                 public void ReadWriteAllText ()
1619                 {
1620                         // The MSDN docs said something about
1621                         // not including a final new line. it looks
1622                         // like that was not true. I'm not sure what
1623                         // that was talking about
1624                         TestRWAT ("");
1625                         TestRWAT ("\r");
1626                         TestRWAT ("\n");
1627                         TestRWAT ("\r\n");
1628                         TestRWAT ("a\r");
1629                         TestRWAT ("a\n");
1630                         TestRWAT ("a\r\n");     
1631                         TestRWAT ("a\ra");
1632                         TestRWAT ("a\na");
1633                         TestRWAT ("a\r\na");
1634                         TestRWAT ("a");
1635                         TestRWAT ("\r\r");
1636                         TestRWAT ("\n\n");
1637                         TestRWAT ("\r\n\r\n");
1638                 }
1639 #endif
1640
1641                 private void DeleteFile (string path)
1642                 {
1643                         if (File.Exists (path))
1644                                 File.Delete (path);
1645                 }
1646         }
1647 }