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