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 [Category("NotWorking")]
308 public void DeleteOpenStreamException ()
310 string path = TempFolder + Path.DirectorySeparatorChar + "DeleteOpenStreamException";
312 FileStream stream = null;
314 stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
324 [ExpectedException(typeof (ArgumentNullException))]
325 public void MoveException1 ()
327 File.Move (null, "b");
331 [ExpectedException(typeof (ArgumentNullException))]
332 public void MoveException2 ()
334 File.Move ("a", null);
338 [ExpectedException(typeof (ArgumentException))]
339 public void MoveException3 ()
345 [ExpectedException(typeof (ArgumentException))]
346 public void MoveException4 ()
352 [ExpectedException(typeof (ArgumentException))]
353 public void MoveException5 ()
355 File.Move (" ", "b");
359 [ExpectedException(typeof (ArgumentException))]
360 public void MoveException6 ()
362 File.Move ("a", " ");
366 [ExpectedException(typeof (FileNotFoundException))]
367 public void MoveException7 ()
369 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist");
370 File.Move (TempFolder + Path.DirectorySeparatorChar + "doesnotexist", "b");
374 [ExpectedException(typeof (DirectoryNotFoundException))]
375 public void MoveException8 ()
377 string path = TempFolder + Path.DirectorySeparatorChar + "foo";
380 File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
381 File.Copy(TempFolder + Path.DirectorySeparatorChar + "AFile.txt", path, true);
382 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
383 File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
385 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
391 [ExpectedException(typeof (IOException))]
392 public void MoveException9 ()
394 File.Create (TempFolder + Path.DirectorySeparatorChar + "foo").Close ();
396 File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder);
398 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "foo");
403 public void TestMove ()
405 string bar = TempFolder + Path.DirectorySeparatorChar + "bar";
406 string baz = TempFolder + Path.DirectorySeparatorChar + "baz";
407 if (!File.Exists (bar)) {
408 FileStream f = File.Create(bar);
412 Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should exist", File.Exists (bar));
413 File.Move (bar, baz);
414 Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should not exist", !File.Exists (bar));
415 Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "baz should exist", File.Exists (baz));
417 // Test moving of directories
418 string dir = Path.Combine (TempFolder, "dir");
419 string dir2 = Path.Combine (TempFolder, "dir2");
420 string dir_foo = Path.Combine (dir, "foo");
421 string dir2_foo = Path.Combine (dir2, "foo");
423 if (Directory.Exists (dir))
424 Directory.Delete (dir, true);
426 Directory.CreateDirectory (dir);
427 Directory.CreateDirectory (dir2);
428 File.Create (dir_foo).Close ();
429 File.Move (dir_foo, dir2_foo);
430 Assert (File.Exists (dir2_foo));
432 Directory.Delete (dir, true);
433 Directory.Delete (dir2, true);
434 DeleteFile (dir_foo);
435 DeleteFile (dir2_foo);
439 public void TestOpen ()
442 FileStream stream = null;
444 path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
445 if (!File.Exists (path))
446 stream = File.Create (path);
448 stream = File.Open (path, FileMode.Open);
450 } catch (Exception e) {
451 Fail ("Unable to open " + TempFolder + Path.DirectorySeparatorChar + "AFile.txt: e=" + e.ToString());
460 /* Exception tests */
462 path = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
463 stream = File.Open (path, FileMode.Open);
464 Fail ("File 'filedoesnotexist' should not exist");
465 } catch (FileNotFoundException) {
466 // do nothing, this is what we expect
467 } catch (Exception e) {
468 Fail ("Unexpect exception caught: e=" + e.ToString());
479 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
480 if (!File.Exists (path))
481 File.Create (path).Close ();
482 FileStream stream = null;
485 stream = File.Open (path, FileMode.Open);
487 Assertion.AssertEquals ("test#01", true, stream.CanRead);
488 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
489 Assertion.AssertEquals ("test#03", true, stream.CanWrite);
492 stream = File.Open (path, FileMode.Open, FileAccess.Write);
493 Assertion.AssertEquals ("test#04", false, stream.CanRead);
494 Assertion.AssertEquals ("test#05", true, stream.CanSeek);
495 Assertion.AssertEquals ("test#06", true, stream.CanWrite);
498 stream = File.Open (path, FileMode.Open, FileAccess.Read);
499 Assertion.AssertEquals ("test#04", true, stream.CanRead);
500 Assertion.AssertEquals ("test#05", true, stream.CanSeek);
501 Assertion.AssertEquals ("test#06", false, stream.CanWrite);
512 [ExpectedException(typeof(ArgumentException))]
513 public void OpenException1 ()
515 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
516 FileStream stream = null;
517 // CreateNew + Read throws an exceptoin
519 stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.CreateNew, FileAccess.Read);
528 [ExpectedException(typeof(ArgumentException))]
529 public void OpenException2 ()
531 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
533 // Append + Read throws an exceptoin
534 if (!File.Exists (path))
535 File.Create (path).Close ();
537 s = File.Open (path, FileMode.Append, FileAccess.Read);
546 public void OpenRead ()
548 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
549 if (!File.Exists (path))
550 File.Create (path).Close ();
551 FileStream stream = null;
554 stream = File.OpenRead (path);
556 Assertion.AssertEquals ("test#01", true, stream.CanRead);
557 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
558 Assertion.AssertEquals ("test#03", false, stream.CanWrite);
568 public void OpenWrite ()
570 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
571 if (!File.Exists (path))
572 File.Create (path).Close ();
573 FileStream stream = null;
576 stream = File.OpenWrite (path);
577 Assertion.AssertEquals ("test#01", false, stream.CanRead);
578 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
579 Assertion.AssertEquals ("test#03", true, stream.CanWrite);
589 public void TestGetCreationTime ()
591 string path = TempFolder + Path.DirectorySeparatorChar + "baz";
595 File.Create (path).Close();
596 DateTime time = File.GetCreationTime (path);
597 Assert ("GetCreationTime incorrect", (DateTime.Now - time).TotalSeconds < 10);
604 [ExpectedException(typeof(IOException))]
605 public void TestGetCreationTimeException ()
607 // Test nonexistent files
608 string path2 = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
610 // should throw an exception
611 File.GetCreationTime (path2);
616 // Setting the creation time on Unix is not possible
617 [Test][Category("NotWorking")]
618 public void CreationTime ()
620 string path = TempFolder + Path.DirectorySeparatorChar + "creationTime";
621 if (File.Exists (path))
623 FileStream stream = null;
626 stream = File.Create (path);
629 File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
630 DateTime time = File.GetCreationTime (path);
631 Assertion.AssertEquals ("test#01", 2002, time.Year);
632 Assertion.AssertEquals ("test#02", 4, time.Month);
633 Assertion.AssertEquals ("test#03", 6, time.Day);
634 Assertion.AssertEquals ("test#04", 4, time.Hour);
635 Assertion.AssertEquals ("test#05", 4, time.Second);
637 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
638 Assertion.AssertEquals ("test#06", 2002, time.Year);
639 Assertion.AssertEquals ("test#07", 4, time.Month);
640 Assertion.AssertEquals ("test#08", 6, time.Day);
641 Assertion.AssertEquals ("test#09", 4, time.Hour);
642 Assertion.AssertEquals ("test#10", 4, time.Second);
644 File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
645 time = File.GetCreationTimeUtc (path);
646 Assertion.AssertEquals ("test#11", 2002, time.Year);
647 Assertion.AssertEquals ("test#12", 4, time.Month);
648 Assertion.AssertEquals ("test#13", 6, time.Day);
649 Assertion.AssertEquals ("test#14", 4, time.Hour);
650 Assertion.AssertEquals ("test#15", 4, time.Second);
652 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
653 Assertion.AssertEquals ("test#16", 2002, time.Year);
654 Assertion.AssertEquals ("test#17", 4, time.Month);
655 Assertion.AssertEquals ("test#18", 6, time.Day);
656 Assertion.AssertEquals ("test#19", 4, time.Hour);
657 Assertion.AssertEquals ("test#20", 4, time.Second);
666 public void LastAccessTime ()
668 string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";
669 if (File.Exists (path))
671 FileStream stream = null;
673 stream = File.Create (path);
676 File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
677 DateTime time = File.GetLastAccessTime (path);
678 Assertion.AssertEquals ("test#01", 2002, time.Year);
679 Assertion.AssertEquals ("test#02", 4, time.Month);
680 Assertion.AssertEquals ("test#03", 6, time.Day);
681 Assertion.AssertEquals ("test#04", 4, time.Hour);
682 Assertion.AssertEquals ("test#05", 4, time.Second);
684 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
685 Assertion.AssertEquals ("test#06", 2002, time.Year);
686 Assertion.AssertEquals ("test#07", 4, time.Month);
687 Assertion.AssertEquals ("test#08", 6, time.Day);
688 Assertion.AssertEquals ("test#09", 4, time.Hour);
689 Assertion.AssertEquals ("test#10", 4, time.Second);
691 File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
692 time = File.GetLastAccessTimeUtc (path);
693 Assertion.AssertEquals ("test#11", 2002, time.Year);
694 Assertion.AssertEquals ("test#12", 4, time.Month);
695 Assertion.AssertEquals ("test#13", 6, time.Day);
696 Assertion.AssertEquals ("test#14", 4, time.Hour);
697 Assertion.AssertEquals ("test#15", 4, time.Second);
699 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
700 Assertion.AssertEquals ("test#16", 2002, time.Year);
701 Assertion.AssertEquals ("test#17", 4, time.Month);
702 Assertion.AssertEquals ("test#18", 6, time.Day);
703 Assertion.AssertEquals ("test#19", 4, time.Hour);
704 Assertion.AssertEquals ("test#20", 4, time.Second);
713 public void LastWriteTime ()
715 string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";
716 if (File.Exists (path))
718 FileStream stream = null;
720 stream = File.Create (path);
723 File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
724 DateTime time = File.GetLastWriteTime (path);
725 Assertion.AssertEquals ("test#01", 2002, time.Year);
726 Assertion.AssertEquals ("test#02", 4, time.Month);
727 Assertion.AssertEquals ("test#03", 6, time.Day);
728 Assertion.AssertEquals ("test#04", 4, time.Hour);
729 Assertion.AssertEquals ("test#05", 4, time.Second);
731 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
732 Assertion.AssertEquals ("test#06", 2002, time.Year);
733 Assertion.AssertEquals ("test#07", 4, time.Month);
734 Assertion.AssertEquals ("test#08", 6, time.Day);
735 Assertion.AssertEquals ("test#09", 4, time.Hour);
736 Assertion.AssertEquals ("test#10", 4, time.Second);
738 File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
739 time = File.GetLastWriteTimeUtc (path);
740 Assertion.AssertEquals ("test#11", 2002, time.Year);
741 Assertion.AssertEquals ("test#12", 4, time.Month);
742 Assertion.AssertEquals ("test#13", 6, time.Day);
743 Assertion.AssertEquals ("test#14", 4, time.Hour);
744 Assertion.AssertEquals ("test#15", 4, time.Second);
746 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
747 Assertion.AssertEquals ("test#16", 2002, time.Year);
748 Assertion.AssertEquals ("test#17", 4, time.Month);
749 Assertion.AssertEquals ("test#18", 6, time.Day);
750 Assertion.AssertEquals ("test#19", 4, time.Hour);
751 Assertion.AssertEquals ("test#20", 4, time.Second);
760 [ExpectedException(typeof(ArgumentNullException))]
761 public void GetCreationTimeException1 ()
763 File.GetCreationTime (null as string);
767 [ExpectedException(typeof(ArgumentException))]
768 public void GetCreationTimeException2 ()
770 File.GetCreationTime ("");
774 [ExpectedException(typeof(IOException))]
775 public void GetCreationTimeException3 ()
777 string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
779 File.GetCreationTime (path);
783 [ExpectedException(typeof(ArgumentException))]
784 public void GetCreationTimeException4 ()
786 File.GetCreationTime (" ");
790 [ExpectedException(typeof(ArgumentException))]
791 public void GetCreationTimeException5 ()
793 File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
797 [ExpectedException(typeof(ArgumentNullException))]
798 public void GetCreationTimeUtcException1 ()
800 File.GetCreationTimeUtc (null as string);
804 [ExpectedException(typeof(ArgumentException))]
805 public void GetCreationTimeUtcException2 ()
807 File.GetCreationTimeUtc ("");
811 [ExpectedException(typeof(IOException))]
812 public void GetCreationTimeUtcException3 ()
814 string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
816 File.GetCreationTimeUtc (path);
820 [ExpectedException(typeof(ArgumentException))]
821 public void GetCreationTimeUtcException4 ()
823 File.GetCreationTimeUtc (" ");
827 [ExpectedException(typeof(ArgumentException))]
828 public void GetCreationTimeUtcException5 ()
830 File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
834 [ExpectedException(typeof(ArgumentNullException))]
835 public void GetLastAccessTimeException1 ()
837 File.GetLastAccessTime (null as string);
841 [ExpectedException(typeof(ArgumentException))]
842 public void GetLastAccessTimeException2 ()
844 File.GetLastAccessTime ("");
848 [ExpectedException(typeof(IOException))]
849 public void GetLastAccessTimeException3 ()
851 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
853 File.GetLastAccessTime (path);
857 [ExpectedException(typeof(ArgumentException))]
858 public void GetLastAccessTimeException4 ()
860 File.GetLastAccessTime (" ");
864 [ExpectedException(typeof(ArgumentException))]
865 public void GetLastAccessTimeException5 ()
867 File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
871 [ExpectedException(typeof(ArgumentNullException))]
872 public void GetLastAccessTimeUtcException1 ()
874 File.GetLastAccessTimeUtc (null as string);
878 [ExpectedException(typeof(ArgumentException))]
879 public void GetLastAccessTimeUtcException2 ()
881 File.GetLastAccessTimeUtc ("");
885 [ExpectedException(typeof(IOException))]
886 public void GetLastAccessTimeUtcException3 ()
888 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
890 File.GetLastAccessTimeUtc (path);
894 [ExpectedException(typeof(ArgumentException))]
895 public void GetLastAccessTimeUtcException4 ()
897 File.GetLastAccessTimeUtc (" ");
901 [ExpectedException(typeof(ArgumentException))]
902 public void GetLastAccessTimeUtcException5 ()
904 File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
908 [ExpectedException(typeof(ArgumentNullException))]
909 public void GetLastWriteTimeException1 ()
911 File.GetLastWriteTime (null as string);
915 [ExpectedException(typeof(ArgumentException))]
916 public void GetLastWriteTimeException2 ()
918 File.GetLastWriteTime ("");
922 [ExpectedException(typeof(IOException))]
923 public void GetLastWriteTimeException3 ()
925 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
927 File.GetLastWriteTime (path);
931 [ExpectedException(typeof(ArgumentException))]
932 public void GetLastWriteTimeException4 ()
934 File.GetLastWriteTime (" ");
938 [ExpectedException(typeof(ArgumentException))]
939 public void GetLastWriteTimeException5 ()
941 File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
945 [ExpectedException(typeof(ArgumentNullException))]
946 public void GetLastWriteTimeUtcException1 ()
948 File.GetLastWriteTimeUtc (null as string);
952 [ExpectedException(typeof(ArgumentException))]
953 public void GetLastWriteTimeUtcException2 ()
955 File.GetLastAccessTimeUtc ("");
959 [ExpectedException(typeof(IOException))]
960 public void GetLastWriteTimeUtcException3 ()
962 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
964 File.GetLastAccessTimeUtc (path);
968 [ExpectedException(typeof(ArgumentException))]
969 public void GetLastWriteTimeUtcException4 ()
971 File.GetLastAccessTimeUtc (" ");
975 [ExpectedException(typeof(ArgumentException))]
976 public void GetLastWriteTimeUtcException5 ()
978 File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
982 [ExpectedException(typeof(IOException))]
983 [Category("ValueAdd")]
985 // This is category ValueAdd, since in Unix the semantics allow for
986 // a file to be deleted while a handle to it remains.
988 public void FileStreamCloseException ()
990 string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamCloseException";
992 FileStream stream = null;
994 stream = File.Create (path);
1004 public void FileStreamClose ()
1006 string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
1007 FileStream stream = null;
1009 stream = File.Create (path);
1019 // SetCreationTime and SetCreationTimeUtc exceptions
1022 [ExpectedException(typeof (ArgumentNullException))]
1023 public void SetCreationTimeArgumentNullException1 ()
1025 File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1029 [ExpectedException(typeof (ArgumentException))]
1030 public void SetCreationTimeArgumenException1 ()
1032 File.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1036 [ExpectedException(typeof (ArgumentException))]
1037 public void SetCreationTimeArgumenException2 ()
1039 File.SetCreationTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1043 [ExpectedException(typeof (ArgumentException))]
1044 [Category("ValueAdd")]
1045 // On Unix there are no invalid path chars.
1046 public void SetCreationTimeArgumenException3 ()
1049 File.SetCreationTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1053 [ExpectedException(typeof (FileNotFoundException))]
1054 public void SetCreationTimeFileNotFoundException1 ()
1056 string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
1059 File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1063 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1064 // public void SetCreationTimeArgumentOutOfRangeException1 ()
1066 // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
1067 // FileStream stream = null;
1068 // DeleteFile (path);
1070 // stream = File.Create (path);
1072 // File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1074 // if (stream != null)
1076 // DeleteFile (path);
1081 [ExpectedException(typeof (IOException))]
1082 public void SetCreationTimeIOException1 ()
1084 string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
1086 FileStream stream = null;
1088 stream = File.Create (path);
1089 File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1098 [ExpectedException(typeof (ArgumentNullException))]
1099 public void SetCreationTimeUtcArgumentNullException1 ()
1101 File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1105 [ExpectedException(typeof (ArgumentException))]
1106 public void SetCreationTimeUtcArgumenException1 ()
1108 File.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1112 [ExpectedException(typeof (ArgumentException))]
1113 public void SetCreationTimeUtcArgumenException2 ()
1115 File.SetCreationTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1119 [ExpectedException(typeof (ArgumentException))]
1120 [Category("ValueAdd")]
1121 // On Unix there are no invalid path chars.
1122 public void SetCreationTimeUtcArgumenException3 ()
1124 File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1128 [ExpectedException(typeof (FileNotFoundException))]
1129 public void SetCreationTimeUtcFileNotFoundException1 ()
1131 string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
1134 File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1138 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1139 // public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
1141 // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
1142 // DeleteFile (path);
1143 // FileStream stream = null;
1145 // stream = File.Create (path);
1147 // File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1149 // if (stream != null)
1151 // DeleteFile (path);
1156 [ExpectedException(typeof (IOException))]
1157 public void SetCreationTimeUtcIOException1 ()
1159 string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
1161 FileStream stream = null;
1163 stream = File.Create (path);
1164 File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1172 // SetLastAccessTime and SetLastAccessTimeUtc exceptions
1175 [ExpectedException(typeof (ArgumentNullException))]
1176 public void SetLastAccessTimeArgumentNullException1 ()
1178 File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1182 [ExpectedException(typeof (ArgumentException))]
1183 public void SetLastAccessTimeArgumenException1 ()
1185 File.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1189 [ExpectedException(typeof (ArgumentException))]
1190 public void SetLastAccessTimeArgumenException2 ()
1192 File.SetLastAccessTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1196 [ExpectedException(typeof (ArgumentException))]
1197 [Category("ValueAdd")]
1198 // On Unix there are no invalid path chars.
1199 public void SetLastAccessTimeArgumenException3 ()
1201 File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1205 [ExpectedException(typeof (FileNotFoundException))]
1206 public void SetLastAccessTimeFileNotFoundException1 ()
1208 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
1211 File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1215 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1216 // public void SetLastAccessTimeArgumentOutOfRangeException1 ()
1218 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
1219 // DeleteFile (path);
1220 // FileStream stream = null;
1222 // stream = File.Create (path);
1224 // File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1226 // if (stream != null)
1228 // DeleteFile (path);
1233 [ExpectedException(typeof (IOException))]
1234 public void SetLastAccessTimeIOException1 ()
1236 string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
1238 FileStream stream = null;
1240 stream = File.Create (path);
1241 File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1250 [ExpectedException(typeof (ArgumentNullException))]
1251 public void SetLastAccessTimeUtcArgumentNullException1 ()
1253 File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1257 [ExpectedException(typeof (ArgumentException))]
1258 public void SetCLastAccessTimeUtcArgumenException1 ()
1260 File.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1264 [ExpectedException(typeof (ArgumentException))]
1265 public void SetLastAccessTimeUtcArgumenException2 ()
1267 File.SetLastAccessTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1271 [ExpectedException(typeof (ArgumentException))]
1272 [Category("ValueAdd")]
1273 // On Unix there are no invalid path chars.
1274 public void SetLastAccessTimeUtcArgumenException3 ()
1276 File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1280 [ExpectedException(typeof (FileNotFoundException))]
1281 public void SetLastAccessTimeUtcFileNotFoundException1 ()
1283 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
1286 File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1290 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1291 // public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
1293 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
1294 // DeleteFile (path);
1295 // FileStream stream = null;
1297 // stream = File.Create (path);
1299 // File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1301 // if (stream != null)
1303 // DeleteFile (path);
1308 [ExpectedException(typeof (IOException))]
1309 public void SetLastAccessTimeUtcIOException1 ()
1311 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
1313 FileStream stream = null;
1315 stream = File.Create (path);
1316 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1324 // SetLastWriteTime and SetLastWriteTimeUtc exceptions
1327 [ExpectedException(typeof (ArgumentNullException))]
1328 public void SetLastWriteTimeArgumentNullException1 ()
1330 File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1334 [ExpectedException(typeof (ArgumentException))]
1335 public void SetLastWriteTimeArgumenException1 ()
1337 File.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1341 [ExpectedException(typeof (ArgumentException))]
1342 public void SetLastWriteTimeArgumenException2 ()
1344 File.SetLastWriteTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1348 [ExpectedException(typeof (ArgumentException))]
1349 [Category("ValueAdd")]
1350 // On Unix there are no invalid path chars.
1351 public void SetLastWriteTimeArgumenException3 ()
1353 File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1357 [ExpectedException(typeof (FileNotFoundException))]
1358 public void SetLastWriteTimeFileNotFoundException1 ()
1360 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
1363 File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1367 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1368 // public void SetLastWriteTimeArgumentOutOfRangeException1 ()
1370 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
1371 // DeleteFile (path);
1372 // FileStream stream = null;
1374 // stream = File.Create (path);
1376 // File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1378 // if (stream != null)
1380 // DeleteFile (path);
1385 [ExpectedException(typeof (IOException))]
1386 public void SetLastWriteTimeIOException1 ()
1388 string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
1390 FileStream stream = null;
1392 stream = File.Create (path);
1393 File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1402 [ExpectedException(typeof (ArgumentNullException))]
1403 public void SetLastWriteTimeUtcArgumentNullException1 ()
1405 File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1409 [ExpectedException(typeof (ArgumentException))]
1410 public void SetCLastWriteTimeUtcArgumenException1 ()
1412 File.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1416 [ExpectedException(typeof (ArgumentException))]
1417 public void SetLastWriteTimeUtcArgumenException2 ()
1419 File.SetLastWriteTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1423 [ExpectedException(typeof (ArgumentException))]
1424 [Category("ValueAdd")]
1425 // On Unix there are no invalid path chars.
1426 public void SetLastWriteTimeUtcArgumenException3 ()
1428 File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1432 [ExpectedException(typeof (FileNotFoundException))]
1433 public void SetLastWriteTimeUtcFileNotFoundException1 ()
1435 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
1438 File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1442 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1443 // public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
1445 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
1446 // DeleteFile (path);
1447 // FileStream stream = null;
1449 // stream = File.Create (path);
1451 // File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1453 // if (stream != null)
1455 // DeleteFile (path);
1460 [ExpectedException(typeof (IOException))]
1461 public void SetLastWriteTimeUtcIOException1 ()
1463 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
1465 FileStream stream = null;
1467 stream = File.Create (path);
1468 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1476 private void DeleteFile (string path)
1478 if (File.Exists (path))