fixed tests
[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 #if TARGET_JVM
591         [Category("NotWorking")]
592 #endif
593                 public void TestGetCreationTime ()
594                 {
595                         string path = TempFolder + Path.DirectorySeparatorChar + "baz";
596                         DeleteFile (path);
597                         
598                         try {
599                                 File.Create (path).Close();
600                                 DateTime time = File.GetCreationTime (path);
601                                 Assert ("GetCreationTime incorrect", (DateTime.Now - time).TotalSeconds < 10);
602                         } finally {
603                                 DeleteFile (path);
604                         }
605                 }
606
607                 // Setting the creation time on Unix is not possible
608                 [Test]
609 #if TARGET_JVM
610         [Category("NotWorking")]
611 #endif
612                 public void CreationTime ()
613                 {
614                         int platform = (int) Environment.OSVersion.Platform;
615                         if ((platform == 4) || (platform == 128))
616                                 return;
617
618                         string path = Path.GetTempFileName ();  
619                         
620                         try {
621                                 File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
622                                 DateTime time = File.GetCreationTime (path);
623                                 Assertion.AssertEquals ("test#01", 2002, time.Year);
624                                 Assertion.AssertEquals ("test#02", 4, time.Month);
625                                 Assertion.AssertEquals ("test#03", 6, time.Day);
626                                 Assertion.AssertEquals ("test#04", 4, time.Hour);
627                                 Assertion.AssertEquals ("test#05", 4, time.Second);
628                         
629                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
630                                 Assertion.AssertEquals ("test#06", 2002, time.Year);
631                                 Assertion.AssertEquals ("test#07", 4, time.Month);
632                                 Assertion.AssertEquals ("test#08", 6, time.Day);
633                                 Assertion.AssertEquals ("test#09", 4, time.Hour);
634                                 Assertion.AssertEquals ("test#10", 4, time.Second);                     
635
636                                 File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
637                                 time = File.GetCreationTimeUtc (path);
638                                 Assertion.AssertEquals ("test#11", 2002, time.Year);
639                                 Assertion.AssertEquals ("test#12", 4, time.Month);
640                                 Assertion.AssertEquals ("test#13", 6, time.Day);
641                                 Assertion.AssertEquals ("test#14", 4, time.Hour);
642                                 Assertion.AssertEquals ("test#15", 4, time.Second);
643                         
644                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
645                                 Assertion.AssertEquals ("test#16", 2002, time.Year);
646                                 Assertion.AssertEquals ("test#17", 4, time.Month);
647                                 Assertion.AssertEquals ("test#18", 6, time.Day);
648                                 Assertion.AssertEquals ("test#19", 4, time.Hour);
649                                 Assertion.AssertEquals ("test#20", 4, time.Second);
650                         } finally {
651                                 DeleteFile (path);
652                         }
653                 }
654
655                 [Test]
656 #if TARGET_JVM
657         [Category("NotWorking")]
658 #endif
659                 public void LastAccessTime ()
660                 {
661                         string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";                      
662                         if (File.Exists (path))
663                                 File.Delete (path);
664                         FileStream stream = null;
665                         try {
666                                 stream = File.Create (path);
667                                 stream.Close ();                        
668                         
669                                 File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
670                                 DateTime time = File.GetLastAccessTime (path);
671                                 Assertion.AssertEquals ("test#01", 2002, time.Year);
672                                 Assertion.AssertEquals ("test#02", 4, time.Month);
673                                 Assertion.AssertEquals ("test#03", 6, time.Day);
674                                 Assertion.AssertEquals ("test#04", 4, time.Hour);
675                                 Assertion.AssertEquals ("test#05", 4, time.Second);
676                         
677                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
678                                 Assertion.AssertEquals ("test#06", 2002, time.Year);
679                                 Assertion.AssertEquals ("test#07", 4, time.Month);
680                                 Assertion.AssertEquals ("test#08", 6, time.Day);
681                                 Assertion.AssertEquals ("test#09", 4, time.Hour);
682                                 Assertion.AssertEquals ("test#10", 4, time.Second);                     
683         
684                                 File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
685                                 time = File.GetLastAccessTimeUtc (path);
686                                 Assertion.AssertEquals ("test#11", 2002, time.Year);
687                                 Assertion.AssertEquals ("test#12", 4, time.Month);
688                                 Assertion.AssertEquals ("test#13", 6, time.Day);
689                                 Assertion.AssertEquals ("test#14", 4, time.Hour);
690                                 Assertion.AssertEquals ("test#15", 4, time.Second);
691                         
692                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
693                                 Assertion.AssertEquals ("test#16", 2002, time.Year);
694                                 Assertion.AssertEquals ("test#17", 4, time.Month);
695                                 Assertion.AssertEquals ("test#18", 6, time.Day);
696                                 Assertion.AssertEquals ("test#19", 4, time.Hour);
697                                 Assertion.AssertEquals ("test#20", 4, time.Second);
698                         } finally {
699                                 if (stream != null)
700                                         stream.Close ();
701                                 DeleteFile (path);                                      
702                         }
703                 }
704                 
705                 [Test]
706                 public void LastWriteTime ()
707                 {
708                         string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";                       
709                         if (File.Exists (path))
710                                 File.Delete (path);
711                         FileStream stream = null;
712                         try {
713                                 stream = File.Create (path);
714                                 stream.Close ();                        
715                         
716                                 File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
717                                 DateTime time = File.GetLastWriteTime (path);
718                                 Assertion.AssertEquals ("test#01", 2002, time.Year);
719                                 Assertion.AssertEquals ("test#02", 4, time.Month);
720                                 Assertion.AssertEquals ("test#03", 6, time.Day);
721                                 Assertion.AssertEquals ("test#04", 4, time.Hour);
722                                 Assertion.AssertEquals ("test#05", 4, time.Second);
723                                 
724                                 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
725                                 Assertion.AssertEquals ("test#06", 2002, time.Year);
726                                 Assertion.AssertEquals ("test#07", 4, time.Month);
727                                 Assertion.AssertEquals ("test#08", 6, time.Day);
728                                 Assertion.AssertEquals ("test#09", 4, time.Hour);
729                                 Assertion.AssertEquals ("test#10", 4, time.Second);                     
730         
731                                 File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
732                                 time = File.GetLastWriteTimeUtc (path);
733                                 Assertion.AssertEquals ("test#11", 2002, time.Year);
734                                 Assertion.AssertEquals ("test#12", 4, time.Month);
735                                 Assertion.AssertEquals ("test#13", 6, time.Day);
736                                 Assertion.AssertEquals ("test#14", 4, time.Hour);
737                                 Assertion.AssertEquals ("test#15", 4, time.Second);
738                                 
739                                 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
740                                 Assertion.AssertEquals ("test#16", 2002, time.Year);
741                                 Assertion.AssertEquals ("test#17", 4, time.Month);
742                                 Assertion.AssertEquals ("test#18", 6, time.Day);
743                                 Assertion.AssertEquals ("test#19", 4, time.Hour);
744                                 Assertion.AssertEquals ("test#20", 4, time.Second);
745                         } finally {
746                                 if (stream != null)
747                                         stream.Close ();
748                                 DeleteFile (path);
749                         }
750                 }
751
752                 [Test]
753                 [ExpectedException(typeof(ArgumentNullException))]      
754 #if TARGET_JVM
755         [Category("NotWorking")]
756 #endif
757                 public void GetCreationTimeException1 ()
758                 {
759                         File.GetCreationTime (null as string);
760                 }
761
762                 [Test]
763                 [ExpectedException(typeof(ArgumentException))]  
764 #if TARGET_JVM
765         [Category("NotWorking")]
766 #endif
767                 public void GetCreationTimeException2 ()
768                 {
769                         File.GetCreationTime ("");
770                 }
771         
772                 [Test]
773 #if !NET_2_0
774                 [ExpectedException(typeof(IOException))]
775 #endif
776 #if TARGET_JVM
777         [Category("NotWorking")]
778 #endif
779                 public void GetCreationTime_NonExistingPath ()
780                 {
781                         string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
782                         DeleteFile (path);
783                         DateTime time = File.GetCreationTime (path);
784
785 #if NET_2_0
786                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
787                         Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
788                         Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
789                         Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
790                         Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
791                         Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
792                         Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
793 #endif
794                 }
795
796                 [Test]
797                 [ExpectedException(typeof(ArgumentException))]
798 #if TARGET_JVM
799         [Category("NotWorking")]
800 #endif
801                 public void GetCreationTimeException4 ()
802                 {
803                         File.GetCreationTime ("    ");
804                 }
805
806                 [Test]
807                 [ExpectedException(typeof(ArgumentException))]
808 #if TARGET_JVM
809         [Category("NotWorking")]
810 #endif
811                 public void GetCreationTimeException5 ()
812                 {
813                         File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
814                 }
815
816                 [Test]
817                 [ExpectedException(typeof(ArgumentNullException))]
818 #if TARGET_JVM
819         [Category("NotWorking")]
820 #endif
821                 public void GetCreationTimeUtcException1 ()
822                 {
823                         File.GetCreationTimeUtc (null as string);
824                 }
825
826                 [Test]
827                 [ExpectedException(typeof(ArgumentException))]
828 #if TARGET_JVM
829         [Category("NotWorking")]
830 #endif
831                 public void GetCreationTimeUtcException2 ()
832                 {
833                         File.GetCreationTimeUtc ("");
834                 }
835         
836                 [Test]
837 #if !NET_2_0
838                 [ExpectedException (typeof (IOException))]
839 #endif
840 #if TARGET_JVM
841         [Category("NotWorking")]
842 #endif
843                 public void GetCreationTimeUtc_NonExistingPath ()
844                 {
845                         string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
846                         DeleteFile (path);
847                         DateTime time = File.GetCreationTimeUtc (path);
848
849 #if NET_2_0
850                         Assertion.AssertEquals ("#1", 1601, time.Year);
851                         Assertion.AssertEquals ("#2", 1, time.Month);
852                         Assertion.AssertEquals ("#3", 1, time.Day);
853                         Assertion.AssertEquals ("#4", 0, time.Hour);
854                         Assertion.AssertEquals ("#5", 0, time.Second);
855                         Assertion.AssertEquals ("#6", 0, time.Millisecond);
856 #endif
857                 }
858
859                 [Test]
860                 [ExpectedException(typeof(ArgumentException))]
861 #if TARGET_JVM
862         [Category("NotWorking")]
863 #endif
864                 public void GetCreationTimeUtcException4 ()
865                 {
866                         File.GetCreationTimeUtc ("    ");
867                 }
868
869                 [Test]
870                 [ExpectedException(typeof(ArgumentException))]
871 #if TARGET_JVM
872         [Category("NotWorking")]
873 #endif
874                 public void GetCreationTimeUtcException5 ()
875                 {
876                         File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
877                 }
878
879                 [Test]
880                 [ExpectedException(typeof(ArgumentNullException))]
881 #if TARGET_JVM
882         [Category("NotWorking")]
883 #endif
884                 public void GetLastAccessTimeException1 ()
885                 {
886                         File.GetLastAccessTime (null as string);
887                 }
888
889                 [Test]
890                 [ExpectedException(typeof(ArgumentException))]
891 #if TARGET_JVM
892         [Category("NotWorking")]
893 #endif
894                 public void GetLastAccessTimeException2 ()
895                 {
896                         File.GetLastAccessTime ("");
897                 }
898         
899                 [Test]
900 #if !NET_2_0
901                 [ExpectedException (typeof (IOException))]
902 #endif
903 #if TARGET_JVM
904         [Category("NotWorking")]
905 #endif
906                 public void GetLastAccessTime_NonExistingPath ()
907                 {
908                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
909                         DeleteFile (path);
910                         DateTime time = File.GetLastAccessTime (path);
911
912 #if NET_2_0
913                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
914                         Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
915                         Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
916                         Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
917                         Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
918                         Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
919                         Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
920 #endif
921                 }
922
923                 [Test]
924                 [ExpectedException(typeof(ArgumentException))]
925 #if TARGET_JVM
926         [Category("NotWorking")]
927 #endif
928                 public void GetLastAccessTimeException4 ()
929                 {
930                         File.GetLastAccessTime ("    ");
931                 }
932
933                 [Test]
934                 [ExpectedException(typeof(ArgumentException))]
935 #if TARGET_JVM
936         [Category("NotWorking")]
937 #endif
938                 public void GetLastAccessTimeException5 ()
939                 {
940                         File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
941                 }
942
943                 [Test]
944                 [ExpectedException(typeof(ArgumentNullException))]
945 #if TARGET_JVM
946         [Category("NotWorking")]
947 #endif
948                 public void GetLastAccessTimeUtcException1 ()
949                 {
950                         File.GetLastAccessTimeUtc (null as string);
951                 }
952
953                 [Test]
954                 [ExpectedException(typeof(ArgumentException))]
955 #if TARGET_JVM
956         [Category("NotWorking")]
957 #endif
958                 public void GetLastAccessTimeUtcException2 ()
959                 {
960                         File.GetLastAccessTimeUtc ("");
961                 }
962         
963                 [Test]
964 #if !NET_2_0
965                 [ExpectedException (typeof (IOException))]
966 #endif
967 #if TARGET_JVM
968         [Category("NotWorking")]
969 #endif
970                 public void GetLastAccessTimeUtc_NonExistingPath ()
971                 {
972                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
973                         DeleteFile (path);
974                         DateTime time = File.GetLastAccessTimeUtc (path);
975
976 #if NET_2_0
977                         Assertion.AssertEquals ("#1", 1601, time.Year);
978                         Assertion.AssertEquals ("#2", 1, time.Month);
979                         Assertion.AssertEquals ("#3", 1, time.Day);
980                         Assertion.AssertEquals ("#4", 0, time.Hour);
981                         Assertion.AssertEquals ("#5", 0, time.Second);
982                         Assertion.AssertEquals ("#6", 0, time.Millisecond);
983 #endif
984                 }
985
986                 [Test]
987                 [ExpectedException(typeof(ArgumentException))]
988 #if TARGET_JVM
989         [Category("NotWorking")]
990 #endif
991                 public void GetLastAccessTimeUtcException4 ()
992                 {
993                         File.GetLastAccessTimeUtc ("    ");
994                 }
995
996                 [Test]
997                 [ExpectedException(typeof(ArgumentException))]
998 #if TARGET_JVM
999         [Category("NotWorking")]
1000 #endif
1001                 public void GetLastAccessTimeUtcException5 ()
1002                 {
1003                         File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
1004                 }
1005
1006                 [Test]
1007                 [ExpectedException(typeof(ArgumentNullException))]
1008                 public void GetLastWriteTimeException1 ()
1009                 {
1010                         File.GetLastWriteTime (null as string);
1011                 }
1012
1013                 [Test]
1014                 [ExpectedException(typeof(ArgumentException))]
1015                 public void GetLastWriteTimeException2 ()
1016                 {
1017                         File.GetLastWriteTime ("");
1018                 }
1019         
1020                 [Test]
1021 #if !NET_2_0
1022                 [ExpectedException (typeof (IOException))]
1023 #endif
1024                 public void GetLastWriteTime_NonExistingPath ()
1025                 {
1026                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
1027                         DeleteFile (path);
1028                         DateTime time = File.GetLastWriteTime (path);
1029
1030 #if NET_2_0
1031                         DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
1032                         Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
1033                         Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
1034                         Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
1035                         Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
1036                         Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
1037                         Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
1038 #endif
1039                 }
1040
1041                 [Test]
1042                 [ExpectedException(typeof(ArgumentException))]
1043                 public void GetLastWriteTimeException4 ()
1044                 {
1045                         File.GetLastWriteTime ("    ");
1046                 }
1047
1048                 [Test]
1049                 [ExpectedException(typeof(ArgumentException))]
1050                 public void GetLastWriteTimeException5 ()
1051                 {
1052                         File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
1053                 }
1054
1055                 [Test]
1056                 [ExpectedException(typeof(ArgumentNullException))]
1057                 public void GetLastWriteTimeUtcException1 ()
1058                 {
1059                         File.GetLastWriteTimeUtc (null as string);
1060                 }
1061
1062                 [Test]
1063                 [ExpectedException(typeof(ArgumentException))]
1064                 public void GetLastWriteTimeUtcException2 ()
1065                 {
1066                         File.GetLastWriteTimeUtc ("");
1067                 }
1068         
1069                 [Test]
1070 #if !NET_2_0
1071                 [ExpectedException (typeof (IOException))]
1072 #endif
1073                 public void GetLastWriteTimeUtc_NonExistingPath ()
1074                 {
1075                         string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
1076                         DeleteFile (path);
1077                         DateTime time = File.GetLastWriteTimeUtc (path);
1078
1079 #if NET_2_0
1080                         Assertion.AssertEquals ("#1", 1601, time.Year);
1081                         Assertion.AssertEquals ("#2", 1, time.Month);
1082                         Assertion.AssertEquals ("#3", 1, time.Day);
1083                         Assertion.AssertEquals ("#4", 0, time.Hour);
1084                         Assertion.AssertEquals ("#5", 0, time.Second);
1085                         Assertion.AssertEquals ("#6", 0, time.Millisecond);
1086 #endif
1087                 }
1088
1089                 [Test]
1090                 [ExpectedException(typeof(ArgumentException))]
1091                 public void GetLastWriteTimeUtcException4 ()
1092                 {
1093                         File.GetLastWriteTimeUtc ("    ");
1094                 }
1095
1096                 [Test]
1097                 [ExpectedException(typeof(ArgumentException))]
1098                 public void GetLastWriteTimeUtcException5 ()
1099                 {
1100                         File.GetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString ());
1101                 }               
1102
1103                 [Test]
1104                 public void FileStreamClose ()
1105                 {
1106                         string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
1107                         FileStream stream = null;
1108                         try {
1109                                 stream = File.Create (path);
1110                                 stream.Close ();
1111                                 File.Delete (path);
1112                         } finally {
1113                                 if (stream != null)
1114                                         stream.Close ();
1115                                 DeleteFile (path);
1116                         }
1117                 }
1118                 
1119                 // SetCreationTime and SetCreationTimeUtc exceptions
1120
1121                 [Test]
1122                 [ExpectedException(typeof (ArgumentNullException))]
1123 #if TARGET_JVM
1124         [Category("NotWorking")]
1125 #endif
1126                 public void SetCreationTimeArgumentNullException1 ()
1127                 {
1128                         File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1129                 }
1130
1131                 [Test]
1132                 [ExpectedException(typeof (ArgumentException))]
1133 #if TARGET_JVM
1134         [Category("NotWorking")]
1135 #endif
1136                 public void SetCreationTimeArgumenException1 ()
1137                 {
1138                         File.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1139                 }
1140
1141                 [Test]
1142                 [ExpectedException(typeof (ArgumentException))]
1143 #if TARGET_JVM
1144         [Category("NotWorking")]
1145 #endif
1146                 public void SetCreationTimeArgumenException2 ()
1147                 {
1148                         File.SetCreationTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1149                 }
1150
1151                 [Test]
1152                 // On Unix there are no invalid path chars.
1153 #if TARGET_JVM
1154         [Category("NotWorking")]
1155 #endif
1156                 public void SetCreationTimeArgumenException3 ()
1157                 {
1158                         if (Path.InvalidPathChars.Length > 1) {
1159                                 bool pass = false;
1160                                 try {
1161                                         File.SetCreationTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1162                                 } catch (ArgumentException) {
1163                                         pass = true;
1164                                 }
1165
1166                                 Assertion.Assert ("#01", pass);
1167                         }
1168                 }
1169
1170                 [Test]
1171                 [ExpectedException(typeof (FileNotFoundException))]
1172 #if TARGET_JVM
1173         [Category("NotWorking")]
1174 #endif
1175                 public void SetCreationTimeFileNotFoundException1 ()
1176                 {
1177                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
1178                         DeleteFile (path);
1179                         
1180                         File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1181                 }
1182
1183 //              [Test]
1184 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1185 //              public void SetCreationTimeArgumentOutOfRangeException1 ()
1186 //              {
1187 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
1188 //                      FileStream stream = null;
1189 //                      DeleteFile (path);
1190 //                      try {
1191 //                              stream = File.Create (path);
1192 //                              stream.Close ();
1193 //                              File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1194 //                      } finally {
1195 //                              if (stream != null)
1196 //                                      stream.Close ();
1197 //                              DeleteFile (path);
1198 //                      }
1199 //              }
1200
1201                 [Test]
1202                 [ExpectedException(typeof (IOException))]
1203 #if TARGET_JVM
1204         [Category("NotWorking")]
1205 #endif
1206                 public void SetCreationTimeIOException1 ()
1207                 {
1208                         string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
1209                         DeleteFile (path);
1210                         FileStream stream = null;
1211                         try {
1212                                 stream = File.Create (path);
1213                                 File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1214                         } finally {
1215                                 if (stream != null)
1216                                         stream.Close ();
1217                                 DeleteFile (path);
1218                         }
1219                 }
1220
1221                 [Test]
1222                 [ExpectedException(typeof (ArgumentNullException))]
1223 #if TARGET_JVM
1224         [Category("NotWorking")]
1225 #endif
1226                 public void SetCreationTimeUtcArgumentNullException1 ()
1227                 { 
1228                         File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1229                 }
1230
1231                 [Test]
1232                 [ExpectedException(typeof (ArgumentException))]
1233 #if TARGET_JVM
1234         [Category("NotWorking")]
1235 #endif
1236                 public void SetCreationTimeUtcArgumenException1 ()
1237                 {
1238                         File.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1239                 }
1240
1241                 [Test]
1242                 [ExpectedException(typeof (ArgumentException))]
1243 #if TARGET_JVM
1244         [Category("NotWorking")]
1245 #endif
1246                 public void SetCreationTimeUtcArgumenException2 ()
1247                 {
1248                         File.SetCreationTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1249                 }
1250
1251                 [Test]
1252                 // On Unix there are no invalid path chars.
1253 #if TARGET_JVM
1254         [Category("NotWorking")]
1255 #endif
1256                 public void SetCreationTimeUtcArgumentException3 ()
1257                 {
1258                         if (Path.InvalidPathChars.Length > 1) {
1259                                 bool pass = false;
1260                                 try {
1261                                         File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1262                                 } catch (ArgumentException) {
1263                                         pass = true;
1264                                 }
1265
1266                                 Assertion.Assert ("#01", pass);
1267                         }
1268                 }
1269
1270                 [Test]
1271                 [ExpectedException(typeof (FileNotFoundException))]
1272 #if TARGET_JVM
1273         [Category("NotWorking")]
1274 #endif
1275                 public void SetCreationTimeUtcFileNotFoundException1 ()
1276                 {
1277                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
1278                         DeleteFile (path);
1279                         
1280                         File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1281                 }
1282
1283 //              [Test]
1284 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1285 //              public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
1286 //              {
1287 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
1288 //                      DeleteFile (path);
1289 //                      FileStream stream = null;
1290 //                      try {                           
1291 //                              stream = File.Create (path);
1292 //                              stream.Close ();
1293 //                              File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1294 //                      } finally {
1295 //                              if (stream != null)
1296 //                                      stream.Close();
1297 //                              DeleteFile (path);
1298 //                      }
1299 //              }
1300
1301                 [Test]
1302                 [ExpectedException(typeof (IOException))]
1303 #if TARGET_JVM
1304         [Category("NotWorking")]
1305 #endif
1306                 public void SetCreationTimeUtcIOException1 ()
1307                 {
1308                         string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
1309                         DeleteFile (path);
1310                         FileStream stream = null;
1311                         try {
1312                                 stream = File.Create (path);
1313                                 File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1314                         } finally {
1315                                 if (stream != null)
1316                                         stream.Close ();
1317                                 DeleteFile (path);
1318                         }
1319                 }
1320
1321                 // SetLastAccessTime and SetLastAccessTimeUtc exceptions
1322
1323                 [Test]
1324                 [ExpectedException(typeof (ArgumentNullException))]
1325 #if TARGET_JVM
1326         [Category("NotWorking")]
1327 #endif
1328                 public void SetLastAccessTimeArgumentNullException1 ()
1329                 {
1330                         File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1331                 }
1332
1333                 [Test]
1334                 [ExpectedException(typeof (ArgumentException))]
1335 #if TARGET_JVM
1336         [Category("NotWorking")]
1337 #endif
1338                 public void SetLastAccessTimeArgumenException1 ()
1339                 {
1340                         File.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1341                 }
1342
1343                 [Test]
1344                 [ExpectedException(typeof (ArgumentException))]
1345 #if TARGET_JVM
1346         [Category("NotWorking")]
1347 #endif
1348                 public void SetLastAccessTimeArgumenException2 ()
1349                 {
1350                         File.SetLastAccessTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1351                 }
1352
1353                 [Test]
1354                 // On Unix there are no invalid path chars.
1355 #if TARGET_JVM
1356         [Category("NotWorking")]
1357 #endif
1358                 public void SetLastAccessTimeArgumenException3 ()
1359                 {
1360                         if (Path.InvalidPathChars.Length > 1) {
1361                                 bool pass = false;
1362                                 try {
1363                                         File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1364                                 } catch (ArgumentException) {
1365                                         pass = true;
1366                                 }
1367
1368                                 Assertion.Assert ("#01", pass);
1369                         }
1370                 }
1371
1372                 [Test]
1373                 [ExpectedException(typeof (FileNotFoundException))]
1374 #if TARGET_JVM
1375         [Category("NotWorking")]
1376 #endif
1377                 public void SetLastAccessTimeFileNotFoundException1 ()
1378                 {
1379                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
1380                         DeleteFile (path);
1381                         
1382                         File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1383                 }
1384
1385 //              [Test]
1386 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1387 //              public void SetLastAccessTimeArgumentOutOfRangeException1 ()
1388 //              {
1389 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
1390 //                      DeleteFile (path);
1391 //                      FileStream stream = null;
1392 //                      try {
1393 //                              stream = File.Create (path);
1394 //                              stream.Close ();
1395 //                              File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1396 //                      } finally {
1397 //                              if (stream != null)
1398 //                                      stream.Close ();
1399 //                              DeleteFile (path);
1400 //                      }
1401 //              }
1402
1403                 [Test]
1404                 [ExpectedException(typeof (IOException))]
1405 #if TARGET_JVM
1406         [Category("NotWorking")]
1407 #endif
1408                 public void SetLastAccessTimeIOException1 ()
1409                 {
1410                         string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
1411                         DeleteFile (path);
1412                         FileStream stream = null;
1413                         try {
1414                                 stream = File.Create (path);
1415                                 File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1416                         } finally {
1417                                 if (stream != null)
1418                                         stream.Close ();
1419                                 DeleteFile (path);
1420                         }
1421                 }
1422
1423                 [Test]
1424                 [ExpectedException(typeof (ArgumentNullException))]
1425 #if TARGET_JVM
1426         [Category("NotWorking")]
1427 #endif
1428                 public void SetLastAccessTimeUtcArgumentNullException1 ()
1429                 {
1430                         File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1431                 }
1432
1433                 [Test]
1434                 [ExpectedException(typeof (ArgumentException))]
1435 #if TARGET_JVM
1436         [Category("NotWorking")]
1437 #endif
1438                 public void SetCLastAccessTimeUtcArgumenException1 ()
1439                 {
1440                         File.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1441                 }
1442
1443                 [Test]
1444                 [ExpectedException(typeof (ArgumentException))]
1445 #if TARGET_JVM
1446         [Category("NotWorking")]
1447 #endif
1448                 public void SetLastAccessTimeUtcArgumenException2 ()
1449                 {
1450                         File.SetLastAccessTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1451                 }
1452
1453                 [Test]
1454                 // On Unix there are no invalid path chars.
1455 #if TARGET_JVM
1456         [Category("NotWorking")]
1457 #endif
1458                 public void SetLastAccessTimeUtcArgumenException3 ()
1459                 {
1460                         if (Path.InvalidPathChars.Length > 1) {
1461                                 bool pass = false;
1462                                 try {
1463                                         File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1464                                 } catch (ArgumentException) {
1465                                         pass = true;
1466                                 }
1467
1468                                 Assertion.Assert ("#01", pass);
1469                         }
1470                 }
1471
1472                 [Test]
1473                 [ExpectedException(typeof (FileNotFoundException))]
1474 #if TARGET_JVM
1475         [Category("NotWorking")]
1476 #endif
1477                 public void SetLastAccessTimeUtcFileNotFoundException1 ()
1478                 {
1479                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
1480                         DeleteFile (path);
1481                         
1482                         File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1483                 }
1484
1485 //              [Test]
1486 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1487 //              public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
1488 //              {
1489 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
1490 //                      DeleteFile (path);
1491 //                      FileStream stream = null;
1492 //                      try {
1493 //                              stream = File.Create (path);
1494 //                              stream.Close ();
1495 //                              File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1496 //                      } finally {
1497 //                              if (stream != null)
1498 //                                      stream.Close ();
1499 //                              DeleteFile (path);
1500 //                      }
1501 //              }
1502
1503                 [Test]
1504                 [ExpectedException(typeof (IOException))]
1505 #if TARGET_JVM
1506         [Category("NotWorking")]
1507 #endif
1508                 public void SetLastAccessTimeUtcIOException1 ()
1509                 {
1510                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
1511                         DeleteFile (path);
1512                         FileStream stream = null;
1513                         try {
1514                                 stream = File.Create (path);
1515                                 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1516                         } finally {
1517                                 if (stream != null)
1518                                         stream.Close ();
1519                                 DeleteFile (path);
1520                         }
1521                 }
1522
1523                 // SetLastWriteTime and SetLastWriteTimeUtc exceptions
1524
1525                 [Test]
1526                 [ExpectedException(typeof (ArgumentNullException))]
1527                 public void SetLastWriteTimeArgumentNullException1 ()
1528                 {
1529                         File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1530                 }
1531
1532                 [Test]
1533                 [ExpectedException(typeof (ArgumentException))]
1534                 public void SetLastWriteTimeArgumenException1 ()
1535                 {
1536                         File.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1537                 }
1538
1539                 [Test]
1540                 [ExpectedException(typeof (ArgumentException))]
1541                 public void SetLastWriteTimeArgumenException2 ()
1542                 {
1543                         File.SetLastWriteTime ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1544                 }
1545
1546                 [Test]
1547                 // On Unix there are no invalid path chars.
1548                 public void SetLastWriteTimeArgumenException3 ()
1549                 {
1550                         if (Path.InvalidPathChars.Length > 1) {
1551                                 bool pass = false;
1552                                 try {
1553                                         File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1554                                 } catch (ArgumentException) {
1555                                         pass = true;
1556                                 }
1557
1558                                 Assertion.Assert ("#01", pass);
1559                         }
1560                 }
1561
1562                 [Test]
1563                 [ExpectedException(typeof (FileNotFoundException))]
1564                 public void SetLastWriteTimeFileNotFoundException1 ()
1565                 {
1566                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
1567                         DeleteFile (path);
1568                         
1569                         File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1570                 }
1571
1572 //              [Test]
1573 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1574 //              public void SetLastWriteTimeArgumentOutOfRangeException1 ()
1575 //              {
1576 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
1577 //                      DeleteFile (path);
1578 //                      FileStream stream = null;
1579 //                      try {
1580 //                              stream = File.Create (path);
1581 //                              stream.Close ();
1582 //                              File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1583 //                      } finally {
1584 //                              if (stream != null)
1585 //                                      stream.Close ();
1586 //                              DeleteFile (path);
1587 //                      }
1588 //              }
1589
1590                 [Test]
1591                 [ExpectedException(typeof (IOException))]
1592 #if TARGET_JVM
1593         [Category("NotWorking")]
1594 #endif
1595                 public void SetLastWriteTimeIOException1 ()
1596                 {
1597                         string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
1598                         DeleteFile (path);
1599                         FileStream stream = null;
1600                         try {
1601                                 stream = File.Create (path);
1602                                 File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1603                         } finally {
1604                                 if (stream != null)
1605                                         stream.Close ();
1606                                 DeleteFile (path);
1607                         }
1608                 }
1609
1610                 [Test]
1611                 [ExpectedException(typeof (ArgumentNullException))]
1612                 public void SetLastWriteTimeUtcArgumentNullException1 ()
1613                 {
1614                         File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1615                 }
1616
1617                 [Test]
1618                 [ExpectedException(typeof (ArgumentException))]
1619                 public void SetCLastWriteTimeUtcArgumenException1 ()
1620                 {
1621                         File.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1622                 }
1623
1624                 [Test]
1625                 [ExpectedException(typeof (ArgumentException))]
1626                 public void SetLastWriteTimeUtcArgumenException2 ()
1627                 {
1628                         File.SetLastWriteTimeUtc ("     ", new DateTime (2000, 12, 12, 11, 59, 59));
1629                 }
1630
1631                 [Test]
1632                 // On Unix there are no invalid path chars.
1633                 public void SetLastWriteTimeUtcArgumenException3 ()
1634                 {
1635                         if (Path.InvalidPathChars.Length > 1) {
1636                                 bool pass = false;
1637                                 try {
1638                                         File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1639                                 } catch (ArgumentException) {
1640                                         pass = true;
1641                                 }
1642
1643                                 Assertion.Assert ("#01", pass);
1644                         }
1645                 }
1646
1647                 [Test]
1648                 [ExpectedException(typeof (FileNotFoundException))]
1649                 public void SetLastWriteTimeUtcFileNotFoundException1 ()
1650                 {
1651                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
1652                         DeleteFile (path);
1653                         
1654                         File.SetLastWriteTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1655                 }
1656
1657 //              [Test]
1658 //              [ExpectedException(typeof (ArgumentOutOfRangeException))]
1659 //              public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
1660 //              {
1661 //                      string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
1662 //                      DeleteFile (path);
1663 //                      FileStream stream = null;
1664 //                      try {
1665 //                              stream = File.Create (path);
1666 //                              stream.Close ();
1667 //                              File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1668 //                      } finally {
1669 //                              if (stream != null)
1670 //                                      stream.Close ();
1671 //                              DeleteFile (path);
1672 //                      }
1673 //              }
1674 //
1675                 [Test]
1676                 [ExpectedException(typeof (IOException))]
1677 #if TARGET_JVM
1678         [Category("NotWorking")]
1679 #endif
1680                 public void SetLastWriteTimeUtcIOException1 ()
1681                 {
1682                         string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
1683                         DeleteFile (path);
1684                         FileStream stream = null;
1685                         try {
1686                                 stream = File.Create (path);
1687                                 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1688                         } finally {
1689                                 if (stream != null)
1690                                         stream.Close ();
1691                                 DeleteFile (path);
1692                         }
1693                 }
1694                 
1695                 [Test]
1696                 public void OpenAppend ()
1697                 {
1698                         string fn = Path.GetTempFileName ();
1699                         using (FileStream s = File.Open (fn, FileMode.Append))
1700                                 ;
1701                         
1702                         DeleteFile (fn);
1703                 }
1704
1705 #if NET_2_0
1706                 void TestRWAT (string s)
1707                 {
1708                         string f = Path.GetTempFileName ();
1709                         try {
1710                                 File.WriteAllText (f, s);
1711                                 string r = File.ReadAllText (f);
1712                                 AssertEquals (r, s);
1713                         } finally {
1714                                 DeleteFile (f);
1715                         }
1716                 }
1717                 [Test]
1718                 public void ReadWriteAllText ()
1719                 {
1720                         // The MSDN docs said something about
1721                         // not including a final new line. it looks
1722                         // like that was not true. I'm not sure what
1723                         // that was talking about
1724                         TestRWAT ("");
1725                         TestRWAT ("\r");
1726                         TestRWAT ("\n");
1727                         TestRWAT ("\r\n");
1728                         TestRWAT ("a\r");
1729                         TestRWAT ("a\n");
1730                         TestRWAT ("a\r\n");     
1731                         TestRWAT ("a\ra");
1732                         TestRWAT ("a\na");
1733                         TestRWAT ("a\r\na");
1734                         TestRWAT ("a");
1735                         TestRWAT ("\r\r");
1736                         TestRWAT ("\n\n");
1737                         TestRWAT ("\r\n\r\n");
1738                 }
1739 #endif
1740
1741                 private void DeleteFile (string path)
1742                 {
1743                         if (File.Exists (path))
1744                                 File.Delete (path);
1745                 }
1746         }
1747 }