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