public void TestEnumerateFilesWithSearch() { var files = Directory.EnumerateFiles(longPathDirectory, "*").ToArray(); Assert.AreEqual(1, files.Length); Assert.IsTrue(files.Contains(longPathFilename)); }
public void TestDeleteDirectory_JunctionPoint() { var targetFolder = rootTestDir.Combine("ADirectory"); var junctionPoint = rootTestDir.Combine("SymLink"); targetFolder.CreateDirectory(); try { var targetFile = targetFolder.Combine("AFile"); File.Create(targetFile).Close(); try { JunctionPoint.Create(junctionPoint, targetFolder, overwrite: false); Assert.IsTrue(File.Exists(targetFolder.Combine("AFile")), "File should be accessible."); Assert.IsTrue(File.Exists(junctionPoint.Combine("AFile")), "File should be accessible via the junction point."); Directory.Delete(junctionPoint, false); Assert.IsTrue(File.Exists(targetFolder.Combine("AFile")), "File should be accessible."); Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point should not exist now."); Assert.IsTrue(!File.Exists(junctionPoint.Combine("AFile")), "File should not be accessible via the junction point."); } finally { File.Delete(targetFile); } } finally { Directory.Delete(targetFolder); } }
public void TestEnumerateFileSystemEntries() { var entries = Directory.EnumerateFileSystemEntries(longPathDirectory).ToArray(); Assert.AreEqual(1, entries.Length); Assert.IsTrue(entries.Contains(longPathFilename)); }
public void TestEnumerateFilesWithSearchWithNoResults() { var files = Directory.EnumerateFiles(longPathDirectory, "giberish").ToArray(); Assert.AreEqual(0, files.Length); Assert.IsFalse(files.Contains(longPathFilename)); }
public void TestGetFileSystemEntriesWithSearch() { var entries = Directory.GetFileSystemEntries(longPathDirectory, "*").ToArray(); Assert.AreEqual(1, entries.Length); Assert.IsTrue(entries.Contains(longPathFilename)); }
public void TestGetAccessControlSections() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var security = Directory.GetAccessControl(tempLongPathFilename, AccessControlSections.Access); Assert.IsNotNull(security); Assert.AreEqual(typeof(FileSystemRights), security.AccessRightType); Assert.AreEqual(typeof(FileSystemAccessRule), security.AccessRuleType); Assert.AreEqual(typeof(FileSystemAuditRule), security.AuditRuleType); Assert.IsTrue(security.AreAccessRulesCanonical); Assert.IsTrue(security.AreAuditRulesCanonical); Assert.IsFalse(security.AreAccessRulesProtected); Assert.IsFalse(security.AreAuditRulesProtected); var securityGetAccessRules = security.GetAuditRules(true, true, typeof(NTAccount)).Cast <FileSystemAccessRule>(); Assert.AreEqual(0, securityGetAccessRules.Count()); var perm = security.GetAccessRules(true, true, typeof(NTAccount)); var ntAccount = new NTAccount(WindowsIdentity.GetCurrent().Name); var rule = perm.Cast <FileSystemAccessRule>().SingleOrDefault(e => ntAccount == e.IdentityReference); Assert.IsNotNull(rule); Assert.IsTrue((rule.FileSystemRights & FileSystemRights.FullControl) != 0); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestGetFileSystemEntriesWithSearchWithNoResults() { var entries = Directory.GetFileSystemEntries(longPathDirectory, "giberish").ToArray(); Assert.AreEqual(0, entries.Length); Assert.IsFalse(entries.Contains(longPathFilename)); }
public void TestGetLogicalDrives() { var directoryGetLogicalDrives = Directory.GetLogicalDrives(); Assert.IsNotNull(directoryGetLogicalDrives); Assert.IsTrue(directoryGetLogicalDrives.Any()); }
public void TestGetRecursiveFilesWithSubsetSearch() { var tempLongPathFilename = longPathDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { Assert.IsTrue(tempLongPathFilename.Exists()); var newEmptyFile1 = Util.CreateNewEmptyFile(tempLongPathFilename, "A-file"); var newEmptyFile2 = Util.CreateNewEmptyFile(tempLongPathFilename, "B-file"); try { var randomFileName = newEmptyFile1.GetFileName(); var di = new DirectoryInfo(longPathDirectory); var files = di.GetFiles("A*", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(1, files.Length); Assert.IsTrue(files.Any(f => f.Name == newEmptyFile1.GetFileName() && f.DirectoryName == newEmptyFile1.GetDirectoryName())); Assert.IsFalse(files.Any(f => f.Name == newEmptyFile2.GetFileName() && f.DirectoryName == newEmptyFile2.GetDirectoryName())); Assert.IsFalse(files.Any(f => f.Name == Filename.GetFileName() && f.DirectoryName == Filename.GetDirectoryName())); } finally { File.Delete(newEmptyFile1); File.Delete(newEmptyFile2); } } finally { const Boolean recursive = true; Directory.Delete(tempLongPathFilename, recursive); } }
public void TestSetLastWriteTimeUtcNonExistentDir() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); var dateTime = DateTime.UtcNow.AddDays(1); Assert.Throws <FileNotFoundException>(() => Directory.SetLastWriteTimeUtc(tempLongPathFilename, dateTime)); }
public void TestGetParentAtRoot() { const String path = @"c:\"; var parent = Directory.GetParent(path); Assert.IsNull(parent); }
public void TestDeleteDirectory() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); Assert.IsTrue(tempLongPathFilename.GetFullPath().Exists()); Directory.Delete(tempLongPathFilename); Assert.IsFalse(tempLongPathFilename.GetFullPath().Exists()); }
public void TestSetCurrentDirectory() { var originalDir = Directory.GetCurrentDirectory(); try { Assert.Throws <NotSupportedException>(() => Directory.SetCurrentDirectory(longPathDirectory)); } finally { Assert.Throws <NotSupportedException>(() => Directory.SetCurrentDirectory(originalDir)); } }
public void TestCreateWithFileSecurity() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); try { Directory.CreateDirectory(tempLongPathFilename, new DirectorySecurity()); Assert.IsTrue(tempLongPathFilename.Exists()); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestInUseMove() { const Boolean recursive = true; #if SHORT_SOURCE var tempPathFilename1 = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), System.IO.Path.GetRandomFileName()); System.IO.Directory.CreateDirectory(tempPathFilename1); Assert.IsTrue(System.IO.Directory.Exists(Path.GetFullPath(tempPathFilename1))); var tempPathFilename2 = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), System.IO.Path.GetRandomFileName()); System.IO.Directory.CreateDirectory(tempPathFilename2); Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename2))); try { using ( var writer = System.IO.File.CreateText(System.IO.Path.Combine(tempPathFilename2, "TestInUseMove"))) { string destinationPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(tempPathFilename1, System.IO.Path.GetFileName(tempPathFilename2))); System.IO.Directory.Move(tempPathFilename2, destinationPath); Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename1))); Assert.IsFalse(System.IO.Directory.Exists(System.IO.Path.GetFullPath(tempPathFilename2))); Assert.IsTrue(System.IO.Directory.Exists(destinationPath)); } } catch (Exception e) { throw; } finally { Directory.Delete(tempPathFilename1, recursive); Directory.Delete(tempPathFilename2, recursive); } #endif var tempLongPathFilename1 = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); tempLongPathFilename1.CreateDirectory(); Assert.IsTrue(tempLongPathFilename1.GetFullPath().Exists()); var tempLongPathFilename2 = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); tempLongPathFilename2.CreateDirectory(); Assert.IsTrue(tempLongPathFilename2.GetFullPath().Exists()); try { using (var writer = File.CreateText(tempLongPathFilename2.Combine("TestInUseMove"))) { var destinationPath = tempLongPathFilename1.Combine(tempLongPathFilename2.GetFileName()).GetFullPath(); Assert.Throws <IOException>(() => Directory.Move(tempLongPathFilename2, destinationPath)); } } finally { Directory.Delete(tempLongPathFilename1, recursive); Directory.Delete(tempLongPathFilename2, recursive); } }
public void TestCreateDirectoryThatEndsWithSlash() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName() + @"\"); var di = tempLongPathFilename.CreateDirectory(); try { Assert.IsNotNull(di); Assert.IsTrue(tempLongPathFilename.Exists()); } finally { Directory.Delete(tempLongPathFilename); } }
public void DeleteTempFolder() { if (this.tempFolder != null) { foreach (var file in new DirectoryInfo(this.tempFolder).GetFileSystemInfos()) { file.Delete(); } Directory.Delete(this.tempFolder); this.tempFolder = null; } }
public void TestReplaceIgnoreMergeWithReadonlyBackupPath() { var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString(); var tempBackupPathName = new StringBuilder(longPathDirectory).Append(@"\readonly").ToString(); var di = new DirectoryInfo(tempBackupPathName); di.Create(); var attr = di.Attributes; di.Attributes = attr | FileAttributes.ReadOnly; var tempBackupLongPathFilename = new StringBuilder(tempBackupPathName).Append(@"\").Append("backup").ToString(); using (var fileStream = File.Create(tempLongPathFilename)) { fileStream.WriteByte(42); } var tempLongPathFilename2 = new StringBuilder(longPathDirectory).Append(@"\").Append("filename2.ext").ToString(); using (var fileStream = File.Create(tempLongPathFilename2)) { fileStream.WriteByte(52); } try { const Boolean ignoreMetadataErrors = true; File.Replace(tempLongPathFilename, tempLongPathFilename2, tempBackupLongPathFilename, ignoreMetadataErrors); using (var fileStream = File.OpenRead(tempLongPathFilename2)) { Assert.AreEqual(42, fileStream.ReadByte()); } Assert.IsFalse(File.Exists(tempLongPathFilename)); Assert.IsTrue(File.Exists(tempBackupLongPathFilename)); } finally { di.Attributes = attr; if (File.Exists(tempLongPathFilename)) { File.Delete(tempLongPathFilename); } File.Delete(tempLongPathFilename2); File.Delete(tempBackupLongPathFilename); if (tempBackupPathName.Exists()) { Directory.Delete(tempBackupPathName); } } }
public void TearDown() { try { File.Delete(longPathFilename); } catch (Exception e) { Trace.WriteLine("Exception {0} deleting \"longPathFilename\"", e.ToString()); throw; } finally { Directory.Delete(longPathRoot, true); } }
public void TestEnumerateFilesSearchWithNoResults() { var tempLongPathFilename = longPathDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); Assert.AreEqual(0, di.EnumerateFiles("gibberish*").Count()); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestCreate() { var tempLongPathFilename = longPathDirectory.Combine(Path.GetRandomFileName()); var di = new DirectoryInfo(tempLongPathFilename); di.Create(); try { Assert.IsTrue(di.Exists); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateDirectoriesWithWildcardSearchAndOptionNoResults() { var tempLongPathFilename = longPathDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); Assert.AreEqual(0, di.EnumerateDirectories("gibberish*", SearchOption.TopDirectoryOnly).Count()); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestGetLastWriteTimeUtc() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var dateTime = Directory.GetLastWriteTimeUtc(tempLongPathFilename); var fi = new DirectoryInfo(tempLongPathFilename); Assert.AreEqual(fi.LastWriteTimeUtc, dateTime); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestSetLastAccessTime() { var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var dateTime = DateTime.Now.AddDays(1); Directory.SetLastAccessTime(tempLongPathFilename, dateTime); var fi = new DirectoryInfo(tempLongPathFilename); Assert.AreEqual(fi.LastAccessTime, dateTime); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestRecursiveEnumerateDirectoriesWithSearchNoResults() { var randomFileName = Pri.LongPath.Path.GetRandomFileName(); var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var dirs = Directory.EnumerateDirectories(longPathDirectory, "gibberish", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(0, dirs.Length); Assert.IsFalse(dirs.Contains(tempLongPathFilename)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateDirectoriesWithSearch() { var randomFileName = Pri.LongPath.Path.GetRandomFileName(); var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var dirs = Directory.EnumerateDirectories(longPathDirectory, "*").ToArray(); Assert.AreEqual(1, dirs.Length); Assert.IsTrue(dirs.Contains(tempLongPathFilename)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateDirectoriesWithSearchWithNoResults() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); var dirs = di.EnumerateDirectories("gibberish").ToArray(); Assert.AreEqual(0, dirs.Length); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestRecursiveEnumerateDirectoriesWithSingleSubsetSearch() { const String randomFileName = "TestRecursiveEnumerateDirectoriesWithSubsetSearch"; var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var dirs = Directory.EnumerateDirectories(longPathDirectory, "T*", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(1, dirs.Length); Assert.IsTrue(dirs.Contains(tempLongPathFilename)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateFilesSearchWithResults() { var tempLongPathFilename = longPathDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); var files = di.EnumerateFiles("*").ToArray(); Assert.AreEqual(1, files.Length); Assert.IsTrue(files.Any(f => f.Name == Filename)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestGetRecursiveDirectoriesWithSubsetSearch() { var tempLongPathFilename = longPathDirectory.Combine("TestGetRecursiveDirectoriesWithSubsetSearch"); tempLongPathFilename.CreateDirectory(); var tempLongPathFilename2 = tempLongPathFilename.Combine("ATestGetRecursiveDirectoriesWithSubsetSearch"); tempLongPathFilename2.CreateDirectory(); try { Assert.AreEqual(1, longPathDirectory.GetDirectories("A*", SearchOption.AllDirectories).Count()); } finally { Directory.Delete(tempLongPathFilename2); Directory.Delete(tempLongPathFilename); } }