| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185 |
- //
- // System.IO.Directory
- //
- // Authors:
- // Ville Palo ([email protected])
- //
- // (C) 2003 Ville Palo
- //
- // TODO: Find out why ArgumentOutOfRange tests does not release directories properly
- //
- using NUnit.Framework;
- using System.IO;
- using System.Text;
- using System;
- using System.Globalization;
- using System.Threading;
- namespace MonoTests.System.IO {
- [TestFixture]
- public class DirectoryTest : Assertion {
-
- string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
-
- [SetUp]
- public void SetUp ()
- {
- if (!Directory.Exists (TempFolder))
- 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 CreateDirectory ()
- {
- string path = TempFolder + "/DirectoryTest.Test.1";
- DeleteDirectory (path);
- try {
- DirectoryInfo info = Directory.CreateDirectory (path);
- AssertEquals ("test#01", true, info.Exists);
- AssertEquals ("test#02", ".1", info.Extension);
- AssertEquals ("test#03", true, info.FullName.EndsWith ("DirectoryTest.Test.1"));
- AssertEquals ("test#04", "DirectoryTest.Test.1", info.Name);
- } finally {
- DeleteDirectory (path);
- }
- }
-
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CreateDirectoryNotSupportedException ()
- {
- DeleteDirectory (":");
- DirectoryInfo info = Directory.CreateDirectory (":");
- DeleteDirectory (":");
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CreateDirectoryArgumentNullException ()
- {
- DirectoryInfo info = Directory.CreateDirectory (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CreateDirectoryArgumentException1 ()
- {
- DirectoryInfo info = Directory.CreateDirectory ("");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CreateDirectoryArgumentException2 ()
- {
- DirectoryInfo info = Directory.CreateDirectory (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void CreateDirectoryArgumentException3 ()
- {
- string path = TempFolder + "/DirectoryTest.Test";
- DeleteDirectory (path);
- try {
- path += Path.InvalidPathChars [0];
- path += ".2";
- DirectoryInfo info = Directory.CreateDirectory (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- public void Delete ()
- {
- string path = TempFolder + "/DirectoryTest.Test.Delete.1";
- DeleteDirectory (path);
- try {
- Directory.CreateDirectory (path);
- AssertEquals ("test#01", true, Directory.Exists (path));
-
- Directory.CreateDirectory (path + "/DirectoryTest.Test.Delete.1.2");
- AssertEquals ("test#02", true, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
-
- Directory.Delete (path + "/DirectoryTest.Test.Delete.1.2");
- AssertEquals ("test#03", false, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#04", true, Directory.Exists (path));
-
- Directory.Delete (path);
- AssertEquals ("test#05", false, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#06", false, Directory.Exists (path));
-
- Directory.CreateDirectory (path);
- Directory.CreateDirectory (path + "/DirectoryTest.Test.Delete.1.2");
- AssertEquals ("test#07", true, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#08", true, Directory.Exists (path));
-
- Directory.Delete (path, true);
- AssertEquals ("test#09", false, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#10", false, Directory.Exists (path));
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void DeleteArgumentException ()
- {
- Directory.Delete ("");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void DeleteArgumentException2 ()
- {
- Directory.Delete (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void DeleteArgumentException3 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.4";
- DeleteDirectory (path);
-
- path += Path.InvalidPathChars [0];
- Directory.Delete (path);
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void DeleteArgumentNullException ()
- {
- Directory.Delete (null as string);
- }
- [Test]
- [ExpectedException(typeof(DirectoryNotFoundException))]
- public void DeleteDirectoryNotFoundException ()
- {
- string path = TempFolder + "/DirectoryTest.Test.5";
- DeleteDirectory (path);
-
- Directory.Delete (path);
- }
- [Test]
- [ExpectedException(typeof(IOException))]
- public void DeleteArgumentException4 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.6";
- DeleteDirectory (path);
- FileStream s = null;
- Directory.CreateDirectory (path);
- try {
- s = File.Create (path + "/DirectoryTest.Test.6");
- Directory.Delete (path);
- } finally {
- if (s != null)
- s.Close ();
- DeleteDirectory (path);
- };
- }
- [Test]
- public void Exists ()
- {
- AssertEquals ("test#01", false, Directory.Exists (null as string));
- }
-
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetCreationTimeException1 ()
- {
- Directory.GetCreationTime (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetCreationTimeException2 ()
- {
- Directory.GetCreationTime ("");
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void GetCreationTimeException3 ()
- {
- string path = TempFolder + "/DirectoryTest.GetCreationTime.1";
- DeleteDirectory (path);
- try {
- Directory.GetCreationTime (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetCreationTimeException4 ()
- {
- Directory.GetCreationTime (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetCreationTimeException5 ()
- {
- Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetCreationTimeUtcException1 ()
- {
- Directory.GetCreationTimeUtc (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetCreationTimeUtcException2 ()
- {
- Directory.GetCreationTimeUtc ("");
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void GetCreationTimeUtcException3 ()
- {
- string path = TempFolder + "/DirectoryTest.GetCreationTimeUtc.1";
- DeleteDirectory (path);
-
- try {
- Directory.GetCreationTimeUtc (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetCreationTimeUtcException4 ()
- {
- Directory.GetCreationTimeUtc (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetCreationTimeUtcException5 ()
- {
- Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetLastAccessTimeException1 ()
- {
- Directory.GetLastAccessTime (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastAccessTimeException2 ()
- {
- Directory.GetLastAccessTime ("");
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void GetLastAccessTimeException3 ()
- {
- string path = TempFolder + "/DirectoryTest.GetLastAccessTime.1";
- DeleteDirectory (path);
-
- try {
- Directory.GetLastAccessTime (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastAccessTimeException4 ()
- {
- Directory.GetLastAccessTime (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastAccessTimeException5 ()
- {
- Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetLastAccessTimeUtcException1 ()
- {
- Directory.GetLastAccessTimeUtc (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastAccessTimeUtcException2 ()
- {
- Directory.GetLastAccessTimeUtc ("");
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void GetLastAccessTimeUtcException3 ()
- {
- string path = TempFolder + "/DirectoryTest.GetLastAccessTimeUtc.1";
- DeleteDirectory (path);
- try {
- Directory.GetLastAccessTimeUtc (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastAccessTimeUtcException4 ()
- {
- Directory.GetLastAccessTimeUtc (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastAccessTimeUtcException5 ()
- {
- Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetLastWriteTimeException1 ()
- {
- Directory.GetLastWriteTime (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeException2 ()
- {
- Directory.GetLastWriteTime ("");
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void GetLastWriteTimeException3 ()
- {
- string path = TempFolder + "/DirectoryTest.GetLastWriteTime.1";
- DeleteDirectory (path);
- try {
- Directory.GetLastWriteTime (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeException4 ()
- {
- Directory.GetLastWriteTime (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeException5 ()
- {
- Directory.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void GetLastWriteTimeUtcException1 ()
- {
- Directory.GetLastWriteTimeUtc (null as string);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeUtcException2 ()
- {
- Directory.GetLastAccessTimeUtc ("");
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void GetLastWriteTimeUtcException3 ()
- {
- string path = TempFolder + "/DirectoryTest.GetLastWriteTimeUtc.1";
- DeleteDirectory (path);
- try {
- Directory.GetLastAccessTimeUtc (path);
- } finally {
- DeleteDirectory (path);
- }
-
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeUtcException4 ()
- {
- Directory.GetLastAccessTimeUtc (" ");
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void GetLastWriteTimeUtcException5 ()
- {
- Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
- }
- [Test]
- public void Move ()
- {
- string path = TempFolder + "/DirectoryTest.Test.9";
- string path2 = TempFolder + "/DirectoryTest.Test.10";
- DeleteDirectory (path);
- DeleteDirectory (path2);
- try {
- Directory.CreateDirectory (path);
- Directory.CreateDirectory (path + "/" + "dir");
- AssertEquals ("test#01", true, Directory.Exists (path + "/" + "dir"));
-
- Directory.Move (path, path2);
- AssertEquals ("test#02", false, Directory.Exists (path + "/" + "dir"));
- AssertEquals ("test#03", true, Directory.Exists (path2 + "/" + "dir"));
-
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path2);
- if (Directory.Exists (path2 + "/" + "dir"))
- Directory.Delete (path2 + "/" + "dir", true);
- }
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void MoveException1 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.8";
- DeleteDirectory (path);
- try {
- Directory.Move (path, path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void MoveException2 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.11";
- DeleteDirectory (path);
- try {
- Directory.Move ("", path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void MoveException3 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.12";
- DeleteDirectory (path);
- try {
- Directory.Move (" ", path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void MoveException4 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.13";
- path += Path.InvalidPathChars [0];
- string path2 = TempFolder + "/DirectoryTest.Test.13";
- DeleteDirectory (path);
- DeleteDirectory (path2);
- try {
- Directory.CreateDirectory (path2);
- Directory.Move (path2, path);
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path2);
- }
- }
- [Test]
- [ExpectedException(typeof(DirectoryNotFoundException))]
- public void MoveException5 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.14";
- DeleteDirectory (path);
- try {
- Directory.Move (path, path + "Test.Test");
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path + "Test.Test");
- }
- }
- [Test]
- [ExpectedException(typeof(IOException))]
- public void MoveException6 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.15";
- DeleteDirectory (path);
- try {
- Directory.CreateDirectory (path);
- Directory.Move (path, path + "/" + "dir");
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path + "/" + "dir");
- }
- }
- [Test]
- [ExpectedException(typeof(IOException))]
- public void MoveException7 ()
- {
- string path = TempFolder + "/DirectoryTest.Test.16";
- string path2 = TempFolder + "/DirectoryTest.Test.17";
-
- DeleteDirectory (path);
- DeleteDirectory (path2);
- try {
- Directory.CreateDirectory (path);
- Directory.CreateDirectory (path2);
- Directory.Move (path, path2);
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path2);
- }
- }
-
- [Test]
- [Ignore("Unix doesnt support CreationTime")]
- public void CreationTime ()
- {
- string path = TempFolder + "/DirectoryTest.CreationTime.1";
- DeleteDirectory (path);
-
- try {
- Directory.CreateDirectory (path);
- Directory.SetCreationTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
- DateTime time = Directory.GetCreationTime (path);
- AssertEquals ("test#01", 2003, time.Year);
- AssertEquals ("test#02", 6, time.Month);
- AssertEquals ("test#03", 4, time.Day);
- AssertEquals ("test#04", 6, time.Hour);
- AssertEquals ("test#05", 4, time.Minute);
- AssertEquals ("test#06", 0, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetCreationTimeUtc (path));
- AssertEquals ("test#07", 2003, time.Year);
- AssertEquals ("test#08", 6, time.Month);
- AssertEquals ("test#09", 4, time.Day);
- AssertEquals ("test#10", 6, time.Hour);
- AssertEquals ("test#11", 4, time.Minute);
- AssertEquals ("test#12", 0, time.Second);
- Directory.SetCreationTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
- time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetCreationTime (path));
- AssertEquals ("test#13", 2003, time.Year);
- AssertEquals ("test#14", 6, time.Month);
- AssertEquals ("test#15", 4, time.Day);
- AssertEquals ("test#16", 6, time.Hour);
- AssertEquals ("test#17", 4, time.Minute);
- AssertEquals ("test#18", 0, time.Second);
- time = Directory.GetCreationTimeUtc (path);
- AssertEquals ("test#19", 2003, time.Year);
- AssertEquals ("test#20", 6, time.Month);
- AssertEquals ("test#21", 4, time.Day);
- AssertEquals ("test#22", 6, time.Hour);
- AssertEquals ("test#23", 4, time.Minute);
- AssertEquals ("test#24", 0, time.Second);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- public void LastAccessTime ()
- {
- string path = TempFolder + "/DirectoryTest.AccessTime.1";
- DeleteDirectory (path);
-
- try {
- Directory.CreateDirectory (path);
- Directory.SetLastAccessTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
- DateTime time = Directory.GetLastAccessTime (path);
- AssertEquals ("test#01", 2003, time.Year);
- AssertEquals ("test#02", 6, time.Month);
- AssertEquals ("test#03", 4, time.Day);
- AssertEquals ("test#04", 6, time.Hour);
- AssertEquals ("test#05", 4, time.Minute);
- AssertEquals ("test#06", 0, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastAccessTimeUtc (path));
- AssertEquals ("test#07", 2003, time.Year);
- AssertEquals ("test#08", 6, time.Month);
- AssertEquals ("test#09", 4, time.Day);
- AssertEquals ("test#10", 6, time.Hour);
- AssertEquals ("test#11", 4, time.Minute);
- AssertEquals ("test#12", 0, time.Second);
- Directory.SetLastAccessTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
- time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastAccessTime (path));
- AssertEquals ("test#13", 2003, time.Year);
- AssertEquals ("test#14", 6, time.Month);
- AssertEquals ("test#15", 4, time.Day);
- AssertEquals ("test#16", 6, time.Hour);
- AssertEquals ("test#17", 4, time.Minute);
- AssertEquals ("test#18", 0, time.Second);
- time = Directory.GetLastAccessTimeUtc (path);
- AssertEquals ("test#19", 2003, time.Year);
- AssertEquals ("test#20", 6, time.Month);
- AssertEquals ("test#21", 4, time.Day);
- AssertEquals ("test#22", 6, time.Hour);
- AssertEquals ("test#23", 4, time.Minute);
- AssertEquals ("test#24", 0, time.Second);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- public void LastWriteTime ()
- {
- string path = TempFolder + "/DirectoryTest.WriteTime.1";
- DeleteDirectory (path);
-
- try {
- Directory.CreateDirectory (path);
- Directory.SetLastWriteTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
- DateTime time = Directory.GetLastWriteTime (path);
- AssertEquals ("test#01", 2003, time.Year);
- AssertEquals ("test#02", 6, time.Month);
- AssertEquals ("test#03", 4, time.Day);
- AssertEquals ("test#04", 6, time.Hour);
- AssertEquals ("test#05", 4, time.Minute);
- AssertEquals ("test#06", 0, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastWriteTimeUtc (path));
- AssertEquals ("test#07", 2003, time.Year);
- AssertEquals ("test#08", 6, time.Month);
- AssertEquals ("test#09", 4, time.Day);
- AssertEquals ("test#10", 6, time.Hour);
- AssertEquals ("test#11", 4, time.Minute);
- AssertEquals ("test#12", 0, time.Second);
- Directory.SetLastWriteTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
- time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastWriteTime (path));
- AssertEquals ("test#13", 2003, time.Year);
- AssertEquals ("test#14", 6, time.Month);
- AssertEquals ("test#15", 4, time.Day);
- AssertEquals ("test#16", 6, time.Hour);
- AssertEquals ("test#17", 4, time.Minute);
- AssertEquals ("test#18", 0, time.Second);
- time = Directory.GetLastWriteTimeUtc (path);
- AssertEquals ("test#19", 2003, time.Year);
- AssertEquals ("test#20", 6, time.Month);
- AssertEquals ("test#21", 4, time.Day);
- AssertEquals ("test#22", 6, time.Hour);
- AssertEquals ("test#23", 4, time.Minute);
- AssertEquals ("test#24", 0, time.Second);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void SetLastWriteTimeException1 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTime (null as string, time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastWriteTimeException2 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTime ("", time);
- }
-
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void SetLastWriteTimeException3 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- string path = TempFolder + "/DirectoryTest.SetLastWriteTime.2";
- DeleteDirectory (path);
- try {
- Directory.SetLastWriteTime (path, time);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastWriteTimeException4 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTime (" ", time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastWriteTimeException5 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTime (Path.InvalidPathChars [0].ToString (), time);
- }
- // [Test]
- // [ExpectedException(typeof(ArgumentOutOfRangeException))]
- // public void SetLastWriteTimeException6 ()
- // {
- // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
- // string path = TempFolder + Path.DirectorySeparatorChar + "DirectoryTest.SetLastWriteTime.1";
- //
- // try {
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- //
- // Directory.SetLastWriteTime (path, time);
- // } finally {
- // DeleteDirectory (path);
- // }
- //
- // }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void SetLastWriteTimeUtcException1 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTimeUtc (null as string, time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastWriteTimeUtcException2 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTimeUtc ("", time);
- }
-
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void SetLastWriteTimeUtcException3 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- string path = TempFolder + "/DirectoryTest.SetLastWriteTimeUtc.2";
- DeleteDirectory (path);
- try {
- Directory.SetLastWriteTimeUtc (path, time);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastWriteTimeUtcException4 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTimeUtc (" ", time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastWriteTimeUtcException5 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString (), time);
- }
- // [Test]
- // [ExpectedException(typeof(ArgumentOutOfRangeException))]
- // public void SetLastWriteTimeUtcException6 ()
- // {
- // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
- // string path = TempFolder + "/DirectoryTest.SetLastWriteTimeUtc.1";
- //
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- // try {
- // Directory.SetLastWriteTimeUtc (path, time);
- // } finally {
- // DeleteDirectory (path);
- // }
- // }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void SetLastAccessTimeException1 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTime (null as string, time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastAccessTimeException2 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTime ("", time);
- }
-
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void SetLastAccessTimeException3 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- string path = TempFolder + "/DirectoryTest.SetLastAccessTime.2";
- DeleteDirectory (path);
- try {
- Directory.SetLastAccessTime (path, time);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastAccessTimeException4 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTime (" ", time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastAccessTimeException5 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTime (Path.InvalidPathChars [0].ToString (), time);
- }
- // [Test]
- // [ExpectedException(typeof(ArgumentOutOfRangeException))]
- // public void SetLastAccessTimeException6 ()
- // {
- // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
- // string path = TempFolder + "/DirectoryTest.SetLastAccessTime.1";
- //
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- // try {
- // Directory.SetLastAccessTime (path, time);
- // } finally {
- // DeleteDirectory (path);
- // }
- //
- // }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void SetLastAccessTimeUtcException1 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTimeUtc (null as string, time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastAccessTimeUtcException2 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTimeUtc ("", time);
- }
-
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void SetLastAccessTimeUtcException3 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- string path = TempFolder + "/DirectoryTest.SetLastAccessTimeUtc.2";
- DeleteDirectory (path);
- try {
- Directory.SetLastAccessTimeUtc (path, time);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastAccessTimeUtcException4 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTimeUtc (" ", time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetLastAccessTimeUtcException5 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString (), time);
- }
- // [Test]
- // [ExpectedException(typeof(ArgumentOutOfRangeException))]
- // public void SetLastAccessTimeUtcException6 ()
- // {
- // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
- // string path = TempFolder + "/DirectoryTest.SetLastAccessTimeUtc.1";
- //
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- // try {
- // Directory.SetLastAccessTimeUtc (path, time);
- // } finally {
- // DeleteDirectory (path);
- // }
- // }
- [ExpectedException(typeof(ArgumentNullException))]
- public void SetCreationTimeException1 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTime (null as string, time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetCreationTimeException2 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTime ("", time);
- }
-
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void SetCreationTimeException3 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- string path = TempFolder + "/DirectoryTest.SetCreationTime.2";
- DeleteDirectory (path);
-
- try {
- Directory.SetCreationTime (path, time);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetCreationTimeException4 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTime (" ", time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetCreationTimeException5 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTime (Path.InvalidPathChars [0].ToString (), time);
- }
- // [Test]
- // [ExpectedException(typeof(ArgumentOutOfRangeException))]
- // public void SetCreationTimeException6 ()
- // {
- // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
- // string path = TempFolder + "/DirectoryTest.SetCreationTime.1";
- //
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- // try {
- // Directory.SetCreationTime (path, time);
- // DeleteDirectory (path);
- // } finally {
- // DeleteDirectory (path);
- // }
- //
- // }
- [Test]
- [ExpectedException(typeof(ArgumentNullException))]
- public void SetCreationTimeUtcException1 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTimeUtc (null as string, time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetCreationTimeUtcException2 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTimeUtc ("", time);
- }
-
- [Test]
- [ExpectedException(typeof(FileNotFoundException))]
- public void SetCreationTimeUtcException3 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- string path = TempFolder + "/DirectoryTest.SetLastAccessTimeUtc.2";
- DeleteDirectory (path);
-
- try {
- Directory.SetCreationTimeUtc (path, time);
- DeleteDirectory (path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetCreationTimeUtcException4 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTimeUtc (" ", time);
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void SetCreationTimeUtcException5 ()
- {
- DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
- Directory.SetCreationTimeUtc (Path.InvalidPathChars [0].ToString (), time);
- }
- // [Test]
- // [ExpectedException(typeof(ArgumentOutOfRangeException))]
- // public void SetCreationTimeUtcException6 ()
- // {
- // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
- // string path = TempFolder + "/DirectoryTest.SetLastAccessTimeUtc.1";
- //
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- // try {
- // Directory.SetCreationTimeUtc (path, time);
- // DeleteDirectory (path);
- // } finally {
- // DeleteDirectory (path);
- // }
- // }
- [Test]
- public void GetDirectories ()
- {
- string path = TempFolder;
- string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetDirectories";
- DeleteDirectory (DirPath);
-
- try {
- Directory.CreateDirectory (DirPath);
-
- string [] dirs = Directory.GetDirectories (path);
-
- foreach (string directory in dirs) {
-
- if (directory == DirPath)
- return;
- }
-
- Assert ("Directory Not Found", false);
- } finally {
- DeleteDirectory (DirPath);
- }
- }
-
- [Test]
- public void GetFiles ()
- {
- string path = TempFolder;
- string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetFiles";
- if (File.Exists (DirPath))
- File.Delete (DirPath);
-
- try {
- File.Create (DirPath).Close ();
- string [] files = Directory.GetFiles (TempFolder);
- foreach (string directory in files) {
-
- if (directory == DirPath)
- return;
- }
-
- Assert ("File Not Found", false);
- } finally {
- if (File.Exists (DirPath))
- File.Delete (DirPath);
-
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void SetCurrentDirectoryNull ()
- {
- Directory.SetCurrentDirectory (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void SetCurrentDirectoryEmpty ()
- {
- Directory.SetCurrentDirectory (String.Empty);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void SetCurrentDirectoryWhitespace ()
- {
- Directory.SetCurrentDirectory (" ");
- }
- [Test]
- public void GetNoFiles () // Bug 58875. This throwed an exception on windows.
- {
- DirectoryInfo dir = new DirectoryInfo (".");
- dir.GetFiles ("*.nonext");
- }
- private void DeleteDirectory (string path)
- {
- if (Directory.Exists (path))
- Directory.Delete (path, true);
- }
- }
- }
|