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