| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747 |
- //
- // FileTest.cs: Test cases for System.IO.File
- //
- // Author:
- // Duncan Mak ([email protected])
- // Ville Palo ([email protected])
- //
- // (C) 2002 Ximian, Inc. http://www.ximian.com
- //
- // TODO: Find out why ArgumentOutOfRangeExceptions does not manage to close streams properly
- //
- using NUnit.Framework;
- using System;
- using System.IO;
- using System.Globalization;
- using System.Threading;
- namespace MonoTests.System.IO
- {
- [TestFixture]
- public class FileTest : Assertion
- {
- static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
- [SetUp]
- public void SetUp ()
- {
- if (Directory.Exists (TempFolder))
- Directory.Delete (TempFolder, true);
- Directory.CreateDirectory (TempFolder);
-
- Thread.CurrentThread.CurrentCulture = new CultureInfo ("EN-us");
- }
- [TearDown]
- public void TearDown ()
- {
- if (Directory.Exists (TempFolder))
- Directory.Delete (TempFolder, true);
- }
- [Test]
- public void TestExists ()
- {
- int i = 0;
- FileStream s = null;
- string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- try {
- Assert ("null filename should not exist", !File.Exists (null));
- i++;
- Assert ("empty filename should not exist", !File.Exists (""));
- i++;
- Assert ("whitespace filename should not exist", !File.Exists (" \t\t \t \n\t\n \n"));
- i++;
- DeleteFile (path);
- s = File.Create (path);
- s.Close ();
- Assert ("File " + path + " should exists", File.Exists (path));
- i++;
- Assert ("File resources" + Path.DirectorySeparatorChar + "doesnotexist should not exist", !File.Exists (TempFolder + Path.DirectorySeparatorChar + "doesnotexist"));
- } catch (Exception e) {
- Fail ("Unexpected exception at i = " + i + ". e=" + e);
- } finally {
- if (s != null)
- s.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- public void Exists_InvalidFileName ()
- {
- Assert ("><|", !File.Exists ("><|"));
- Assert ("?*", !File.Exists ("?*"));
- }
- [Test]
- public void Exists_InvalidDirectory ()
- {
- Assert ("InvalidDirectory", !File.Exists (Path.Combine ("does not exist", "file.txt")));
- }
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- public void CtorArgumentNullException1 ()
- {
- FileStream stream = File.Create (null);
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void CtorArgumentException1 ()
- {
- FileStream stream = File.Create ("");
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void CtorArgumentException2 ()
- {
- FileStream stream = File.Create (" ");
- }
- [Test]
- [ExpectedException(typeof (DirectoryNotFoundException))]
- public void CtorDirectoryNotFoundException ()
- {
- FileStream stream = null;
- string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
-
- try {
- stream = File.Create (path);
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- public void TestCreate ()
- {
- FileStream stream = null;
- string path = "";
- /* positive test: create resources/foo */
- try {
- path = TempFolder + Path.DirectorySeparatorChar + "foo";
- stream = File.Create (path);
- Assert ("File should exist", File.Exists (path));
- stream.Close ();
- } catch (Exception e) {
- Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
-
- path = "";
- stream = null;
- /* positive test: repeat test above again to test for overwriting file */
- try {
- path = TempFolder + Path.DirectorySeparatorChar + "foo";
- stream = File.Create (path);
- Assert ("File should exist", File.Exists (path));
- stream.Close ();
- } catch (Exception e) {
- Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CopyArgumentNullException1 ()
- {
- File.Copy (null, "b");
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CopyArgumentNullException2 ()
- {
- File.Copy ("a", null);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CopyArgumentException1 ()
- {
- File.Copy ("", "b");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CopyArgumentException2 ()
- {
- File.Copy ("a", "");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CopyArgumentException3 ()
- {
- File.Copy (" ", "b");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CopyArgumentException4 ()
- {
- File.Copy ("a", " ");
- }
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void CopyFileNotFoundException ()
- {
- File.Copy ("doesnotexist", "b");
- }
- [ExpectedException(typeof(IOException))]
- public void CopyIOException ()
- {
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
- try {
- File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
- File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar");
- File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar");
- } finally {
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
- }
- }
- [Test]
- public void TestCopy ()
- {
- string path1 = TempFolder + Path.DirectorySeparatorChar + "bar";
- string path2 = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- /* positive test: copy resources/AFile.txt to resources/bar */
- try {
- try {
- DeleteFile (path1);
- DeleteFile (path2);
- File.Create (path2).Close ();
- File.Copy (path2, path1);
- Assert ("File AFile.txt should still exist", File.Exists (path2));
- Assert ("File bar should exist after File.Copy", File.Exists (path1));
- } catch (Exception e) {
- Fail ("#1 File.Copy('resources/AFile.txt', 'resources/bar') unexpected exception caught: e=" + e.ToString());
- }
- /* positive test: copy resources/AFile.txt to resources/bar, overwrite */
- try {
- Assert ("File bar should exist before File.Copy", File.Exists (path1));
- File.Copy (path2, path1, true);
- Assert ("File AFile.txt should still exist", File.Exists (path2));
- Assert ("File bar should exist after File.Copy", File.Exists (path1));
- } catch (Exception e) {
- Fail ("File.Copy('resources/AFile.txt', 'resources/bar', true) unexpected exception caught: e=" + e.ToString());
- }
- }finally {
- DeleteFile (path1);
- DeleteFile (path2);
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DeleteArgumentNullException ()
- {
- File.Delete (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DeleteArgumentException1 ()
- {
- File.Delete ("");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DeleteArgumentException2 ()
- {
- File.Delete (" ");
- }
- [Test]
- [ExpectedException (typeof (DirectoryNotFoundException))]
- public void DeleteDirectoryNotFoundException ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
- if (Directory.Exists (path))
- Directory.Delete (path, true);
- File.Delete (path);
- }
- [Test]
- public void TestDelete ()
- {
- string foopath = TempFolder + Path.DirectorySeparatorChar + "foo";
- DeleteFile (foopath);
- try {
- File.Create (foopath).Close ();
- try {
- File.Delete (foopath);
- } catch (Exception e) {
- Fail ("Unable to delete " + foopath + " e=" + e.ToString());
- }
- Assert ("File " + foopath + " should not exist after File.Delete", !File.Exists (foopath));
- } finally {
- DeleteFile (foopath);
- }
- }
- [Test]
- [ExpectedException(typeof (IOException))]
- [Category("NotWorking")]
- public void DeleteOpenStreamException ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "DeleteOpenStreamException";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- File.Delete (path);
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
-
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- public void MoveException1 ()
- {
- File.Move (null, "b");
- }
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- public void MoveException2 ()
- {
- File.Move ("a", null);
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void MoveException3 ()
- {
- File.Move ("", "b");
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void MoveException4 ()
- {
- File.Move ("a", "");
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void MoveException5 ()
- {
- File.Move (" ", "b");
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void MoveException6 ()
- {
- File.Move ("a", " ");
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- public void MoveException7 ()
- {
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist");
- File.Move (TempFolder + Path.DirectorySeparatorChar + "doesnotexist", "b");
- }
- [Test]
- [ExpectedException(typeof (DirectoryNotFoundException))]
- public void MoveException8 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "foo";
- DeleteFile (path);
- try {
- File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
- File.Copy(TempFolder + Path.DirectorySeparatorChar + "AFile.txt", path, true);
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
- File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
- } finally {
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof (IOException))]
- public void MoveException9 ()
- {
- File.Create (TempFolder + Path.DirectorySeparatorChar + "foo").Close ();
- try {
- File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder);
- } finally {
- DeleteFile (TempFolder + Path.DirectorySeparatorChar + "foo");
- }
- }
- [Test]
- public void TestMove ()
- {
- string bar = TempFolder + Path.DirectorySeparatorChar + "bar";
- string baz = TempFolder + Path.DirectorySeparatorChar + "baz";
- if (!File.Exists (bar)) {
- FileStream f = File.Create(bar);
- f.Close();
- }
-
- Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should exist", File.Exists (bar));
- File.Move (bar, baz);
- Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should not exist", !File.Exists (bar));
- Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "baz should exist", File.Exists (baz));
- // Test moving of directories
- string dir = Path.Combine (TempFolder, "dir");
- string dir2 = Path.Combine (TempFolder, "dir2");
- string dir_foo = Path.Combine (dir, "foo");
- string dir2_foo = Path.Combine (dir2, "foo");
- if (Directory.Exists (dir))
- Directory.Delete (dir, true);
-
- Directory.CreateDirectory (dir);
- Directory.CreateDirectory (dir2);
- File.Create (dir_foo).Close ();
- File.Move (dir_foo, dir2_foo);
- Assert (File.Exists (dir2_foo));
-
- Directory.Delete (dir, true);
- Directory.Delete (dir2, true);
- DeleteFile (dir_foo);
- DeleteFile (dir2_foo);
- }
- [Test]
- public void TestOpen ()
- {
- string path = "";
- FileStream stream = null;
- try {
- path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- if (!File.Exists (path))
- stream = File.Create (path);
- stream.Close ();
- stream = File.Open (path, FileMode.Open);
- stream.Close ();
- } catch (Exception e) {
- Fail ("Unable to open " + TempFolder + Path.DirectorySeparatorChar + "AFile.txt: e=" + e.ToString());
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
-
- path = "";
- stream = null;
- /* Exception tests */
- try {
- path = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
- stream = File.Open (path, FileMode.Open);
- Fail ("File 'filedoesnotexist' should not exist");
- } catch (FileNotFoundException) {
- // do nothing, this is what we expect
- } catch (Exception e) {
- Fail ("Unexpect exception caught: e=" + e.ToString());
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- public void Open ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- if (!File.Exists (path))
- File.Create (path).Close ();
- FileStream stream = null;
- try {
-
- stream = File.Open (path, FileMode.Open);
-
- Assertion.AssertEquals ("test#01", true, stream.CanRead);
- Assertion.AssertEquals ("test#02", true, stream.CanSeek);
- Assertion.AssertEquals ("test#03", true, stream.CanWrite);
- stream.Close ();
-
- stream = File.Open (path, FileMode.Open, FileAccess.Write);
- Assertion.AssertEquals ("test#04", false, stream.CanRead);
- Assertion.AssertEquals ("test#05", true, stream.CanSeek);
- Assertion.AssertEquals ("test#06", true, stream.CanWrite);
- stream.Close ();
-
- stream = File.Open (path, FileMode.Open, FileAccess.Read);
- Assertion.AssertEquals ("test#04", true, stream.CanRead);
- Assertion.AssertEquals ("test#05", true, stream.CanSeek);
- Assertion.AssertEquals ("test#06", false, stream.CanWrite);
- stream.Close ();
-
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
-
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void OpenException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- FileStream stream = null;
- // CreateNew + Read throws an exceptoin
- try {
- stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.CreateNew, FileAccess.Read);
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void OpenException2 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- FileStream s = null;
- // Append + Read throws an exceptoin
- if (!File.Exists (path))
- File.Create (path).Close ();
- try {
- s = File.Open (path, FileMode.Append, FileAccess.Read);
- } finally {
- if (s != null)
- s.Close ();
- DeleteFile (path);
- }
- }
-
- [Test]
- public void OpenRead ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- if (!File.Exists (path))
- File.Create (path).Close ();
- FileStream stream = null;
-
- try {
- stream = File.OpenRead (path);
-
- Assertion.AssertEquals ("test#01", true, stream.CanRead);
- Assertion.AssertEquals ("test#02", true, stream.CanSeek);
- Assertion.AssertEquals ("test#03", false, stream.CanWrite);
-
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- public void OpenWrite ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
- if (!File.Exists (path))
- File.Create (path).Close ();
- FileStream stream = null;
-
- try {
- stream = File.OpenWrite (path);
- Assertion.AssertEquals ("test#01", false, stream.CanRead);
- Assertion.AssertEquals ("test#02", true, stream.CanSeek);
- Assertion.AssertEquals ("test#03", true, stream.CanWrite);
- stream.Close ();
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void TestGetCreationTime ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "baz";
- DeleteFile (path);
-
- try {
- File.Create (path).Close();
- DateTime time = File.GetCreationTime (path);
- Assert ("GetCreationTime incorrect", (DateTime.Now - time).TotalSeconds < 10);
- } finally {
- DeleteFile (path);
- }
- }
- // Setting the creation time on Unix is not possible
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void CreationTime ()
- {
- int platform = (int) Environment.OSVersion.Platform;
- if ((platform == 4) || (platform == 128))
- return;
- string path = Path.GetTempFileName ();
-
- try {
- File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
- DateTime time = File.GetCreationTime (path);
- Assertion.AssertEquals ("test#01", 2002, time.Year);
- Assertion.AssertEquals ("test#02", 4, time.Month);
- Assertion.AssertEquals ("test#03", 6, time.Day);
- Assertion.AssertEquals ("test#04", 4, time.Hour);
- Assertion.AssertEquals ("test#05", 4, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
- Assertion.AssertEquals ("test#06", 2002, time.Year);
- Assertion.AssertEquals ("test#07", 4, time.Month);
- Assertion.AssertEquals ("test#08", 6, time.Day);
- Assertion.AssertEquals ("test#09", 4, time.Hour);
- Assertion.AssertEquals ("test#10", 4, time.Second);
- File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
- time = File.GetCreationTimeUtc (path);
- Assertion.AssertEquals ("test#11", 2002, time.Year);
- Assertion.AssertEquals ("test#12", 4, time.Month);
- Assertion.AssertEquals ("test#13", 6, time.Day);
- Assertion.AssertEquals ("test#14", 4, time.Hour);
- Assertion.AssertEquals ("test#15", 4, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
- Assertion.AssertEquals ("test#16", 2002, time.Year);
- Assertion.AssertEquals ("test#17", 4, time.Month);
- Assertion.AssertEquals ("test#18", 6, time.Day);
- Assertion.AssertEquals ("test#19", 4, time.Hour);
- Assertion.AssertEquals ("test#20", 4, time.Second);
- } finally {
- DeleteFile (path);
- }
- }
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void LastAccessTime ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";
- if (File.Exists (path))
- File.Delete (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- stream.Close ();
-
- File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
- DateTime time = File.GetLastAccessTime (path);
- Assertion.AssertEquals ("test#01", 2002, time.Year);
- Assertion.AssertEquals ("test#02", 4, time.Month);
- Assertion.AssertEquals ("test#03", 6, time.Day);
- Assertion.AssertEquals ("test#04", 4, time.Hour);
- Assertion.AssertEquals ("test#05", 4, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
- Assertion.AssertEquals ("test#06", 2002, time.Year);
- Assertion.AssertEquals ("test#07", 4, time.Month);
- Assertion.AssertEquals ("test#08", 6, time.Day);
- Assertion.AssertEquals ("test#09", 4, time.Hour);
- Assertion.AssertEquals ("test#10", 4, time.Second);
-
- File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
- time = File.GetLastAccessTimeUtc (path);
- Assertion.AssertEquals ("test#11", 2002, time.Year);
- Assertion.AssertEquals ("test#12", 4, time.Month);
- Assertion.AssertEquals ("test#13", 6, time.Day);
- Assertion.AssertEquals ("test#14", 4, time.Hour);
- Assertion.AssertEquals ("test#15", 4, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
- Assertion.AssertEquals ("test#16", 2002, time.Year);
- Assertion.AssertEquals ("test#17", 4, time.Month);
- Assertion.AssertEquals ("test#18", 6, time.Day);
- Assertion.AssertEquals ("test#19", 4, time.Hour);
- Assertion.AssertEquals ("test#20", 4, time.Second);
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
-
- [Test]
- public void LastWriteTime ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";
- if (File.Exists (path))
- File.Delete (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- stream.Close ();
-
- File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
- DateTime time = File.GetLastWriteTime (path);
- Assertion.AssertEquals ("test#01", 2002, time.Year);
- Assertion.AssertEquals ("test#02", 4, time.Month);
- Assertion.AssertEquals ("test#03", 6, time.Day);
- Assertion.AssertEquals ("test#04", 4, time.Hour);
- Assertion.AssertEquals ("test#05", 4, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
- Assertion.AssertEquals ("test#06", 2002, time.Year);
- Assertion.AssertEquals ("test#07", 4, time.Month);
- Assertion.AssertEquals ("test#08", 6, time.Day);
- Assertion.AssertEquals ("test#09", 4, time.Hour);
- Assertion.AssertEquals ("test#10", 4, time.Second);
-
- File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
- time = File.GetLastWriteTimeUtc (path);
- Assertion.AssertEquals ("test#11", 2002, time.Year);
- Assertion.AssertEquals ("test#12", 4, time.Month);
- Assertion.AssertEquals ("test#13", 6, time.Day);
- Assertion.AssertEquals ("test#14", 4, time.Hour);
- Assertion.AssertEquals ("test#15", 4, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
- Assertion.AssertEquals ("test#16", 2002, time.Year);
- Assertion.AssertEquals ("test#17", 4, time.Month);
- Assertion.AssertEquals ("test#18", 6, time.Day);
- Assertion.AssertEquals ("test#19", 4, time.Hour);
- Assertion.AssertEquals ("test#20", 4, time.Second);
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeException1 ()
- {
- File.GetCreationTime (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeException2 ()
- {
- File.GetCreationTime ("");
- }
-
- [Test]
- #if !NET_2_0
- [ExpectedException(typeof(IOException))]
- #endif
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTime_NonExistingPath ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
- DeleteFile (path);
- DateTime time = File.GetCreationTime (path);
- #if NET_2_0
- DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
- Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
- Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
- Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
- Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
- Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
- Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
- #endif
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeException4 ()
- {
- File.GetCreationTime (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeException5 ()
- {
- File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeUtcException1 ()
- {
- File.GetCreationTimeUtc (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeUtcException2 ()
- {
- File.GetCreationTimeUtc ("");
- }
-
- [Test]
- #if !NET_2_0
- [ExpectedException (typeof (IOException))]
- #endif
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeUtc_NonExistingPath ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
- DeleteFile (path);
- DateTime time = File.GetCreationTimeUtc (path);
- #if NET_2_0
- Assertion.AssertEquals ("#1", 1601, time.Year);
- Assertion.AssertEquals ("#2", 1, time.Month);
- Assertion.AssertEquals ("#3", 1, time.Day);
- Assertion.AssertEquals ("#4", 0, time.Hour);
- Assertion.AssertEquals ("#5", 0, time.Second);
- Assertion.AssertEquals ("#6", 0, time.Millisecond);
- #endif
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeUtcException4 ()
- {
- File.GetCreationTimeUtc (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetCreationTimeUtcException5 ()
- {
- File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeException1 ()
- {
- File.GetLastAccessTime (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeException2 ()
- {
- File.GetLastAccessTime ("");
- }
-
- [Test]
- #if !NET_2_0
- [ExpectedException (typeof (IOException))]
- #endif
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTime_NonExistingPath ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
- DeleteFile (path);
- DateTime time = File.GetLastAccessTime (path);
- #if NET_2_0
- DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
- Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
- Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
- Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
- Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
- Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
- Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
- #endif
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeException4 ()
- {
- File.GetLastAccessTime (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeException5 ()
- {
- File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeUtcException1 ()
- {
- File.GetLastAccessTimeUtc (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeUtcException2 ()
- {
- File.GetLastAccessTimeUtc ("");
- }
-
- [Test]
- #if !NET_2_0
- [ExpectedException (typeof (IOException))]
- #endif
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeUtc_NonExistingPath ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
- DeleteFile (path);
- DateTime time = File.GetLastAccessTimeUtc (path);
- #if NET_2_0
- Assertion.AssertEquals ("#1", 1601, time.Year);
- Assertion.AssertEquals ("#2", 1, time.Month);
- Assertion.AssertEquals ("#3", 1, time.Day);
- Assertion.AssertEquals ("#4", 0, time.Hour);
- Assertion.AssertEquals ("#5", 0, time.Second);
- Assertion.AssertEquals ("#6", 0, time.Millisecond);
- #endif
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeUtcException4 ()
- {
- File.GetLastAccessTimeUtc (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void GetLastAccessTimeUtcException5 ()
- {
- File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetLastWriteTimeException1 ()
- {
- File.GetLastWriteTime (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeException2 ()
- {
- File.GetLastWriteTime ("");
- }
-
- [Test]
- #if !NET_2_0
- [ExpectedException (typeof (IOException))]
- #endif
- public void GetLastWriteTime_NonExistingPath ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
- DeleteFile (path);
- DateTime time = File.GetLastWriteTime (path);
- #if NET_2_0
- DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
- Assertion.AssertEquals ("#1", expectedTime.Year, time.Year);
- Assertion.AssertEquals ("#2", expectedTime.Month, time.Month);
- Assertion.AssertEquals ("#3", expectedTime.Day, time.Day);
- Assertion.AssertEquals ("#4", expectedTime.Hour, time.Hour);
- Assertion.AssertEquals ("#5", expectedTime.Second, time.Second);
- Assertion.AssertEquals ("#6", expectedTime.Millisecond, time.Millisecond);
- #endif
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeException4 ()
- {
- File.GetLastWriteTime (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeException5 ()
- {
- File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetLastWriteTimeUtcException1 ()
- {
- File.GetLastWriteTimeUtc (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeUtcException2 ()
- {
- File.GetLastWriteTimeUtc ("");
- }
-
- [Test]
- #if !NET_2_0
- [ExpectedException (typeof (IOException))]
- #endif
- public void GetLastWriteTimeUtc_NonExistingPath ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
- DeleteFile (path);
- DateTime time = File.GetLastWriteTimeUtc (path);
- #if NET_2_0
- Assertion.AssertEquals ("#1", 1601, time.Year);
- Assertion.AssertEquals ("#2", 1, time.Month);
- Assertion.AssertEquals ("#3", 1, time.Day);
- Assertion.AssertEquals ("#4", 0, time.Hour);
- Assertion.AssertEquals ("#5", 0, time.Second);
- Assertion.AssertEquals ("#6", 0, time.Millisecond);
- #endif
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeUtcException4 ()
- {
- File.GetLastWriteTimeUtc (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeUtcException5 ()
- {
- File.GetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- public void FileStreamClose ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
- FileStream stream = null;
- try {
- stream = File.Create (path);
- stream.Close ();
- File.Delete (path);
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
-
- // SetCreationTime and SetCreationTimeUtc exceptions
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeArgumentNullException1 ()
- {
- File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeArgumenException1 ()
- {
- File.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeArgumenException2 ()
- {
- File.SetCreationTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- // On Unix there are no invalid path chars.
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeArgumenException3 ()
- {
- if (Path.InvalidPathChars.Length > 1) {
- bool pass = false;
- try {
- File.SetCreationTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
- } catch (ArgumentException) {
- pass = true;
- }
- Assertion.Assert ("#01", pass);
- }
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeFileNotFoundException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
- DeleteFile (path);
-
- File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- // [Test]
- // [ExpectedException(typeof (ArgumentOutOfRangeException))]
- // public void SetCreationTimeArgumentOutOfRangeException1 ()
- // {
- // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
- // FileStream stream = null;
- // DeleteFile (path);
- // try {
- // stream = File.Create (path);
- // stream.Close ();
- // File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
- // } finally {
- // if (stream != null)
- // stream.Close ();
- // DeleteFile (path);
- // }
- // }
- [Test]
- [ExpectedException(typeof (IOException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeIOException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeUtcArgumentNullException1 ()
- {
- File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeUtcArgumenException1 ()
- {
- File.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeUtcArgumenException2 ()
- {
- File.SetCreationTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- // On Unix there are no invalid path chars.
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeUtcArgumentException3 ()
- {
- if (Path.InvalidPathChars.Length > 1) {
- bool pass = false;
- try {
- File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
- } catch (ArgumentException) {
- pass = true;
- }
- Assertion.Assert ("#01", pass);
- }
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeUtcFileNotFoundException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
- DeleteFile (path);
-
- File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- // [Test]
- // [ExpectedException(typeof (ArgumentOutOfRangeException))]
- // public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
- // {
- // string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
- // DeleteFile (path);
- // FileStream stream = null;
- // try {
- // stream = File.Create (path);
- // stream.Close ();
- // File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
- // } finally {
- // if (stream != null)
- // stream.Close();
- // DeleteFile (path);
- // }
- // }
- [Test]
- [ExpectedException(typeof (IOException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCreationTimeUtcIOException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- // SetLastAccessTime and SetLastAccessTimeUtc exceptions
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeArgumentNullException1 ()
- {
- File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeArgumenException1 ()
- {
- File.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeArgumenException2 ()
- {
- File.SetLastAccessTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- // On Unix there are no invalid path chars.
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeArgumenException3 ()
- {
- if (Path.InvalidPathChars.Length > 1) {
- bool pass = false;
- try {
- File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
- } catch (ArgumentException) {
- pass = true;
- }
- Assertion.Assert ("#01", pass);
- }
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeFileNotFoundException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
- DeleteFile (path);
-
- File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- // [Test]
- // [ExpectedException(typeof (ArgumentOutOfRangeException))]
- // public void SetLastAccessTimeArgumentOutOfRangeException1 ()
- // {
- // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
- // DeleteFile (path);
- // FileStream stream = null;
- // try {
- // stream = File.Create (path);
- // stream.Close ();
- // File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
- // } finally {
- // if (stream != null)
- // stream.Close ();
- // DeleteFile (path);
- // }
- // }
- [Test]
- [ExpectedException(typeof (IOException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeIOException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeUtcArgumentNullException1 ()
- {
- File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetCLastAccessTimeUtcArgumenException1 ()
- {
- File.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeUtcArgumenException2 ()
- {
- File.SetLastAccessTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- // On Unix there are no invalid path chars.
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeUtcArgumenException3 ()
- {
- if (Path.InvalidPathChars.Length > 1) {
- bool pass = false;
- try {
- File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
- } catch (ArgumentException) {
- pass = true;
- }
- Assertion.Assert ("#01", pass);
- }
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeUtcFileNotFoundException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
- DeleteFile (path);
-
- File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- // [Test]
- // [ExpectedException(typeof (ArgumentOutOfRangeException))]
- // public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
- // {
- // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
- // DeleteFile (path);
- // FileStream stream = null;
- // try {
- // stream = File.Create (path);
- // stream.Close ();
- // File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
- // } finally {
- // if (stream != null)
- // stream.Close ();
- // DeleteFile (path);
- // }
- // }
- [Test]
- [ExpectedException(typeof (IOException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastAccessTimeUtcIOException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- // SetLastWriteTime and SetLastWriteTimeUtc exceptions
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- public void SetLastWriteTimeArgumentNullException1 ()
- {
- File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void SetLastWriteTimeArgumenException1 ()
- {
- File.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void SetLastWriteTimeArgumenException2 ()
- {
- File.SetLastWriteTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- // On Unix there are no invalid path chars.
- public void SetLastWriteTimeArgumenException3 ()
- {
- if (Path.InvalidPathChars.Length > 1) {
- bool pass = false;
- try {
- File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
- } catch (ArgumentException) {
- pass = true;
- }
- Assertion.Assert ("#01", pass);
- }
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- public void SetLastWriteTimeFileNotFoundException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
- DeleteFile (path);
-
- File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- // [Test]
- // [ExpectedException(typeof (ArgumentOutOfRangeException))]
- // public void SetLastWriteTimeArgumentOutOfRangeException1 ()
- // {
- // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
- // DeleteFile (path);
- // FileStream stream = null;
- // try {
- // stream = File.Create (path);
- // stream.Close ();
- // File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
- // } finally {
- // if (stream != null)
- // stream.Close ();
- // DeleteFile (path);
- // }
- // }
- [Test]
- [ExpectedException(typeof (IOException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastWriteTimeIOException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- public void SetLastWriteTimeUtcArgumentNullException1 ()
- {
- File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void SetCLastWriteTimeUtcArgumenException1 ()
- {
- File.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void SetLastWriteTimeUtcArgumenException2 ()
- {
- File.SetLastWriteTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
- }
- [Test]
- // On Unix there are no invalid path chars.
- public void SetLastWriteTimeUtcArgumenException3 ()
- {
- if (Path.InvalidPathChars.Length > 1) {
- bool pass = false;
- try {
- File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
- } catch (ArgumentException) {
- pass = true;
- }
- Assertion.Assert ("#01", pass);
- }
- }
- [Test]
- [ExpectedException(typeof (FileNotFoundException))]
- public void SetLastWriteTimeUtcFileNotFoundException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
- DeleteFile (path);
-
- File.SetLastWriteTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
- }
- // [Test]
- // [ExpectedException(typeof (ArgumentOutOfRangeException))]
- // public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
- // {
- // string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
- // DeleteFile (path);
- // FileStream stream = null;
- // try {
- // stream = File.Create (path);
- // stream.Close ();
- // File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
- // } finally {
- // if (stream != null)
- // stream.Close ();
- // DeleteFile (path);
- // }
- // }
- //
- [Test]
- [ExpectedException(typeof (IOException))]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void SetLastWriteTimeUtcIOException1 ()
- {
- string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
- DeleteFile (path);
- FileStream stream = null;
- try {
- stream = File.Create (path);
- File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
- } finally {
- if (stream != null)
- stream.Close ();
- DeleteFile (path);
- }
- }
-
- [Test]
- public void OpenAppend ()
- {
- string fn = Path.GetTempFileName ();
- using (FileStream s = File.Open (fn, FileMode.Append))
- ;
-
- DeleteFile (fn);
- }
- #if NET_2_0
- void TestRWAT (string s)
- {
- string f = Path.GetTempFileName ();
- try {
- File.WriteAllText (f, s);
- string r = File.ReadAllText (f);
- AssertEquals (r, s);
- } finally {
- DeleteFile (f);
- }
- }
- [Test]
- public void ReadWriteAllText ()
- {
- // The MSDN docs said something about
- // not including a final new line. it looks
- // like that was not true. I'm not sure what
- // that was talking about
- TestRWAT ("");
- TestRWAT ("\r");
- TestRWAT ("\n");
- TestRWAT ("\r\n");
- TestRWAT ("a\r");
- TestRWAT ("a\n");
- TestRWAT ("a\r\n");
- TestRWAT ("a\ra");
- TestRWAT ("a\na");
- TestRWAT ("a\r\na");
- TestRWAT ("a");
- TestRWAT ("\r\r");
- TestRWAT ("\n\n");
- TestRWAT ("\r\n\r\n");
- }
- #endif
- private void DeleteFile (string path)
- {
- if (File.Exists (path))
- File.Delete (path);
- }
- }
- }
|