コード例 #1
0
        public void TestEnumerateFilesWithSearch()
        {
            var files = Directory.EnumerateFiles(longPathDirectory, "*").ToArray();

            Assert.AreEqual(1, files.Length);
            Assert.IsTrue(files.Contains(longPathFilename));
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        public void TestEnumerateFileSystemEntries()
        {
            var entries = Directory.EnumerateFileSystemEntries(longPathDirectory).ToArray();

            Assert.AreEqual(1, entries.Length);
            Assert.IsTrue(entries.Contains(longPathFilename));
        }
コード例 #4
0
        public void TestEnumerateFilesWithSearchWithNoResults()
        {
            var files = Directory.EnumerateFiles(longPathDirectory, "giberish").ToArray();

            Assert.AreEqual(0, files.Length);
            Assert.IsFalse(files.Contains(longPathFilename));
        }
コード例 #5
0
        public void TestGetFileSystemEntriesWithSearch()
        {
            var entries = Directory.GetFileSystemEntries(longPathDirectory, "*").ToArray();

            Assert.AreEqual(1, entries.Length);
            Assert.IsTrue(entries.Contains(longPathFilename));
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        public void TestGetFileSystemEntriesWithSearchWithNoResults()
        {
            var entries = Directory.GetFileSystemEntries(longPathDirectory, "giberish").ToArray();

            Assert.AreEqual(0, entries.Length);
            Assert.IsFalse(entries.Contains(longPathFilename));
        }
コード例 #8
0
        public void TestGetLogicalDrives()
        {
            var directoryGetLogicalDrives = Directory.GetLogicalDrives();

            Assert.IsNotNull(directoryGetLogicalDrives);
            Assert.IsTrue(directoryGetLogicalDrives.Any());
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        public void TestSetLastWriteTimeUtcNonExistentDir()
        {
            var tempLongPathFilename = longPathDirectory.Combine(Pri.LongPath.Path.GetRandomFileName());
            var dateTime             = DateTime.UtcNow.AddDays(1);

            Assert.Throws <FileNotFoundException>(() => Directory.SetLastWriteTimeUtc(tempLongPathFilename, dateTime));
        }
コード例 #11
0
        public void TestGetParentAtRoot()
        {
            const String path   = @"c:\";
            var          parent = Directory.GetParent(path);

            Assert.IsNull(parent);
        }
コード例 #12
0
        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());
        }
コード例 #13
0
        public void TestSetCurrentDirectory()
        {
            var originalDir = Directory.GetCurrentDirectory();

            try {
                Assert.Throws <NotSupportedException>(() => Directory.SetCurrentDirectory(longPathDirectory));
            }
            finally {
                Assert.Throws <NotSupportedException>(() => Directory.SetCurrentDirectory(originalDir));
            }
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
        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;
            }
        }
コード例 #18
0
ファイル: FileTests.cs プロジェクト: Protiguous/Pri.LongPath
        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);
                }
            }
        }
コード例 #19
0
        public void TearDown()
        {
            try {
                File.Delete(longPathFilename);
            }
            catch (Exception e) {
                Trace.WriteLine("Exception {0} deleting \"longPathFilename\"", e.ToString());

                throw;
            }
            finally {
                Directory.Delete(longPathRoot, true);
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
        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);
            }
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
        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);
            }
        }
コード例 #30
0
        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);
            }
        }