public void TestGetRecursiveFilesWithAllSearch() { var tempLongPathFilename = longPathDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { Assert.IsTrue(tempLongPathFilename.Exists()); var newEmptyFile = Util.CreateNewEmptyFile(tempLongPathFilename); try { var randomFileName = newEmptyFile.GetFileName(); var di = new DirectoryInfo(longPathDirectory); var files = di.GetFiles("*", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(2, files.Length); Assert.IsTrue(files.Any(f => f.Name == Filename)); Assert.IsTrue(files.Any(f => f.Name == randomFileName)); } finally { File.Delete(newEmptyFile); } } finally { const Boolean recursive = true; Directory.Delete(tempLongPathFilename, recursive); } }
public void TestGetTempPath() { var path = Path.GetTempPath(); Assert.IsNotNull(path); Assert.IsTrue(path.Length > 0); }
public void TestCreateTextAndWrite() { Assert.IsTrue(uncDirectory.Exists()); String tempLongPathFilename; do { tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); } while (Pri.LongPath.File.Exists(tempLongPathFilename)); Assert.IsFalse(Pri.LongPath.File.Exists(tempLongPathFilename)); const String fileText = "test"; using (var writer = Pri.LongPath.File.CreateText(tempLongPathFilename)) { writer.WriteLine(fileText); } try { Assert.IsTrue(Pri.LongPath.File.Exists(tempLongPathFilename)); var fileInfo = new FileInfo(tempLongPathFilename); Assert.AreEqual(fileText.Length + Environment.NewLine.Length, fileInfo.Length); } finally { Pri.LongPath.File.Delete(tempLongPathFilename); } }
public void FileInfoReturnsCorrectDirectoryForLongPathFile() { Assert.IsTrue(uncDirectory.Exists()); String tempLongPathFilename; do { tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); } while (File.Exists(tempLongPathFilename)); Assert.IsFalse(File.Exists(tempLongPathFilename)); using (var writer = File.CreateText(tempLongPathFilename)) { writer.WriteLine("test"); } try { Assert.IsTrue(File.Exists(tempLongPathFilename)); var fileInfo = new FileInfo(tempLongPathFilename); Assert.AreEqual(uncDirectory, fileInfo.Directory.FullName); Assert.AreEqual(uncDirectory.GetFileName(), fileInfo.Directory.Name); } finally { File.Delete(tempLongPathFilename); } }
public void TestGetRecursiveFilesWithSubsetSearch() { var tempLongPathFilename = uncDirectory.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(uncDirectory); 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 { Pri.LongPath.File.Delete(newEmptyFile1); Pri.LongPath.File.Delete(newEmptyFile2); } } finally { const Boolean recursive = true; Pri.LongPath.Directory.Delete(tempLongPathFilename, recursive); } }
public void TestGetTempFilename() { var filename = Path.GetTempFileName(); Assert.IsNotNull(filename); Assert.IsTrue(filename.Length > 0); }
public void TestGetAccessControlSections() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(tempLongPathFilename); var security = di.GetAccessControl(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 { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }
public void TestMoveToSamePathWithSlash() { var randomDirectoryName = Path.GetRandomFileName(); var tempLongPathDirectory = uncDirectory.Combine(randomDirectoryName) + @"\"; var di = new DirectoryInfo(tempLongPathDirectory); Assert.Throws <IOException>(() => di.MoveTo(tempLongPathDirectory)); }
public void TestMoveToNullPath() { var randomDirectoryName = Path.GetRandomFileName(); var tempLongPathDirectory = uncDirectory.Combine(randomDirectoryName); var di = new DirectoryInfo(tempLongPathDirectory); Assert.Throws <ArgumentNullException>(() => di.MoveTo(null)); }
public void TestMoveToDifferentRoot() { var randomDirectoryName = Path.GetRandomFileName(); var tempLongPathDirectory = uncDirectory.Combine(randomDirectoryName); var di = new DirectoryInfo(tempLongPathDirectory); Assert.Throws <IOException>(() => di.MoveTo(@"D:\")); }
public void TestCombineArrayOnePath() { var strings = new[] { longPathDirectory }; Assert.AreEqual(longPathDirectory, Path.Combine(strings)); }
public void TestCombineArrayTwoPaths() { var strings = new[] { longPathDirectory, "filename.ext" }; Assert.AreEqual(longPathDirectory.Combine("filename.ext"), Path.Combine(strings)); }
public void TestMoveToEmptyPath() { var randomDirectoryName = Path.GetRandomFileName(); var tempLongPathDirectory = longPathDirectory.Combine(randomDirectoryName); var di = new DirectoryInfo(tempLongPathDirectory); Assert.Throws <ArgumentException>(() => di.MoveTo(String.Empty)); }
public void TestCreateWithFileSecurity() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); var di = new DirectoryInfo(tempLongPathFilename); try { di.Create(new DirectorySecurity()); Assert.IsTrue(tempLongPathFilename.Exists()); } finally { di.Delete(); } }
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 TestCreateSubdirectory() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { Assert.IsNotNull(newDi); Assert.IsTrue(di.Exists); } finally { newDi.Delete(); } }
public void TestCreate() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); var di = new DirectoryInfo(tempLongPathFilename); di.Create(); try { Assert.IsTrue(di.Exists); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateFilesSearchWithNoResults() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(uncDirectory); Assert.AreEqual(0, di.EnumerateFiles("gibberish*").Count()); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }
public void TestCreateSubdirectoryWithFileSecurity() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); DirectoryInfo newDi = null; try { newDi = di.CreateSubdirectory(randomFileName, new DirectorySecurity()); Assert.IsNotNull(newDi); Assert.IsTrue(di.Exists); } finally { newDi?.Delete(); } }
public void TestEnumerateDirectoriesWithSearchWithNoResults() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = uncDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(uncDirectory); var dirs = di.EnumerateDirectories("gibberish").ToArray(); Assert.AreEqual(0, dirs.Length); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateFilesSearchWithResults() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(uncDirectory); var files = di.EnumerateFiles("*").ToArray(); Assert.AreEqual(1, files.Length); Assert.IsTrue(files.Any(f => f.Name == Filename)); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }
public void TestRecursiveEnumerateDirectoriesWithSearchNoResults() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); var dirs = di.EnumerateDirectories("gibberish", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(0, dirs.Length); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestEnumerateDirectoriesWithSearchRecursive() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); var dirs = di.EnumerateDirectories("*", SearchOption.AllDirectories).ToArray(); Assert.AreEqual(1, dirs.Length); Assert.IsTrue(dirs.Any(f => f.Name == randomFileName)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestGetDirectories() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = longPathDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(longPathDirectory); var dirs = di.GetDirectories(); Assert.AreEqual(1, dirs.Count()); Assert.IsTrue(dirs.Any(f => f.Name == randomFileName)); } finally { Directory.Delete(tempLongPathFilename); } }
public void TestGetDirectoriesWithAllSearch() { var randomFileName = Path.GetRandomFileName(); var tempLongPathFilename = uncDirectory.Combine(randomFileName); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(uncDirectory); var dirs = di.GetDirectories("*").ToArray(); Assert.AreEqual(1, dirs.Length); Assert.IsTrue(dirs.Any(f => f.Name == randomFileName)); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }
public void TestMove() { var sourceFilename = Util.CreateNewFile(uncDirectory); var destFilename = uncDirectory.Combine(Path.GetRandomFileName()); File.Move(sourceFilename, destFilename); try { Assert.IsFalse(File.Exists(sourceFilename)); Assert.IsTrue(File.Exists(destFilename)); Assert.IsTrue(Util.VerifyContentsOfNewFile(destFilename)); } finally { if (File.Exists(destFilename)) { File.Delete(destFilename); } } }
public void TestOpenCreatesEmpty() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); try { using (var writer = Pri.LongPath.File.CreateText(tempLongPathFilename)) { writer.WriteLine("test"); } var fi = new FileInfo(tempLongPathFilename); using (var fileStream = fi.Open(FileMode.Append, FileAccess.Read, FileShare.Read)) { Assert.AreEqual(-1, fileStream.ReadByte()); } } finally { Pri.LongPath.File.Delete(tempLongPathFilename); } }
public void TestGetFileSystemInfosWithSearchRecursiveNoResults() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(newDi.FullName.Combine("filename")); using (fi.Create()) { } try { Assert.AreEqual(0, di.GetFileSystemInfos("gibberish", SearchOption.AllDirectories).Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestGetFileSystemInfosWithSearchAndOptionMultipleResults() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(newDi.FullName.Combine("filename")); using (fi.Create()) { } try { Assert.AreEqual(2, di.GetFileSystemInfos("*", SearchOption.TopDirectoryOnly).Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }
public void TestGetFileSystemInfos() { var di = new DirectoryInfo(uncDirectory); var randomFileName = Path.GetRandomFileName(); var newDi = di.CreateSubdirectory(randomFileName); try { var fi = new FileInfo(newDi.FullName.Combine("filename")); using (fi.Create()) { } try { Assert.AreEqual(1, newDi.GetFileSystemInfos().Count()); } finally { fi.Delete(); } } finally { newDi.Delete(true); } }