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 ("><|"));
74 Assert ("?*", !File.Exists ("?*"));
78 public void Exists_InvalidDirectory ()
80 Assert ("InvalidDirectory", !File.Exists (Path.Combine ("does not exist", "file.txt")));
84 [ExpectedException(typeof (ArgumentNullException))]
85 public void CtorArgumentNullException1 ()
87 FileStream stream = File.Create (null);
91 [ExpectedException(typeof (ArgumentException))]
92 public void CtorArgumentException1 ()
94 FileStream stream = File.Create ("");
98 [ExpectedException(typeof (ArgumentException))]
99 public void CtorArgumentException2 ()
101 FileStream stream = File.Create (" ");
105 [ExpectedException(typeof (DirectoryNotFoundException))]
106 public void CtorDirectoryNotFoundException ()
108 FileStream stream = null;
109 string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
112 stream = File.Create (path);
121 public void TestCreate ()
123 FileStream stream = null;
125 /* positive test: create resources/foo */
127 path = TempFolder + Path.DirectorySeparatorChar + "foo";
128 stream = File.Create (path);
129 Assert ("File should exist", File.Exists (path));
131 } catch (Exception e) {
132 Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
142 /* positive test: repeat test above again to test for overwriting file */
144 path = TempFolder + Path.DirectorySeparatorChar + "foo";
145 stream = File.Create (path);
146 Assert ("File should exist", File.Exists (path));
148 } catch (Exception e) {
149 Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
158 [ExpectedException(typeof(ArgumentNullException))]
159 public void CopyArgumentNullException1 ()
161 File.Copy (null, "b");
165 [ExpectedException(typeof(ArgumentNullException))]
166 public void CopyArgumentNullException2 ()
168 File.Copy ("a", null);
172 [ExpectedException(typeof(ArgumentException))]
173 public void CopyArgumentException1 ()
179 [ExpectedException(typeof(ArgumentException))]
180 public void CopyArgumentException2 ()
186 [ExpectedException(typeof(ArgumentException))]
187 public void CopyArgumentException3 ()
189 File.Copy (" ", "b");
193 [ExpectedException(typeof(ArgumentException))]
194 public void CopyArgumentException4 ()
196 File.Copy ("a", " ");
200 [ExpectedException(typeof(FileNotFoundException))]
201 public void CopyFileNotFoundException ()
203 File.Copy ("doesnotexist", "b");
206 [ExpectedException(typeof(IOException))]
207 public void CopyIOException ()
209 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
210 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
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");
216 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
217 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
222 public void TestCopy ()
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 */
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());
240 /* positive test: copy resources/AFile.txt to resources/bar, overwrite */
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());
256 [ExpectedException (typeof (ArgumentNullException))]
257 public void DeleteArgumentNullException ()
263 [ExpectedException (typeof (ArgumentException))]
264 public void DeleteArgumentException1 ()
270 [ExpectedException (typeof (ArgumentException))]
271 public void DeleteArgumentException2 ()
277 [ExpectedException (typeof (DirectoryNotFoundException))]
278 public void DeleteDirectoryNotFoundException ()
280 string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
281 if (Directory.Exists (path))
282 Directory.Delete (path, true);
288 public void TestDelete ()
290 string foopath = TempFolder + Path.DirectorySeparatorChar + "foo";
291 DeleteFile (foopath);
293 File.Create (foopath).Close ();
296 File.Delete (foopath);
297 } catch (Exception e) {
298 Fail ("Unable to delete " + foopath + " e=" + e.ToString());
300 Assert ("File " + foopath + " should not exist after File.Delete", !File.Exists (foopath));
302 DeleteFile (foopath);
307 [ExpectedException(typeof (IOException))]
308 [Category("NotWorking")]
309 public void DeleteOpenStreamException ()
311 string path = TempFolder + Path.DirectorySeparatorChar + "DeleteOpenStreamException";
313 FileStream stream = null;
315 stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
325 [ExpectedException(typeof (ArgumentNullException))]
326 public void MoveException1 ()
328 File.Move (null, "b");
332 [ExpectedException(typeof (ArgumentNullException))]
333 public void MoveException2 ()
335 File.Move ("a", null);
339 [ExpectedException(typeof (ArgumentException))]
340 public void MoveException3 ()
346 [ExpectedException(typeof (ArgumentException))]
347 public void MoveException4 ()
353 [ExpectedException(typeof (ArgumentException))]
354 public void MoveException5 ()
356 File.Move (" ", "b");
360 [ExpectedException(typeof (ArgumentException))]
361 public void MoveException6 ()
363 File.Move ("a", " ");
367 [ExpectedException(typeof (FileNotFoundException))]
368 public void MoveException7 ()
370 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist");
371 File.Move (TempFolder + Path.DirectorySeparatorChar + "doesnotexist", "b");
375 [ExpectedException(typeof (DirectoryNotFoundException))]
376 public void MoveException8 ()
378 string path = TempFolder + Path.DirectorySeparatorChar + "foo";
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");
386 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
392 [ExpectedException(typeof (IOException))]
393 public void MoveException9 ()
395 File.Create (TempFolder + Path.DirectorySeparatorChar + "foo").Close ();
397 File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder);
399 DeleteFile (TempFolder + Path.DirectorySeparatorChar + "foo");
404 public void TestMove ()
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);
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));
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");
424 if (Directory.Exists (dir))
425 Directory.Delete (dir, true);
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));
433 Directory.Delete (dir, true);
434 Directory.Delete (dir2, true);
435 DeleteFile (dir_foo);
436 DeleteFile (dir2_foo);
440 public void TestOpen ()
443 FileStream stream = null;
445 path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
446 if (!File.Exists (path))
447 stream = File.Create (path);
449 stream = File.Open (path, FileMode.Open);
451 } catch (Exception e) {
452 Fail ("Unable to open " + TempFolder + Path.DirectorySeparatorChar + "AFile.txt: e=" + e.ToString());
461 /* Exception tests */
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());
480 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
481 if (!File.Exists (path))
482 File.Create (path).Close ();
483 FileStream stream = null;
486 stream = File.Open (path, FileMode.Open);
488 Assertion.AssertEquals ("test#01", true, stream.CanRead);
489 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
490 Assertion.AssertEquals ("test#03", true, stream.CanWrite);
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);
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);
513 [ExpectedException(typeof(ArgumentException))]
514 public void OpenException1 ()
516 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
517 FileStream stream = null;
518 // CreateNew + Read throws an exceptoin
520 stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.CreateNew, FileAccess.Read);
529 [ExpectedException(typeof(ArgumentException))]
530 public void OpenException2 ()
532 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
534 // Append + Read throws an exceptoin
535 if (!File.Exists (path))
536 File.Create (path).Close ();
538 s = File.Open (path, FileMode.Append, FileAccess.Read);
547 public void OpenRead ()
549 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
550 if (!File.Exists (path))
551 File.Create (path).Close ();
552 FileStream stream = null;
555 stream = File.OpenRead (path);
557 Assertion.AssertEquals ("test#01", true, stream.CanRead);
558 Assertion.AssertEquals ("test#02", true, stream.CanSeek);
559 Assertion.AssertEquals ("test#03", false, stream.CanWrite);
569 public void OpenWrite ()
571 string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
572 if (!File.Exists (path))
573 File.Create (path).Close ();
574 FileStream stream = null;
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);
590 public void TestGetCreationTime ()
592 string path = TempFolder + Path.DirectorySeparatorChar + "baz";
596 File.Create (path).Close();
597 DateTime time = File.GetCreationTime (path);
598 Assert ("GetCreationTime incorrect", (DateTime.Now - time).TotalSeconds < 10);
605 [ExpectedException(typeof(IOException))]
606 public void TestGetCreationTimeException ()
608 // Test nonexistent files
609 string path2 = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
611 // should throw an exception
612 File.GetCreationTime (path2);
617 // Setting the creation time on Unix is not possible
618 [Test][Category("NotWorking")]
619 public void CreationTime ()
621 string path = TempFolder + Path.DirectorySeparatorChar + "creationTime";
622 if (File.Exists (path))
624 FileStream stream = null;
627 stream = File.Create (path);
630 File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
631 DateTime time = File.GetCreationTime (path);
632 Assertion.AssertEquals ("test#01", 2002, time.Year);
633 Assertion.AssertEquals ("test#02", 4, time.Month);
634 Assertion.AssertEquals ("test#03", 6, time.Day);
635 Assertion.AssertEquals ("test#04", 4, time.Hour);
636 Assertion.AssertEquals ("test#05", 4, time.Second);
638 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
639 Assertion.AssertEquals ("test#06", 2002, time.Year);
640 Assertion.AssertEquals ("test#07", 4, time.Month);
641 Assertion.AssertEquals ("test#08", 6, time.Day);
642 Assertion.AssertEquals ("test#09", 4, time.Hour);
643 Assertion.AssertEquals ("test#10", 4, time.Second);
645 File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
646 time = File.GetCreationTimeUtc (path);
647 Assertion.AssertEquals ("test#11", 2002, time.Year);
648 Assertion.AssertEquals ("test#12", 4, time.Month);
649 Assertion.AssertEquals ("test#13", 6, time.Day);
650 Assertion.AssertEquals ("test#14", 4, time.Hour);
651 Assertion.AssertEquals ("test#15", 4, time.Second);
653 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
654 Assertion.AssertEquals ("test#16", 2002, time.Year);
655 Assertion.AssertEquals ("test#17", 4, time.Month);
656 Assertion.AssertEquals ("test#18", 6, time.Day);
657 Assertion.AssertEquals ("test#19", 4, time.Hour);
658 Assertion.AssertEquals ("test#20", 4, time.Second);
667 public void LastAccessTime ()
669 string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";
670 if (File.Exists (path))
672 FileStream stream = null;
674 stream = File.Create (path);
677 File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
678 DateTime time = File.GetLastAccessTime (path);
679 Assertion.AssertEquals ("test#01", 2002, time.Year);
680 Assertion.AssertEquals ("test#02", 4, time.Month);
681 Assertion.AssertEquals ("test#03", 6, time.Day);
682 Assertion.AssertEquals ("test#04", 4, time.Hour);
683 Assertion.AssertEquals ("test#05", 4, time.Second);
685 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
686 Assertion.AssertEquals ("test#06", 2002, time.Year);
687 Assertion.AssertEquals ("test#07", 4, time.Month);
688 Assertion.AssertEquals ("test#08", 6, time.Day);
689 Assertion.AssertEquals ("test#09", 4, time.Hour);
690 Assertion.AssertEquals ("test#10", 4, time.Second);
692 File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
693 time = File.GetLastAccessTimeUtc (path);
694 Assertion.AssertEquals ("test#11", 2002, time.Year);
695 Assertion.AssertEquals ("test#12", 4, time.Month);
696 Assertion.AssertEquals ("test#13", 6, time.Day);
697 Assertion.AssertEquals ("test#14", 4, time.Hour);
698 Assertion.AssertEquals ("test#15", 4, time.Second);
700 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
701 Assertion.AssertEquals ("test#16", 2002, time.Year);
702 Assertion.AssertEquals ("test#17", 4, time.Month);
703 Assertion.AssertEquals ("test#18", 6, time.Day);
704 Assertion.AssertEquals ("test#19", 4, time.Hour);
705 Assertion.AssertEquals ("test#20", 4, time.Second);
714 public void LastWriteTime ()
716 string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";
717 if (File.Exists (path))
719 FileStream stream = null;
721 stream = File.Create (path);
724 File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
725 DateTime time = File.GetLastWriteTime (path);
726 Assertion.AssertEquals ("test#01", 2002, time.Year);
727 Assertion.AssertEquals ("test#02", 4, time.Month);
728 Assertion.AssertEquals ("test#03", 6, time.Day);
729 Assertion.AssertEquals ("test#04", 4, time.Hour);
730 Assertion.AssertEquals ("test#05", 4, time.Second);
732 time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
733 Assertion.AssertEquals ("test#06", 2002, time.Year);
734 Assertion.AssertEquals ("test#07", 4, time.Month);
735 Assertion.AssertEquals ("test#08", 6, time.Day);
736 Assertion.AssertEquals ("test#09", 4, time.Hour);
737 Assertion.AssertEquals ("test#10", 4, time.Second);
739 File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
740 time = File.GetLastWriteTimeUtc (path);
741 Assertion.AssertEquals ("test#11", 2002, time.Year);
742 Assertion.AssertEquals ("test#12", 4, time.Month);
743 Assertion.AssertEquals ("test#13", 6, time.Day);
744 Assertion.AssertEquals ("test#14", 4, time.Hour);
745 Assertion.AssertEquals ("test#15", 4, time.Second);
747 time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
748 Assertion.AssertEquals ("test#16", 2002, time.Year);
749 Assertion.AssertEquals ("test#17", 4, time.Month);
750 Assertion.AssertEquals ("test#18", 6, time.Day);
751 Assertion.AssertEquals ("test#19", 4, time.Hour);
752 Assertion.AssertEquals ("test#20", 4, time.Second);
761 [ExpectedException(typeof(ArgumentNullException))]
762 public void GetCreationTimeException1 ()
764 File.GetCreationTime (null as string);
768 [ExpectedException(typeof(ArgumentException))]
769 public void GetCreationTimeException2 ()
771 File.GetCreationTime ("");
775 [ExpectedException(typeof(IOException))]
776 public void GetCreationTimeException3 ()
778 string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
780 File.GetCreationTime (path);
784 [ExpectedException(typeof(ArgumentException))]
785 public void GetCreationTimeException4 ()
787 File.GetCreationTime (" ");
791 [ExpectedException(typeof(ArgumentException))]
792 public void GetCreationTimeException5 ()
794 File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
798 [ExpectedException(typeof(ArgumentNullException))]
799 public void GetCreationTimeUtcException1 ()
801 File.GetCreationTimeUtc (null as string);
805 [ExpectedException(typeof(ArgumentException))]
806 public void GetCreationTimeUtcException2 ()
808 File.GetCreationTimeUtc ("");
812 [ExpectedException(typeof(IOException))]
813 public void GetCreationTimeUtcException3 ()
815 string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
817 File.GetCreationTimeUtc (path);
821 [ExpectedException(typeof(ArgumentException))]
822 public void GetCreationTimeUtcException4 ()
824 File.GetCreationTimeUtc (" ");
828 [ExpectedException(typeof(ArgumentException))]
829 public void GetCreationTimeUtcException5 ()
831 File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
835 [ExpectedException(typeof(ArgumentNullException))]
836 public void GetLastAccessTimeException1 ()
838 File.GetLastAccessTime (null as string);
842 [ExpectedException(typeof(ArgumentException))]
843 public void GetLastAccessTimeException2 ()
845 File.GetLastAccessTime ("");
849 [ExpectedException(typeof(IOException))]
850 public void GetLastAccessTimeException3 ()
852 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
854 File.GetLastAccessTime (path);
858 [ExpectedException(typeof(ArgumentException))]
859 public void GetLastAccessTimeException4 ()
861 File.GetLastAccessTime (" ");
865 [ExpectedException(typeof(ArgumentException))]
866 public void GetLastAccessTimeException5 ()
868 File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
872 [ExpectedException(typeof(ArgumentNullException))]
873 public void GetLastAccessTimeUtcException1 ()
875 File.GetLastAccessTimeUtc (null as string);
879 [ExpectedException(typeof(ArgumentException))]
880 public void GetLastAccessTimeUtcException2 ()
882 File.GetLastAccessTimeUtc ("");
886 [ExpectedException(typeof(IOException))]
887 public void GetLastAccessTimeUtcException3 ()
889 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
891 File.GetLastAccessTimeUtc (path);
895 [ExpectedException(typeof(ArgumentException))]
896 public void GetLastAccessTimeUtcException4 ()
898 File.GetLastAccessTimeUtc (" ");
902 [ExpectedException(typeof(ArgumentException))]
903 public void GetLastAccessTimeUtcException5 ()
905 File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
909 [ExpectedException(typeof(ArgumentNullException))]
910 public void GetLastWriteTimeException1 ()
912 File.GetLastWriteTime (null as string);
916 [ExpectedException(typeof(ArgumentException))]
917 public void GetLastWriteTimeException2 ()
919 File.GetLastWriteTime ("");
923 [ExpectedException(typeof(IOException))]
924 public void GetLastWriteTimeException3 ()
926 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
928 File.GetLastWriteTime (path);
932 [ExpectedException(typeof(ArgumentException))]
933 public void GetLastWriteTimeException4 ()
935 File.GetLastWriteTime (" ");
939 [ExpectedException(typeof(ArgumentException))]
940 public void GetLastWriteTimeException5 ()
942 File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
946 [ExpectedException(typeof(ArgumentNullException))]
947 public void GetLastWriteTimeUtcException1 ()
949 File.GetLastWriteTimeUtc (null as string);
953 [ExpectedException(typeof(ArgumentException))]
954 public void GetLastWriteTimeUtcException2 ()
956 File.GetLastAccessTimeUtc ("");
960 [ExpectedException(typeof(IOException))]
961 public void GetLastWriteTimeUtcException3 ()
963 string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
965 File.GetLastAccessTimeUtc (path);
969 [ExpectedException(typeof(ArgumentException))]
970 public void GetLastWriteTimeUtcException4 ()
972 File.GetLastAccessTimeUtc (" ");
976 [ExpectedException(typeof(ArgumentException))]
977 public void GetLastWriteTimeUtcException5 ()
979 File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
983 [ExpectedException(typeof(IOException))]
984 [Category("ValueAdd")]
986 // This is category ValueAdd, since in Unix the semantics allow for
987 // a file to be deleted while a handle to it remains.
989 public void FileStreamCloseException ()
991 string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamCloseException";
993 FileStream stream = null;
995 stream = File.Create (path);
1005 public void FileStreamClose ()
1007 string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
1008 FileStream stream = null;
1010 stream = File.Create (path);
1020 // SetCreationTime and SetCreationTimeUtc exceptions
1023 [ExpectedException(typeof (ArgumentNullException))]
1024 public void SetCreationTimeArgumentNullException1 ()
1026 File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1030 [ExpectedException(typeof (ArgumentException))]
1031 public void SetCreationTimeArgumenException1 ()
1033 File.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1037 [ExpectedException(typeof (ArgumentException))]
1038 public void SetCreationTimeArgumenException2 ()
1040 File.SetCreationTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1044 [ExpectedException(typeof (ArgumentException))]
1045 [Category("ValueAdd")]
1046 // On Unix there are no invalid path chars.
1047 public void SetCreationTimeArgumenException3 ()
1050 File.SetCreationTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1054 [ExpectedException(typeof (FileNotFoundException))]
1055 public void SetCreationTimeFileNotFoundException1 ()
1057 string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
1060 File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1064 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1065 // public void SetCreationTimeArgumentOutOfRangeException1 ()
1067 // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
1068 // FileStream stream = null;
1069 // DeleteFile (path);
1071 // stream = File.Create (path);
1073 // File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1075 // if (stream != null)
1077 // DeleteFile (path);
1082 [ExpectedException(typeof (IOException))]
1083 public void SetCreationTimeIOException1 ()
1085 string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
1087 FileStream stream = null;
1089 stream = File.Create (path);
1090 File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1099 [ExpectedException(typeof (ArgumentNullException))]
1100 public void SetCreationTimeUtcArgumentNullException1 ()
1102 File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1106 [ExpectedException(typeof (ArgumentException))]
1107 public void SetCreationTimeUtcArgumenException1 ()
1109 File.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1113 [ExpectedException(typeof (ArgumentException))]
1114 public void SetCreationTimeUtcArgumenException2 ()
1116 File.SetCreationTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1120 [ExpectedException(typeof (ArgumentException))]
1121 [Category("ValueAdd")]
1122 // On Unix there are no invalid path chars.
1123 public void SetCreationTimeUtcArgumenException3 ()
1125 File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1129 [ExpectedException(typeof (FileNotFoundException))]
1130 public void SetCreationTimeUtcFileNotFoundException1 ()
1132 string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
1135 File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1139 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1140 // public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
1142 // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
1143 // DeleteFile (path);
1144 // FileStream stream = null;
1146 // stream = File.Create (path);
1148 // File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1150 // if (stream != null)
1152 // DeleteFile (path);
1157 [ExpectedException(typeof (IOException))]
1158 public void SetCreationTimeUtcIOException1 ()
1160 string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
1162 FileStream stream = null;
1164 stream = File.Create (path);
1165 File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1173 // SetLastAccessTime and SetLastAccessTimeUtc exceptions
1176 [ExpectedException(typeof (ArgumentNullException))]
1177 public void SetLastAccessTimeArgumentNullException1 ()
1179 File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1183 [ExpectedException(typeof (ArgumentException))]
1184 public void SetLastAccessTimeArgumenException1 ()
1186 File.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1190 [ExpectedException(typeof (ArgumentException))]
1191 public void SetLastAccessTimeArgumenException2 ()
1193 File.SetLastAccessTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1197 [ExpectedException(typeof (ArgumentException))]
1198 [Category("ValueAdd")]
1199 // On Unix there are no invalid path chars.
1200 public void SetLastAccessTimeArgumenException3 ()
1202 File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1206 [ExpectedException(typeof (FileNotFoundException))]
1207 public void SetLastAccessTimeFileNotFoundException1 ()
1209 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
1212 File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1216 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1217 // public void SetLastAccessTimeArgumentOutOfRangeException1 ()
1219 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
1220 // DeleteFile (path);
1221 // FileStream stream = null;
1223 // stream = File.Create (path);
1225 // File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1227 // if (stream != null)
1229 // DeleteFile (path);
1234 [ExpectedException(typeof (IOException))]
1235 public void SetLastAccessTimeIOException1 ()
1237 string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
1239 FileStream stream = null;
1241 stream = File.Create (path);
1242 File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1251 [ExpectedException(typeof (ArgumentNullException))]
1252 public void SetLastAccessTimeUtcArgumentNullException1 ()
1254 File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1258 [ExpectedException(typeof (ArgumentException))]
1259 public void SetCLastAccessTimeUtcArgumenException1 ()
1261 File.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1265 [ExpectedException(typeof (ArgumentException))]
1266 public void SetLastAccessTimeUtcArgumenException2 ()
1268 File.SetLastAccessTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1272 [ExpectedException(typeof (ArgumentException))]
1273 [Category("ValueAdd")]
1274 // On Unix there are no invalid path chars.
1275 public void SetLastAccessTimeUtcArgumenException3 ()
1277 File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1281 [ExpectedException(typeof (FileNotFoundException))]
1282 public void SetLastAccessTimeUtcFileNotFoundException1 ()
1284 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
1287 File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1291 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1292 // public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
1294 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
1295 // DeleteFile (path);
1296 // FileStream stream = null;
1298 // stream = File.Create (path);
1300 // File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1302 // if (stream != null)
1304 // DeleteFile (path);
1309 [ExpectedException(typeof (IOException))]
1310 public void SetLastAccessTimeUtcIOException1 ()
1312 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
1314 FileStream stream = null;
1316 stream = File.Create (path);
1317 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1325 // SetLastWriteTime and SetLastWriteTimeUtc exceptions
1328 [ExpectedException(typeof (ArgumentNullException))]
1329 public void SetLastWriteTimeArgumentNullException1 ()
1331 File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1335 [ExpectedException(typeof (ArgumentException))]
1336 public void SetLastWriteTimeArgumenException1 ()
1338 File.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
1342 [ExpectedException(typeof (ArgumentException))]
1343 public void SetLastWriteTimeArgumenException2 ()
1345 File.SetLastWriteTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1349 [ExpectedException(typeof (ArgumentException))]
1350 [Category("ValueAdd")]
1351 // On Unix there are no invalid path chars.
1352 public void SetLastWriteTimeArgumenException3 ()
1354 File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1358 [ExpectedException(typeof (FileNotFoundException))]
1359 public void SetLastWriteTimeFileNotFoundException1 ()
1361 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
1364 File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
1368 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1369 // public void SetLastWriteTimeArgumentOutOfRangeException1 ()
1371 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
1372 // DeleteFile (path);
1373 // FileStream stream = null;
1375 // stream = File.Create (path);
1377 // File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1379 // if (stream != null)
1381 // DeleteFile (path);
1386 [ExpectedException(typeof (IOException))]
1387 public void SetLastWriteTimeIOException1 ()
1389 string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
1391 FileStream stream = null;
1393 stream = File.Create (path);
1394 File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
1403 [ExpectedException(typeof (ArgumentNullException))]
1404 public void SetLastWriteTimeUtcArgumentNullException1 ()
1406 File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
1410 [ExpectedException(typeof (ArgumentException))]
1411 public void SetCLastWriteTimeUtcArgumenException1 ()
1413 File.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
1417 [ExpectedException(typeof (ArgumentException))]
1418 public void SetLastWriteTimeUtcArgumenException2 ()
1420 File.SetLastWriteTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
1424 [ExpectedException(typeof (ArgumentException))]
1425 [Category("ValueAdd")]
1426 // On Unix there are no invalid path chars.
1427 public void SetLastWriteTimeUtcArgumenException3 ()
1429 File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
1433 [ExpectedException(typeof (FileNotFoundException))]
1434 public void SetLastWriteTimeUtcFileNotFoundException1 ()
1436 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
1439 File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
1443 // [ExpectedException(typeof (ArgumentOutOfRangeException))]
1444 // public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
1446 // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
1447 // DeleteFile (path);
1448 // FileStream stream = null;
1450 // stream = File.Create (path);
1452 // File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1454 // if (stream != null)
1456 // DeleteFile (path);
1461 [ExpectedException(typeof (IOException))]
1462 public void SetLastWriteTimeUtcIOException1 ()
1464 string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
1466 FileStream stream = null;
1468 stream = File.Create (path);
1469 File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
1477 private void DeleteFile (string path)
1479 if (File.Exists (path))