示例#1
0
        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);
            }
        }
示例#2
0
        public void TestGetTempPath()
        {
            var path = Path.GetTempPath();

            Assert.IsNotNull(path);
            Assert.IsTrue(path.Length > 0);
        }
示例#3
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);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        public void TestGetTempFilename()
        {
            var filename = Path.GetTempFileName();

            Assert.IsNotNull(filename);
            Assert.IsTrue(filename.Length > 0);
        }
示例#7
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);
            }
        }
示例#8
0
        public void TestMoveToSamePathWithSlash()
        {
            var randomDirectoryName   = Path.GetRandomFileName();
            var tempLongPathDirectory = uncDirectory.Combine(randomDirectoryName) + @"\";
            var di = new DirectoryInfo(tempLongPathDirectory);

            Assert.Throws <IOException>(() => di.MoveTo(tempLongPathDirectory));
        }
示例#9
0
        public void TestMoveToNullPath()
        {
            var randomDirectoryName   = Path.GetRandomFileName();
            var tempLongPathDirectory = uncDirectory.Combine(randomDirectoryName);
            var di = new DirectoryInfo(tempLongPathDirectory);

            Assert.Throws <ArgumentNullException>(() => di.MoveTo(null));
        }
示例#10
0
        public void TestMoveToDifferentRoot()
        {
            var randomDirectoryName   = Path.GetRandomFileName();
            var tempLongPathDirectory = uncDirectory.Combine(randomDirectoryName);
            var di = new DirectoryInfo(tempLongPathDirectory);

            Assert.Throws <IOException>(() => di.MoveTo(@"D:\"));
        }
示例#11
0
        public void TestCombineArrayOnePath()
        {
            var strings = new[] {
                longPathDirectory
            };

            Assert.AreEqual(longPathDirectory, Path.Combine(strings));
        }
示例#12
0
        public void TestCombineArrayTwoPaths()
        {
            var strings = new[] {
                longPathDirectory, "filename.ext"
            };

            Assert.AreEqual(longPathDirectory.Combine("filename.ext"), Path.Combine(strings));
        }
示例#13
0
        public void TestMoveToEmptyPath()
        {
            var randomDirectoryName   = Path.GetRandomFileName();
            var tempLongPathDirectory = longPathDirectory.Combine(randomDirectoryName);
            var di = new DirectoryInfo(tempLongPathDirectory);

            Assert.Throws <ArgumentException>(() => di.MoveTo(String.Empty));
        }
示例#14
0
        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();
            }
        }
示例#15
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);
            }
        }
示例#16
0
        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();
            }
        }
示例#17
0
        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);
            }
        }
示例#18
0
        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);
            }
        }
示例#19
0
        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();
            }
        }
示例#20
0
        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);
            }
        }
示例#21
0
        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);
            }
        }
示例#22
0
        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);
            }
        }
示例#23
0
        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);
            }
        }
示例#24
0
        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);
            }
        }
示例#25
0
        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);
            }
        }
示例#26
0
        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);
                }
            }
        }
示例#27
0
        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);
            }
        }
示例#28
0
        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);
            }
        }
示例#29
0
        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);
            }
        }
示例#30
0
        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);
            }
        }