2 // FileTest.cs: Test cases for System.IO.File
5 // Duncan Mak (duncan@ximian.com)
6 // Ville Palo (vi64pa@kolumbus.fi)
8 // (C) 2002 Ximian, Inc. http://www.ximian.com
10 // TODO: Find out why ArgumentOutOfRangeExceptions does not manage to close streams properly
12 using NUnit
.Framework
;
15 using System
.Globalization
;
16 using System
.Threading
;
18 namespace MonoTests
.System
.IO
21 public class FileTest
: Assertion
23 static string TempFolder
= Path
.Combine (Path
.GetTempPath (), "MonoTests.System.IO.Tests");
28 if (Directory
.Exists (TempFolder
))
29 Directory
.Delete (TempFolder
, true);
30 Directory
.CreateDirectory (TempFolder
);
32 Thread
.CurrentThread
.CurrentCulture
= new CultureInfo ("EN-us");
36 public void TearDown ()
38 if (Directory
.Exists (TempFolder
))
39 Directory
.Delete (TempFolder
, true);
43 public void TestExists ()
47 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
49 Assert ("null filename should not exist", !File
.Exists (null));
51 Assert ("empty filename should not exist", !File
.Exists (""));
53 Assert ("whitespace filename should not exist", !File
.Exists (" \t\t \t \n\t\n \n"));
56 s
= File
.Create (path
);
58 Assert ("File " + path
+ " should exists", File
.Exists (path
));
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
);
71 public void Exists_InvalidFileName ()
73 Assert ("><|", !File
.Exists ("><|"));
77 public void Exists_InvalidDirectory ()
79 Assert ("InvalidDirectory", !File
.Exists (Path
.Combine ("does not exist", "file.txt")));
83 [ExpectedException(typeof (ArgumentNullException
))]
84 public void CtorArgumentNullException1 ()
86 FileStream stream
= File
.Create (null);
90 [ExpectedException(typeof (ArgumentException
))]
91 public void CtorArgumentException1 ()
93 FileStream stream
= File
.Create ("");
97 [ExpectedException(typeof (ArgumentException
))]
98 public void CtorArgumentException2 ()
100 FileStream stream
= File
.Create (" ");
104 [ExpectedException(typeof (DirectoryNotFoundException
))]
105 public void CtorDirectoryNotFoundException ()
107 FileStream stream
= null;
108 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "directory_does_not_exist" + Path
.DirectorySeparatorChar
+ "foo";
111 stream
= File
.Create (path
);
120 public void TestCreate ()
122 FileStream stream
= null;
124 /* positive test: create resources/foo */
126 path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "foo";
127 stream
= File
.Create (path
);
128 Assert ("File should exist", File
.Exists (path
));
130 } catch (Exception e
) {
131 Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e
.ToString());
141 /* positive test: repeat test above again to test for overwriting file */
143 path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "foo";
144 stream
= File
.Create (path
);
145 Assert ("File should exist", File
.Exists (path
));
147 } catch (Exception e
) {
148 Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e
.ToString());
157 [ExpectedException(typeof(ArgumentNullException
))]
158 public void CopyArgumentNullException1 ()
160 File
.Copy (null, "b");
164 [ExpectedException(typeof(ArgumentNullException
))]
165 public void CopyArgumentNullException2 ()
167 File
.Copy ("a", null);
171 [ExpectedException(typeof(ArgumentException
))]
172 public void CopyArgumentException1 ()
178 [ExpectedException(typeof(ArgumentException
))]
179 public void CopyArgumentException2 ()
185 [ExpectedException(typeof(ArgumentException
))]
186 public void CopyArgumentException3 ()
188 File
.Copy (" ", "b");
192 [ExpectedException(typeof(ArgumentException
))]
193 public void CopyArgumentException4 ()
195 File
.Copy ("a", " ");
199 [ExpectedException(typeof(FileNotFoundException
))]
200 public void CopyFileNotFoundException ()
202 File
.Copy ("doesnotexist", "b");
205 [ExpectedException(typeof(IOException
))]
206 public void CopyIOException ()
208 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "bar");
209 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt");
211 File
.Create (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt").Close ();
212 File
.Copy (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt", TempFolder
+ Path
.DirectorySeparatorChar
+ "bar");
213 File
.Copy (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt", TempFolder
+ Path
.DirectorySeparatorChar
+ "bar");
215 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "bar");
216 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt");
221 public void TestCopy ()
223 string path1
= TempFolder
+ Path
.DirectorySeparatorChar
+ "bar";
224 string path2
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
225 /* positive test: copy resources/AFile.txt to resources/bar */
231 File
.Create (path2
).Close ();
232 File
.Copy (path2
, path1
);
233 Assert ("File AFile.txt should still exist", File
.Exists (path2
));
234 Assert ("File bar should exist after File.Copy", File
.Exists (path1
));
235 } catch (Exception e
) {
236 Fail ("#1 File.Copy('resources/AFile.txt', 'resources/bar') unexpected exception caught: e=" + e
.ToString());
239 /* positive test: copy resources/AFile.txt to resources/bar, overwrite */
241 Assert ("File bar should exist before File.Copy", File
.Exists (path1
));
242 File
.Copy (path2
, path1
, true);
243 Assert ("File AFile.txt should still exist", File
.Exists (path2
));
244 Assert ("File bar should exist after File.Copy", File
.Exists (path1
));
245 } catch (Exception e
) {
246 Fail ("File.Copy('resources/AFile.txt', 'resources/bar', true) unexpected exception caught: e=" + e
.ToString());
255 [ExpectedException (typeof (ArgumentNullException
))]
256 public void DeleteArgumentNullException ()
262 [ExpectedException (typeof (ArgumentException
))]
263 public void DeleteArgumentException1 ()
269 [ExpectedException (typeof (ArgumentException
))]
270 public void DeleteArgumentException2 ()
276 [ExpectedException (typeof (DirectoryNotFoundException
))]
277 public void DeleteDirectoryNotFoundException ()
279 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "directory_does_not_exist" + Path
.DirectorySeparatorChar
+ "foo";
280 if (Directory
.Exists (path
))
281 Directory
.Delete (path
, true);
287 public void TestDelete ()
289 string foopath
= TempFolder
+ Path
.DirectorySeparatorChar
+ "foo";
290 DeleteFile (foopath
);
292 File
.Create (foopath
).Close ();
295 File
.Delete (foopath
);
296 } catch (Exception e
) {
297 Fail ("Unable to delete " + foopath
+ " e=" + e
.ToString());
299 Assert ("File " + foopath
+ " should not exist after File.Delete", !File
.Exists (foopath
));
301 DeleteFile (foopath
);
306 [ExpectedException(typeof (IOException
))]
307 public void DeleteOpenStreamException ()
309 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "DeleteOpenStreamException";
311 FileStream stream
= null;
313 stream
= new FileStream (path
, FileMode
.OpenOrCreate
, FileAccess
.ReadWrite
);
323 [ExpectedException(typeof (ArgumentNullException
))]
324 public void MoveException1 ()
326 File
.Move (null, "b");
330 [ExpectedException(typeof (ArgumentNullException
))]
331 public void MoveException2 ()
333 File
.Move ("a", null);
337 [ExpectedException(typeof (ArgumentException
))]
338 public void MoveException3 ()
344 [ExpectedException(typeof (ArgumentException
))]
345 public void MoveException4 ()
351 [ExpectedException(typeof (ArgumentException
))]
352 public void MoveException5 ()
354 File
.Move (" ", "b");
358 [ExpectedException(typeof (ArgumentException
))]
359 public void MoveException6 ()
361 File
.Move ("a", " ");
365 [ExpectedException(typeof (FileNotFoundException
))]
366 public void MoveException7 ()
368 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "doesnotexist");
369 File
.Move (TempFolder
+ Path
.DirectorySeparatorChar
+ "doesnotexist", "b");
373 [ExpectedException(typeof (DirectoryNotFoundException
))]
374 public void MoveException8 ()
376 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "foo";
379 File
.Create (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt").Close ();
380 File
.Copy(TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt", path
, true);
381 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "doesnotexist" + Path
.DirectorySeparatorChar
+ "b");
382 File
.Move (TempFolder
+ Path
.DirectorySeparatorChar
+ "foo", TempFolder
+ Path
.DirectorySeparatorChar
+ "doesnotexist" + Path
.DirectorySeparatorChar
+ "b");
384 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt");
390 [ExpectedException(typeof (IOException
))]
391 public void MoveException9 ()
393 File
.Create (TempFolder
+ Path
.DirectorySeparatorChar
+ "foo").Close ();
395 File
.Move (TempFolder
+ Path
.DirectorySeparatorChar
+ "foo", TempFolder
);
397 DeleteFile (TempFolder
+ Path
.DirectorySeparatorChar
+ "foo");
402 public void TestMove ()
404 string bar
= TempFolder
+ Path
.DirectorySeparatorChar
+ "bar";
405 string baz
= TempFolder
+ Path
.DirectorySeparatorChar
+ "baz";
406 if (!File
.Exists (bar
)) {
407 FileStream f
= File
.Create(bar
);
411 Assert ("File " + TempFolder
+ Path
.DirectorySeparatorChar
+ "bar should exist", File
.Exists (bar
));
412 File
.Move (bar
, baz
);
413 Assert ("File " + TempFolder
+ Path
.DirectorySeparatorChar
+ "bar should not exist", !File
.Exists (bar
));
414 Assert ("File " + TempFolder
+ Path
.DirectorySeparatorChar
+ "baz should exist", File
.Exists (baz
));
416 // Test moving of directories
417 string dir
= Path
.Combine (TempFolder
, "dir");
418 string dir2
= Path
.Combine (TempFolder
, "dir2");
419 string dir_foo
= Path
.Combine (dir
, "foo");
420 string dir2_foo
= Path
.Combine (dir2
, "foo");
422 if (Directory
.Exists (dir
))
423 Directory
.Delete (dir
, true);
425 Directory
.CreateDirectory (dir
);
426 Directory
.CreateDirectory (dir2
);
427 File
.Create (dir_foo
).Close ();
428 File
.Move (dir_foo
, dir2_foo
);
429 Assert (File
.Exists (dir2_foo
));
431 Directory
.Delete (dir
, true);
432 Directory
.Delete (dir2
, true);
433 DeleteFile (dir_foo
);
434 DeleteFile (dir2_foo
);
438 public void TestOpen ()
441 FileStream stream
= null;
443 path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
444 if (!File
.Exists (path
))
445 stream
= File
.Create (path
);
447 stream
= File
.Open (path
, FileMode
.Open
);
449 } catch (Exception e
) {
450 Fail ("Unable to open " + TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt: e=" + e
.ToString());
459 /* Exception tests */
461 path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "filedoesnotexist";
462 stream
= File
.Open (path
, FileMode
.Open
);
463 Fail ("File 'filedoesnotexist' should not exist");
464 } catch (FileNotFoundException
) {
465 // do nothing, this is what we expect
466 } catch (Exception e
) {
467 Fail ("Unexpect exception caught: e=" + e
.ToString());
478 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
479 if (!File
.Exists (path
))
480 File
.Create (path
).Close ();
481 FileStream stream
= null;
484 stream
= File
.Open (path
, FileMode
.Open
);
486 Assertion
.AssertEquals ("test#01", true, stream
.CanRead
);
487 Assertion
.AssertEquals ("test#02", true, stream
.CanSeek
);
488 Assertion
.AssertEquals ("test#03", true, stream
.CanWrite
);
491 stream
= File
.Open (path
, FileMode
.Open
, FileAccess
.Write
);
492 Assertion
.AssertEquals ("test#04", false, stream
.CanRead
);
493 Assertion
.AssertEquals ("test#05", true, stream
.CanSeek
);
494 Assertion
.AssertEquals ("test#06", true, stream
.CanWrite
);
497 stream
= File
.Open (path
, FileMode
.Open
, FileAccess
.Read
);
498 Assertion
.AssertEquals ("test#04", true, stream
.CanRead
);
499 Assertion
.AssertEquals ("test#05", true, stream
.CanSeek
);
500 Assertion
.AssertEquals ("test#06", false, stream
.CanWrite
);
511 [ExpectedException(typeof(ArgumentException
))]
512 public void OpenException1 ()
514 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
515 FileStream stream
= null;
516 // CreateNew + Read throws an exceptoin
518 stream
= File
.Open (TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt", FileMode
.CreateNew
, FileAccess
.Read
);
527 [ExpectedException(typeof(ArgumentException
))]
528 public void OpenException2 ()
530 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
532 // Append + Read throws an exceptoin
533 if (!File
.Exists (path
))
534 File
.Create (path
).Close ();
536 s
= File
.Open (path
, FileMode
.Append
, FileAccess
.Read
);
545 public void OpenRead ()
547 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
548 if (!File
.Exists (path
))
549 File
.Create (path
).Close ();
550 FileStream stream
= null;
553 stream
= File
.OpenRead (path
);
555 Assertion
.AssertEquals ("test#01", true, stream
.CanRead
);
556 Assertion
.AssertEquals ("test#02", true, stream
.CanSeek
);
557 Assertion
.AssertEquals ("test#03", false, stream
.CanWrite
);
567 public void OpenWrite ()
569 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "AFile.txt";
570 if (!File
.Exists (path
))
571 File
.Create (path
).Close ();
572 FileStream stream
= null;
575 stream
= File
.OpenWrite (path
);
576 Assertion
.AssertEquals ("test#01", false, stream
.CanRead
);
577 Assertion
.AssertEquals ("test#02", true, stream
.CanSeek
);
578 Assertion
.AssertEquals ("test#03", true, stream
.CanWrite
);
588 public void TestGetCreationTime ()
590 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "baz";
594 File
.Create (path
).Close();
595 DateTime time
= File
.GetCreationTime (path
);
596 Assert ("GetCreationTime incorrect", (DateTime
.Now
- time
).TotalSeconds
< 10);
603 [ExpectedException(typeof(IOException
))]
604 public void TestGetCreationTimeException ()
606 // Test nonexistent files
607 string path2
= TempFolder
+ Path
.DirectorySeparatorChar
+ "filedoesnotexist";
609 // should throw an exception
610 File
.GetCreationTime (path2
);
616 public void CreationTime ()
618 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "creationTime";
619 if (File
.Exists (path
))
621 FileStream stream
= null;
624 stream
= File
.Create (path
);
627 File
.SetCreationTime (path
, new DateTime (2002, 4, 6, 4, 6, 4));
628 DateTime time
= File
.GetCreationTime (path
);
629 Assertion
.AssertEquals ("test#01", 2002, time
.Year
);
630 Assertion
.AssertEquals ("test#02", 4, time
.Month
);
631 Assertion
.AssertEquals ("test#03", 6, time
.Day
);
632 Assertion
.AssertEquals ("test#04", 4, time
.Hour
);
633 Assertion
.AssertEquals ("test#05", 4, time
.Second
);
635 time
= TimeZone
.CurrentTimeZone
.ToLocalTime (File
.GetCreationTimeUtc (path
));
636 Assertion
.AssertEquals ("test#06", 2002, time
.Year
);
637 Assertion
.AssertEquals ("test#07", 4, time
.Month
);
638 Assertion
.AssertEquals ("test#08", 6, time
.Day
);
639 Assertion
.AssertEquals ("test#09", 4, time
.Hour
);
640 Assertion
.AssertEquals ("test#10", 4, time
.Second
);
642 File
.SetCreationTimeUtc (path
, new DateTime (2002, 4, 6, 4, 6, 4));
643 time
= File
.GetCreationTimeUtc (path
);
644 Assertion
.AssertEquals ("test#11", 2002, time
.Year
);
645 Assertion
.AssertEquals ("test#12", 4, time
.Month
);
646 Assertion
.AssertEquals ("test#13", 6, time
.Day
);
647 Assertion
.AssertEquals ("test#14", 4, time
.Hour
);
648 Assertion
.AssertEquals ("test#15", 4, time
.Second
);
650 time
= TimeZone
.CurrentTimeZone
.ToUniversalTime (File
.GetCreationTime (path
));
651 Assertion
.AssertEquals ("test#16", 2002, time
.Year
);
652 Assertion
.AssertEquals ("test#17", 4, time
.Month
);
653 Assertion
.AssertEquals ("test#18", 6, time
.Day
);
654 Assertion
.AssertEquals ("test#19", 4, time
.Hour
);
655 Assertion
.AssertEquals ("test#20", 4, time
.Second
);
664 public void LastAccessTime ()
666 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "lastAccessTime";
667 if (File
.Exists (path
))
669 FileStream stream
= null;
671 stream
= File
.Create (path
);
674 File
.SetLastAccessTime (path
, new DateTime (2002, 4, 6, 4, 6, 4));
675 DateTime time
= File
.GetLastAccessTime (path
);
676 Assertion
.AssertEquals ("test#01", 2002, time
.Year
);
677 Assertion
.AssertEquals ("test#02", 4, time
.Month
);
678 Assertion
.AssertEquals ("test#03", 6, time
.Day
);
679 Assertion
.AssertEquals ("test#04", 4, time
.Hour
);
680 Assertion
.AssertEquals ("test#05", 4, time
.Second
);
682 time
= TimeZone
.CurrentTimeZone
.ToLocalTime (File
.GetLastAccessTimeUtc (path
));
683 Assertion
.AssertEquals ("test#06", 2002, time
.Year
);
684 Assertion
.AssertEquals ("test#07", 4, time
.Month
);
685 Assertion
.AssertEquals ("test#08", 6, time
.Day
);
686 Assertion
.AssertEquals ("test#09", 4, time
.Hour
);
687 Assertion
.AssertEquals ("test#10", 4, time
.Second
);
689 File
.SetLastAccessTimeUtc (path
, new DateTime (2002, 4, 6, 4, 6, 4));
690 time
= File
.GetLastAccessTimeUtc (path
);
691 Assertion
.AssertEquals ("test#11", 2002, time
.Year
);
692 Assertion
.AssertEquals ("test#12", 4, time
.Month
);
693 Assertion
.AssertEquals ("test#13", 6, time
.Day
);
694 Assertion
.AssertEquals ("test#14", 4, time
.Hour
);
695 Assertion
.AssertEquals ("test#15", 4, time
.Second
);
697 time
= TimeZone
.CurrentTimeZone
.ToUniversalTime (File
.GetLastAccessTime (path
));
698 Assertion
.AssertEquals ("test#16", 2002, time
.Year
);
699 Assertion
.AssertEquals ("test#17", 4, time
.Month
);
700 Assertion
.AssertEquals ("test#18", 6, time
.Day
);
701 Assertion
.AssertEquals ("test#19", 4, time
.Hour
);
702 Assertion
.AssertEquals ("test#20", 4, time
.Second
);
711 public void LastWriteTime ()
713 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "lastWriteTime";
714 if (File
.Exists (path
))
716 FileStream stream
= null;
718 stream
= File
.Create (path
);
721 File
.SetLastWriteTime (path
, new DateTime (2002, 4, 6, 4, 6, 4));
722 DateTime time
= File
.GetLastWriteTime (path
);
723 Assertion
.AssertEquals ("test#01", 2002, time
.Year
);
724 Assertion
.AssertEquals ("test#02", 4, time
.Month
);
725 Assertion
.AssertEquals ("test#03", 6, time
.Day
);
726 Assertion
.AssertEquals ("test#04", 4, time
.Hour
);
727 Assertion
.AssertEquals ("test#05", 4, time
.Second
);
729 time
= TimeZone
.CurrentTimeZone
.ToLocalTime (File
.GetLastWriteTimeUtc (path
));
730 Assertion
.AssertEquals ("test#06", 2002, time
.Year
);
731 Assertion
.AssertEquals ("test#07", 4, time
.Month
);
732 Assertion
.AssertEquals ("test#08", 6, time
.Day
);
733 Assertion
.AssertEquals ("test#09", 4, time
.Hour
);
734 Assertion
.AssertEquals ("test#10", 4, time
.Second
);
736 File
.SetLastWriteTimeUtc (path
, new DateTime (2002, 4, 6, 4, 6, 4));
737 time
= File
.GetLastWriteTimeUtc (path
);
738 Assertion
.AssertEquals ("test#11", 2002, time
.Year
);
739 Assertion
.AssertEquals ("test#12", 4, time
.Month
);
740 Assertion
.AssertEquals ("test#13", 6, time
.Day
);
741 Assertion
.AssertEquals ("test#14", 4, time
.Hour
);
742 Assertion
.AssertEquals ("test#15", 4, time
.Second
);
744 time
= TimeZone
.CurrentTimeZone
.ToUniversalTime (File
.GetLastWriteTime (path
));
745 Assertion
.AssertEquals ("test#16", 2002, time
.Year
);
746 Assertion
.AssertEquals ("test#17", 4, time
.Month
);
747 Assertion
.AssertEquals ("test#18", 6, time
.Day
);
748 Assertion
.AssertEquals ("test#19", 4, time
.Hour
);
749 Assertion
.AssertEquals ("test#20", 4, time
.Second
);
758 [ExpectedException(typeof(ArgumentNullException
))]
759 public void GetCreationTimeException1 ()
761 File
.GetCreationTime (null as string);
765 [ExpectedException(typeof(ArgumentException
))]
766 public void GetCreationTimeException2 ()
768 File
.GetCreationTime ("");
772 [ExpectedException(typeof(IOException
))]
773 public void GetCreationTimeException3 ()
775 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "GetCreationTimeException3";
777 File
.GetCreationTime (path
);
781 [ExpectedException(typeof(ArgumentException
))]
782 public void GetCreationTimeException4 ()
784 File
.GetCreationTime (" ");
788 [ExpectedException(typeof(ArgumentException
))]
789 public void GetCreationTimeException5 ()
791 File
.GetCreationTime (Path
.InvalidPathChars
[0].ToString ());
795 [ExpectedException(typeof(ArgumentNullException
))]
796 public void GetCreationTimeUtcException1 ()
798 File
.GetCreationTimeUtc (null as string);
802 [ExpectedException(typeof(ArgumentException
))]
803 public void GetCreationTimeUtcException2 ()
805 File
.GetCreationTimeUtc ("");
809 [ExpectedException(typeof(IOException
))]
810 public void GetCreationTimeUtcException3 ()
812 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "GetCreationTimeUtcException3";
814 File
.GetCreationTimeUtc (path
);
818 [ExpectedException(typeof(ArgumentException
))]
819 public void GetCreationTimeUtcException4 ()
821 File
.GetCreationTimeUtc (" ");
825 [ExpectedException(typeof(ArgumentException
))]
826 public void GetCreationTimeUtcException5 ()
828 File
.GetCreationTime (Path
.InvalidPathChars
[0].ToString ());
832 [ExpectedException(typeof(ArgumentNullException
))]
833 public void GetLastAccessTimeException1 ()
835 File
.GetLastAccessTime (null as string);
839 [ExpectedException(typeof(ArgumentException
))]
840 public void GetLastAccessTimeException2 ()
842 File
.GetLastAccessTime ("");
846 [ExpectedException(typeof(IOException
))]
847 public void GetLastAccessTimeException3 ()
849 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "GetLastAccessTimeException3";
851 File
.GetLastAccessTime (path
);
855 [ExpectedException(typeof(ArgumentException
))]
856 public void GetLastAccessTimeException4 ()
858 File
.GetLastAccessTime (" ");
862 [ExpectedException(typeof(ArgumentException
))]
863 public void GetLastAccessTimeException5 ()
865 File
.GetLastAccessTime (Path
.InvalidPathChars
[0].ToString ());
869 [ExpectedException(typeof(ArgumentNullException
))]
870 public void GetLastAccessTimeUtcException1 ()
872 File
.GetLastAccessTimeUtc (null as string);
876 [ExpectedException(typeof(ArgumentException
))]
877 public void GetLastAccessTimeUtcException2 ()
879 File
.GetLastAccessTimeUtc ("");
883 [ExpectedException(typeof(IOException
))]
884 public void GetLastAccessTimeUtcException3 ()
886 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "GetLastAccessTimeUtcException3";
888 File
.GetLastAccessTimeUtc (path
);
892 [ExpectedException(typeof(ArgumentException
))]
893 public void GetLastAccessTimeUtcException4 ()
895 File
.GetLastAccessTimeUtc (" ");
899 [ExpectedException(typeof(ArgumentException
))]
900 public void GetLastAccessTimeUtcException5 ()
902 File
.GetLastAccessTimeUtc (Path
.InvalidPathChars
[0].ToString ());
906 [ExpectedException(typeof(ArgumentNullException
))]
907 public void GetLastWriteTimeException1 ()
909 File
.GetLastWriteTime (null as string);
913 [ExpectedException(typeof(ArgumentException
))]
914 public void GetLastWriteTimeException2 ()
916 File
.GetLastWriteTime ("");
920 [ExpectedException(typeof(IOException
))]
921 public void GetLastWriteTimeException3 ()
923 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "GetLastAccessTimeUtcException3";
925 File
.GetLastWriteTime (path
);
929 [ExpectedException(typeof(ArgumentException
))]
930 public void GetLastWriteTimeException4 ()
932 File
.GetLastWriteTime (" ");
936 [ExpectedException(typeof(ArgumentException
))]
937 public void GetLastWriteTimeException5 ()
939 File
.GetLastWriteTime (Path
.InvalidPathChars
[0].ToString ());
943 [ExpectedException(typeof(ArgumentNullException
))]
944 public void GetLastWriteTimeUtcException1 ()
946 File
.GetLastWriteTimeUtc (null as string);
950 [ExpectedException(typeof(ArgumentException
))]
951 public void GetLastWriteTimeUtcException2 ()
953 File
.GetLastAccessTimeUtc ("");
957 [ExpectedException(typeof(IOException
))]
958 public void GetLastWriteTimeUtcException3 ()
960 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "GetLastWriteTimeUtcException3";
962 File
.GetLastAccessTimeUtc (path
);
966 [ExpectedException(typeof(ArgumentException
))]
967 public void GetLastWriteTimeUtcException4 ()
969 File
.GetLastAccessTimeUtc (" ");
973 [ExpectedException(typeof(ArgumentException
))]
974 public void GetLastWriteTimeUtcException5 ()
976 File
.GetLastAccessTimeUtc (Path
.InvalidPathChars
[0].ToString ());
980 [ExpectedException(typeof(IOException
))]
981 public void FileStreamCloseException ()
983 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "FileStreamCloseException";
985 FileStream stream
= null;
987 stream
= File
.Create (path
);
997 public void FileStreamClose ()
999 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "FileStreamClose";
1000 FileStream stream
= null;
1002 stream
= File
.Create (path
);
1012 // SetCreationTime and SetCreationTimeUtc exceptions
1015 [ExpectedException(typeof (ArgumentNullException
))]
1016 public void SetCreationTimeArgumentNullException1 ()
1018 File
.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1022 [ExpectedException(typeof (ArgumentException
))]
1023 public void SetCreationTimeArgumenException1 ()
1025 File
.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1029 [ExpectedException(typeof (ArgumentException
))]
1030 public void SetCreationTimeArgumenException2 ()
1032 File
.SetCreationTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1036 [ExpectedException(typeof (ArgumentException
))]
1037 public void SetCreationTimeArgumenException3 ()
1039 File
.SetCreationTime (Path
.InvalidPathChars
[1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1043 [ExpectedException(typeof (FileNotFoundException
))]
1044 public void SetCreationTimeFileNotFoundException1 ()
1046 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetCreationTimeFileNotFoundException1";
1049 File
.SetCreationTime (path
, new DateTime (2000, 12, 12, 11, 59, 59));
1053 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1054 // public void SetCreationTimeArgumentOutOfRangeException1 ()
1056 // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
1057 // FileStream stream = null;
1058 // DeleteFile (path);
1060 // stream = File.Create (path);
1062 // File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1064 // if (stream != null)
1066 // DeleteFile (path);
1071 [ExpectedException(typeof (IOException
))]
1072 public void SetCreationTimeIOException1 ()
1074 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "CreationTimeIOException1";
1076 FileStream stream
= null;
1078 stream
= File
.Create (path
);
1079 File
.SetCreationTime (path
, new DateTime (1000, 12, 12, 11, 59, 59));
1088 [ExpectedException(typeof (ArgumentNullException
))]
1089 public void SetCreationTimeUtcArgumentNullException1 ()
1091 File
.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1095 [ExpectedException(typeof (ArgumentException
))]
1096 public void SetCreationTimeUtcArgumenException1 ()
1098 File
.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1102 [ExpectedException(typeof (ArgumentException
))]
1103 public void SetCreationTimeUtcArgumenException2 ()
1105 File
.SetCreationTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1109 [ExpectedException(typeof (ArgumentException
))]
1110 public void SetCreationTimeUtcArgumenException3 ()
1112 File
.SetCreationTimeUtc (Path
.InvalidPathChars
[1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1116 [ExpectedException(typeof (FileNotFoundException
))]
1117 public void SetCreationTimeUtcFileNotFoundException1 ()
1119 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetCreationTimeUtcFileNotFoundException1";
1122 File
.SetCreationTimeUtc (path
, new DateTime (2000, 12, 12, 11, 59, 59));
1126 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1127 // public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
1129 // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
1130 // DeleteFile (path);
1131 // FileStream stream = null;
1133 // stream = File.Create (path);
1135 // File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1137 // if (stream != null)
1139 // DeleteFile (path);
1144 [ExpectedException(typeof (IOException
))]
1145 public void SetCreationTimeUtcIOException1 ()
1147 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetCreationTimeUtcIOException1";
1149 FileStream stream
= null;
1151 stream
= File
.Create (path
);
1152 File
.SetCreationTimeUtc (path
, new DateTime (1000, 12, 12, 11, 59, 59));
1160 // SetLastAccessTime and SetLastAccessTimeUtc exceptions
1163 [ExpectedException(typeof (ArgumentNullException
))]
1164 public void SetLastAccessTimeArgumentNullException1 ()
1166 File
.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1170 [ExpectedException(typeof (ArgumentException
))]
1171 public void SetLastAccessTimeArgumenException1 ()
1173 File
.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1177 [ExpectedException(typeof (ArgumentException
))]
1178 public void SetLastAccessTimeArgumenException2 ()
1180 File
.SetLastAccessTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1184 [ExpectedException(typeof (ArgumentException
))]
1185 public void SetLastAccessTimeArgumenException3 ()
1187 File
.SetLastAccessTime (Path
.InvalidPathChars
[1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1191 [ExpectedException(typeof (FileNotFoundException
))]
1192 public void SetLastAccessTimeFileNotFoundException1 ()
1194 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetLastAccessTimeFileNotFoundException1";
1197 File
.SetLastAccessTime (path
, new DateTime (2000, 12, 12, 11, 59, 59));
1201 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1202 // public void SetLastAccessTimeArgumentOutOfRangeException1 ()
1204 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
1205 // DeleteFile (path);
1206 // FileStream stream = null;
1208 // stream = File.Create (path);
1210 // File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1212 // if (stream != null)
1214 // DeleteFile (path);
1219 [ExpectedException(typeof (IOException
))]
1220 public void SetLastAccessTimeIOException1 ()
1222 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "LastAccessIOException1";
1224 FileStream stream
= null;
1226 stream
= File
.Create (path
);
1227 File
.SetLastAccessTime (path
, new DateTime (1000, 12, 12, 11, 59, 59));
1236 [ExpectedException(typeof (ArgumentNullException
))]
1237 public void SetLastAccessTimeUtcArgumentNullException1 ()
1239 File
.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1243 [ExpectedException(typeof (ArgumentException
))]
1244 public void SetCLastAccessTimeUtcArgumenException1 ()
1246 File
.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1250 [ExpectedException(typeof (ArgumentException
))]
1251 public void SetLastAccessTimeUtcArgumenException2 ()
1253 File
.SetLastAccessTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1257 [ExpectedException(typeof (ArgumentException
))]
1258 public void SetLastAccessTimeUtcArgumenException3 ()
1260 File
.SetLastAccessTimeUtc (Path
.InvalidPathChars
[1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1264 [ExpectedException(typeof (FileNotFoundException
))]
1265 public void SetLastAccessTimeUtcFileNotFoundException1 ()
1267 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetLastAccessTimeUtcFileNotFoundException1";
1270 File
.SetLastAccessTimeUtc (path
, new DateTime (2000, 12, 12, 11, 59, 59));
1274 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1275 // public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
1277 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
1278 // DeleteFile (path);
1279 // FileStream stream = null;
1281 // stream = File.Create (path);
1283 // File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1285 // if (stream != null)
1287 // DeleteFile (path);
1292 [ExpectedException(typeof (IOException
))]
1293 public void SetLastAccessTimeUtcIOException1 ()
1295 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetLastAccessTimeUtcIOException1";
1297 FileStream stream
= null;
1299 stream
= File
.Create (path
);
1300 File
.SetLastAccessTimeUtc (path
, new DateTime (1000, 12, 12, 11, 59, 59));
1308 // SetLastWriteTime and SetLastWriteTimeUtc exceptions
1311 [ExpectedException(typeof (ArgumentNullException
))]
1312 public void SetLastWriteTimeArgumentNullException1 ()
1314 File
.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1318 [ExpectedException(typeof (ArgumentException
))]
1319 public void SetLastWriteTimeArgumenException1 ()
1321 File
.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1325 [ExpectedException(typeof (ArgumentException
))]
1326 public void SetLastWriteTimeArgumenException2 ()
1328 File
.SetLastWriteTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1332 [ExpectedException(typeof (ArgumentException
))]
1333 public void SetLastWriteTimeArgumenException3 ()
1335 File
.SetLastWriteTime (Path
.InvalidPathChars
[1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1339 [ExpectedException(typeof (FileNotFoundException
))]
1340 public void SetLastWriteTimeFileNotFoundException1 ()
1342 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetLastWriteTimeFileNotFoundException1";
1345 File
.SetLastWriteTime (path
, new DateTime (2000, 12, 12, 11, 59, 59));
1349 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1350 // public void SetLastWriteTimeArgumentOutOfRangeException1 ()
1352 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
1353 // DeleteFile (path);
1354 // FileStream stream = null;
1356 // stream = File.Create (path);
1358 // File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1360 // if (stream != null)
1362 // DeleteFile (path);
1367 [ExpectedException(typeof (IOException
))]
1368 public void SetLastWriteTimeIOException1 ()
1370 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "LastWriteTimeIOException1";
1372 FileStream stream
= null;
1374 stream
= File
.Create (path
);
1375 File
.SetLastWriteTime (path
, new DateTime (1000, 12, 12, 11, 59, 59));
1384 [ExpectedException(typeof (ArgumentNullException
))]
1385 public void SetLastWriteTimeUtcArgumentNullException1 ()
1387 File
.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1391 [ExpectedException(typeof (ArgumentException
))]
1392 public void SetCLastWriteTimeUtcArgumenException1 ()
1394 File
.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1398 [ExpectedException(typeof (ArgumentException
))]
1399 public void SetLastWriteTimeUtcArgumenException2 ()
1401 File
.SetLastWriteTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1405 [ExpectedException(typeof (ArgumentException
))]
1406 public void SetLastWriteTimeUtcArgumenException3 ()
1408 File
.SetLastWriteTimeUtc (Path
.InvalidPathChars
[1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1412 [ExpectedException(typeof (FileNotFoundException
))]
1413 public void SetLastWriteTimeUtcFileNotFoundException1 ()
1415 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetLastWriteTimeUtcFileNotFoundException1";
1418 File
.SetLastAccessTimeUtc (path
, new DateTime (2000, 12, 12, 11, 59, 59));
1422 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1423 // public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
1425 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
1426 // DeleteFile (path);
1427 // FileStream stream = null;
1429 // stream = File.Create (path);
1431 // File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1433 // if (stream != null)
1435 // DeleteFile (path);
1440 [ExpectedException(typeof (IOException
))]
1441 public void SetLastWriteTimeUtcIOException1 ()
1443 string path
= TempFolder
+ Path
.DirectorySeparatorChar
+ "SetLastWriteTimeUtcIOException1";
1445 FileStream stream
= null;
1447 stream
= File
.Create (path
);
1448 File
.SetLastAccessTimeUtc (path
, new DateTime (1000, 12, 12, 11, 59, 59));
1456 private void DeleteFile (string path
)
1458 if (File
.Exists (path
))