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