| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196 |
- //
- // 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");
- static readonly char DSC = Path.DirectorySeparatorChar;
- [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 + DSC + "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 + DSC + "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 + DSC + "DirectoryTest.Test.Delete.1";
- DeleteDirectory (path);
- try {
- Directory.CreateDirectory (path);
- AssertEquals ("test#01", true, Directory.Exists (path));
-
- Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
- AssertEquals ("test#02", true, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
-
- Directory.Delete (path + DSC + "DirectoryTest.Test.Delete.1.2");
- AssertEquals ("test#03", false, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#04", true, Directory.Exists (path));
-
- Directory.Delete (path);
- AssertEquals ("test#05", false, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#06", false, Directory.Exists (path));
-
- Directory.CreateDirectory (path);
- Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
- AssertEquals ("test#07", true, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
- AssertEquals ("test#08", true, Directory.Exists (path));
-
- Directory.Delete (path, true);
- AssertEquals ("test#09", false, Directory.Exists (path + DSC + "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 + DSC + "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 + DSC + "DirectoryTest.Test.5";
- DeleteDirectory (path);
-
- Directory.Delete (path);
- }
- [Test]
- [ExpectedException(typeof(IOException))]
- public void DeleteArgumentException4 ()
- {
- string path = TempFolder + DSC + "DirectoryTest.Test.6";
- DeleteDirectory (path);
- FileStream s = null;
- Directory.CreateDirectory (path);
- try {
- s = File.Create (path + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "DirectoryTest.Test.9";
- string path2 = TempFolder + DSC + "DirectoryTest.Test.10";
- DeleteDirectory (path);
- DeleteDirectory (path2);
- try {
- Directory.CreateDirectory (path);
- Directory.CreateDirectory (path + DSC + "dir");
- AssertEquals ("test#01", true, Directory.Exists (path + DSC + "dir"));
-
- Directory.Move (path, path2);
- AssertEquals ("test#02", false, Directory.Exists (path + DSC + "dir"));
- AssertEquals ("test#03", true, Directory.Exists (path2 + DSC + "dir"));
-
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path2);
- if (Directory.Exists (path2 + DSC + "dir"))
- Directory.Delete (path2 + DSC + "dir", true);
- }
- }
-
- [Test]
- [ExpectedException(typeof(IOException))]
- public void MoveException1 ()
- {
- string path = TempFolder + DSC + "DirectoryTest.Test.8";
- DeleteDirectory (path);
- try {
- Directory.Move (path, path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void MoveException2 ()
- {
- string path = TempFolder + DSC + "DirectoryTest.Test.11";
- DeleteDirectory (path);
- try {
- Directory.Move ("", path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void MoveException3 ()
- {
- string path = TempFolder + DSC + "DirectoryTest.Test.12";
- DeleteDirectory (path);
- try {
- Directory.Move (" ", path);
- } finally {
- DeleteDirectory (path);
- }
- }
- [Test]
- [ExpectedException(typeof(ArgumentException))]
- public void MoveException4 ()
- {
- string path = TempFolder + DSC + "DirectoryTest.Test.13";
- path += Path.InvalidPathChars [0];
- string path2 = TempFolder + DSC + "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 + DSC + "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 + DSC + "DirectoryTest.Test.15";
- DeleteDirectory (path);
- try {
- Directory.CreateDirectory (path);
- Directory.Move (path, path + DSC + "dir");
- } finally {
- DeleteDirectory (path);
- DeleteDirectory (path + DSC + "dir");
- }
- }
- [Test]
- [ExpectedException(typeof(IOException))]
- public void MoveException7 ()
- {
- string path = TempFolder + DSC + "DirectoryTest.Test.16";
- string path2 = TempFolder + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
- //
- // if (!Directory.Exists (path))
- // Directory.CreateDirectory (path);
- // try {
- // Directory.SetLastAccessTimeUtc (path, time);
- // } finally {
- // DeleteDirectory (path);
- // }
- // }
- [Test]
- [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 + DSC + "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 + DSC + "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 + DSC + "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 + DSC + "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 GetParentOfRootDirectory ()
- {
- DirectoryInfo info;
- info = Directory.GetParent (Path.GetPathRoot (Path.GetTempPath ()));
- AssertEquals (null, info);
- }
-
- [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);
- }
- }
- }
|