private void AlphaFS_Directory_CopyTimestamps(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder1 = tempRoot.CreateDirectory();

                Thread.Sleep(1500);

                var folder2 = tempRoot.CreateDirectory();


                Console.WriteLine("Input Directory1 Path: [{0}]", folder1.FullName);
                Console.WriteLine("Input Directory2 Path: [{0}]", folder2.FullName);


                Assert.AreNotEqual(System.IO.Directory.GetCreationTime(folder1.FullName), System.IO.Directory.GetCreationTime(folder2.FullName));
                Assert.AreNotEqual(System.IO.Directory.GetLastAccessTime(folder1.FullName), System.IO.Directory.GetLastAccessTime(folder2.FullName));
                Assert.AreNotEqual(System.IO.Directory.GetLastWriteTime(folder1.FullName), System.IO.Directory.GetLastWriteTime(folder2.FullName));


                Alphaleonis.Win32.Filesystem.Directory.CopyTimestamps(folder1.FullName, folder2.FullName);


                Assert.AreEqual(System.IO.Directory.GetCreationTime(folder1.FullName), System.IO.Directory.GetCreationTime(folder2.FullName));
                Assert.AreEqual(System.IO.Directory.GetLastAccessTime(folder1.FullName), System.IO.Directory.GetLastAccessTime(folder2.FullName));
                Assert.AreEqual(System.IO.Directory.GetLastWriteTime(folder1.FullName), System.IO.Directory.GetLastWriteTime(folder2.FullName));
            }

            Console.WriteLine();
        }
Exemple #2
0
        private void DirectoryInfo_MoveTo_FolderToEmptyFolder(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var testfolder = tempRoot.RandomDirectoryName;

                var folderSrc = Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(System.IO.Path.Combine(tempRoot.Directory.FullName, testfolder));
                var folderDst = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folderSrc.FullName);
                Console.WriteLine("\n\tMove folder to: [{0}]", folderDst.FullName);


                folderSrc.MoveTo(System.IO.Path.Combine(folderDst.FullName, testfolder));

                folderSrc.Refresh();
                folderDst.Refresh();


                Assert.IsTrue(folderSrc.Exists, "It is expected that the source exists, but is does not.");

                Assert.AreEqual(folderSrc.Parent.FullName, folderDst.FullName);
            }

            Console.WriteLine();
        }
Exemple #3
0
        private void AlphaFS_Directory_SetTimestamps(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);


                folder.Attributes |= System.IO.FileAttributes.ReadOnly | System.IO.FileAttributes.Hidden;

                var creationTime   = tempRoot.GetRandomFileDate();
                var lastAccessTime = tempRoot.GetRandomFileDate();
                var lastWriteTime  = tempRoot.GetRandomFileDate();


                Alphaleonis.Win32.Filesystem.Directory.SetTimestamps(folder.FullName, creationTime, lastAccessTime, lastWriteTime);


                Assert.AreEqual(System.IO.Directory.GetCreationTime(folder.FullName), creationTime);
                Assert.AreEqual(System.IO.Directory.GetLastAccessTime(folder.FullName), lastAccessTime);
                Assert.AreEqual(System.IO.Directory.GetLastWriteTime(folder.FullName), lastWriteTime);
            }

            Console.WriteLine();
        }
Exemple #4
0
        public void AlphaFS_Volume_DefineDosDevice_SymbolicLinkDriveMapping(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();
                var drive  = string.Format(CultureInfo.InvariantCulture, @"{0}:\", Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter(true));

                Assert.IsFalse(System.IO.Directory.Exists(drive), "The drive exists, but it is expected not to.");


                try
                {
                    Alphaleonis.Win32.Filesystem.Volume.DefineDosDevice(drive, folder.FullName, Alphaleonis.Win32.Filesystem.DosDeviceAttributes.RawTargetPath);


                    // Remove Symbolic Link, no exact match: fail.

                    ExceptionAssert.FileNotFoundException(() => Alphaleonis.Win32.Filesystem.Volume.DeleteDosDevice(drive, folder.FullName));
                }
                finally
                {
                    // Remove Symbolic Link, exact match: success.

                    Alphaleonis.Win32.Filesystem.Volume.DeleteDosDevice(drive, folder.FullName, true);

                    Assert.IsFalse(System.IO.Directory.Exists(drive), "The drive exists, but it is expected not to.");
                }
            }

            Console.WriteLine();
        }
        private void File_Move_FileOpenedWithFileShareDeleteFlag(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                var srcFile = System.IO.Path.Combine(folder.FullName, tempRoot.RandomString);

                var dstFile = System.IO.Path.Combine(folder.FullName, tempRoot.RandomString);

                Console.WriteLine("Src File Path: [{0}]", srcFile);
                Console.WriteLine("Dst File Path: [{0}]", dstFile);


                using (System.IO.File.Open(srcFile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite | System.IO.FileShare.Delete))
                {
                    Alphaleonis.Win32.Filesystem.File.Move(srcFile, dstFile);


                    Assert.IsFalse(Alphaleonis.Win32.Filesystem.File.Exists(srcFile));

                    Assert.IsTrue(Alphaleonis.Win32.Filesystem.File.Exists(dstFile));
                }
            }

            Console.WriteLine();
        }
Exemple #6
0
        private void AlphaFS_Directory_GetFileInfoByHandle(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);


                var bhfi = Alphaleonis.Win32.Filesystem.Directory.GetFileInfoByHandle(folder.FullName);

                UnitTestConstants.Dump(bhfi);


                Assert.IsNotNull(bhfi);

                Assert.AreEqual(folder.CreationTimeUtc, bhfi.CreationTimeUtc);

                Assert.AreEqual(folder.LastAccessTimeUtc, bhfi.LastAccessTimeUtc);

                Assert.AreEqual(folder.LastWriteTimeUtc, bhfi.LastWriteTimeUtc);
            }

            Console.WriteLine();
        }
Exemple #7
0
        private void AlphaFS_Directory_SetTimestampsOnSymbolicLink(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                var symlinkPath = System.IO.Path.Combine(tempRoot.Directory.FullName, tempRoot.RandomString) + "_symlink";

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);
                Console.WriteLine("Input SymLink Path  : [{0}]", symlinkPath);


                Alphaleonis.Win32.Filesystem.Directory.CreateSymbolicLink(symlinkPath, folder.FullName);


                var rnd = new Random();

                var creationTime   = new DateTime(rnd.Next(1971, 2071), rnd.Next(1, 12), rnd.Next(1, 28), rnd.Next(0, 23), rnd.Next(0, 59), rnd.Next(0, 59));
                var lastAccessTime = new DateTime(rnd.Next(1971, 2071), rnd.Next(1, 12), rnd.Next(1, 28), rnd.Next(0, 23), rnd.Next(0, 59), rnd.Next(0, 59));
                var lastWriteTime  = new DateTime(rnd.Next(1971, 2071), rnd.Next(1, 12), rnd.Next(1, 28), rnd.Next(0, 23), rnd.Next(0, 59), rnd.Next(0, 59));


                Alphaleonis.Win32.Filesystem.Directory.SetTimestamps(folder.FullName, creationTime, lastAccessTime, lastWriteTime);


                Assert.AreEqual(System.IO.Directory.GetCreationTime(folder.FullName), creationTime);
                Assert.AreEqual(System.IO.Directory.GetLastAccessTime(folder.FullName), lastAccessTime);
                Assert.AreEqual(System.IO.Directory.GetLastWriteTime(folder.FullName), lastWriteTime);


                // SymbolicLink
                Alphaleonis.Win32.Filesystem.Directory.SetTimestamps(symlinkPath, creationTime.AddDays(1), lastAccessTime.AddDays(1), lastWriteTime.AddDays(1), true, Alphaleonis.Win32.Filesystem.PathFormat.RelativePath);
                Assert.AreEqual(System.IO.Directory.GetCreationTime(symlinkPath), Alphaleonis.Win32.Filesystem.Directory.GetCreationTime(symlinkPath));
                Assert.AreEqual(System.IO.Directory.GetLastAccessTime(symlinkPath), Alphaleonis.Win32.Filesystem.Directory.GetLastAccessTime(symlinkPath));
                Assert.AreEqual(System.IO.Directory.GetLastWriteTime(symlinkPath), Alphaleonis.Win32.Filesystem.Directory.GetLastWriteTime(symlinkPath));


                creationTime   = new DateTime(rnd.Next(1971, 2071), rnd.Next(1, 12), rnd.Next(1, 28), rnd.Next(0, 23), rnd.Next(0, 59), rnd.Next(0, 59));
                lastAccessTime = new DateTime(rnd.Next(1971, 2071), rnd.Next(1, 12), rnd.Next(1, 28), rnd.Next(0, 23), rnd.Next(0, 59), rnd.Next(0, 59));
                lastWriteTime  = new DateTime(rnd.Next(1971, 2071), rnd.Next(1, 12), rnd.Next(1, 28), rnd.Next(0, 23), rnd.Next(0, 59), rnd.Next(0, 59));


                Alphaleonis.Win32.Filesystem.Directory.SetTimestampsUtc(folder.FullName, creationTime, lastAccessTime, lastWriteTime);


                Assert.AreEqual(System.IO.Directory.GetCreationTimeUtc(folder.FullName), creationTime);
                Assert.AreEqual(System.IO.Directory.GetLastAccessTimeUtc(folder.FullName), lastAccessTime);
                Assert.AreEqual(System.IO.Directory.GetLastWriteTimeUtc(folder.FullName), lastWriteTime);


                // SymbolicLink
                Alphaleonis.Win32.Filesystem.Directory.SetTimestampsUtc(symlinkPath, creationTime.AddDays(1), lastAccessTime.AddDays(1), lastWriteTime.AddDays(1), true, Alphaleonis.Win32.Filesystem.PathFormat.RelativePath);
                Assert.AreEqual(System.IO.Directory.GetCreationTimeUtc(symlinkPath), Alphaleonis.Win32.Filesystem.File.GetCreationTimeUtc(symlinkPath));
                Assert.AreEqual(System.IO.Directory.GetLastAccessTimeUtc(symlinkPath), Alphaleonis.Win32.Filesystem.File.GetLastAccessTimeUtc(symlinkPath));
                Assert.AreEqual(System.IO.Directory.GetLastWriteTimeUtc(symlinkPath), Alphaleonis.Win32.Filesystem.File.GetLastWriteTimeUtc(symlinkPath));
            }

            Console.WriteLine();
        }
        private void Directory_SetAccessControl(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                var sysIO            = System.IO.Directory.GetAccessControl(folder.FullName);
                var sysIOaccessRules = sysIO.GetAccessRules(true, true, typeof(NTAccount));

                var alphaFS            = Alphaleonis.Win32.Filesystem.Directory.GetAccessControl(folder.FullName);
                var alphaFSaccessRules = alphaFS.GetAccessRules(true, true, typeof(NTAccount));


                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);
                Console.WriteLine("\n\tSystem.IO rules found: [{0}]\n\tAlphaFS rules found  : [{1}]", sysIOaccessRules.Count, alphaFSaccessRules.Count);
                Assert.AreEqual(sysIOaccessRules.Count, alphaFSaccessRules.Count);


                // Sanity check.
                UnitTestConstants.TestAccessRules(sysIO, alphaFS);


                // Remove inherited properties.
                // Passing true for first parameter protects the new permission from inheritance,
                // and second parameter removes the existing inherited permissions
                Console.WriteLine("\n\tRemove inherited properties and persist it.");
                alphaFS.SetAccessRuleProtection(true, false);
                Alphaleonis.Win32.Filesystem.Directory.SetAccessControl(folder.FullName, alphaFS, AccessControlSections.Access);


                // Re-read, using instance methods.
                var sysIOdi   = new System.IO.DirectoryInfo(folder.FullName);
                var alphaFSdi = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder.FullName);

                sysIO   = sysIOdi.GetAccessControl(AccessControlSections.Access);
                alphaFS = alphaFSdi.GetAccessControl(AccessControlSections.Access);

                // Sanity check.
                UnitTestConstants.TestAccessRules(sysIO, alphaFS);


                // Restore inherited properties.
                Console.WriteLine("\n\tRestore inherited properties and persist it.");
                alphaFS.SetAccessRuleProtection(false, true);
                Alphaleonis.Win32.Filesystem.Directory.SetAccessControl(folder.FullName, alphaFS, AccessControlSections.Access);


                // Re-read.
                sysIO   = System.IO.Directory.GetAccessControl(folder.FullName, AccessControlSections.Access);
                alphaFS = Alphaleonis.Win32.Filesystem.Directory.GetAccessControl(folder.FullName, AccessControlSections.Access);

                // Sanity check.
                UnitTestConstants.TestAccessRules(sysIO, alphaFS);
            }

            Console.WriteLine();
        }
Exemple #9
0
        private void DirectoryInfo_InitializeInstance_ExistingDirectory(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

                CompareDirectoryInfos(folder, new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder.FullName), true);
            }

            Console.WriteLine();
        }
Exemple #10
0
        private void AnalyzeDirectoryInfoSecurity_ShouldNotExist(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);


                SetSecuritySystem(folder.FullName);

                var dirsec = new System.IO.DirectoryInfo(folder.FullName + @"\inherited").GetAccessControl();

                var accessRules = dirsec.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));

                UnitTestConstants.Dump(dirsec);

                Assert.IsFalse(HasLocalAces(accessRules), "Local access rules are found, but it is not expected.");



                folder = tempRoot.CreateDirectory();

                Console.WriteLine("\nInput Directory Path: [{0}]", folder.FullName);

                SetSecurityAlpha(folder.FullName);

                dirsec = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder.FullName + @"\inherited").GetAccessControl();

                accessRules = dirsec.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));

                UnitTestConstants.Dump(dirsec);

                Assert.IsFalse(HasLocalAces(accessRules), "Local access rules are found, but it is not expected.");
            }

            Console.WriteLine();
        }
        private void File_Delete_ThrowUnauthorizedAccessException_PathIsADirectoryNotAFile(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

                ExceptionAssert.UnauthorizedAccessException(() => System.IO.File.Delete(folder.FullName));

                ExceptionAssert.UnauthorizedAccessException(() => Alphaleonis.Win32.Filesystem.File.Delete(folder.FullName));
            }

            Console.WriteLine();
        }
        private void AlphaFS_Directory_EnableEncryption_And_DisableEncryption(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]\n", folder.FullName);


                var deskTopIni = System.IO.Path.Combine(folder.FullName, "Desktop.ini");
                var enabled    = new[] { "[Encryption]", "Disable=0" };
                var disabled   = new[] { "[Encryption]", "Disable=1" };


                // Enable.
                Alphaleonis.Win32.Filesystem.Directory.EnableEncryption(folder.FullName);


                // Read Desktop.ini file.
                var collection = System.IO.File.ReadAllLines(deskTopIni);

                for (int i = 0, l = collection.Length; i < l; i++)
                {
                    Console.WriteLine("\t" + collection[i]);
                }
                Console.WriteLine();

                CollectionAssert.AreEqual(enabled, collection);



                // Disable.
                Alphaleonis.Win32.Filesystem.Directory.DisableEncryption(folder.FullName);


                // Read Desktop.ini file.
                collection = System.IO.File.ReadAllLines(deskTopIni);

                for (int i = 0, l = collection.Length; i < l; i++)
                {
                    Console.WriteLine("\t" + collection[i]);
                }

                CollectionAssert.AreEqual(disabled, collection);
            }

            Console.WriteLine();
        }
Exemple #13
0
        private void AlphaFS_Directory_Move_ThrowAlreadyExistsException_DestinationDirectoryAlreadyExists(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var srcFolder  = tempRoot.CreateTree();
                var dstFfolder = tempRoot.CreateDirectory();

                Console.WriteLine("Src Directory Path: [{0}]", srcFolder.FullName);
                Console.WriteLine("Dst Directory Path: [{0}]", dstFfolder.FullName);

                ExceptionAssert.IOException(() => System.IO.Directory.Move(srcFolder.FullName, dstFfolder.FullName));

                ExceptionAssert.AlreadyExistsException(() => Alphaleonis.Win32.Filesystem.Directory.Move(srcFolder.FullName, dstFfolder.FullName));
            }

            Console.WriteLine();
        }
        private void Directory_Exists_ExistingDirectory(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

                var existsSysIO = System.IO.Directory.Exists(folder.FullName);

                var existsAlpha = Alphaleonis.Win32.Filesystem.Directory.Exists(folder.FullName);


                Assert.AreEqual(existsSysIO, existsAlpha);
            }


            Console.WriteLine();
        }
        private void AlphaFS_Directory_GetFileIdInfo(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);


                var fid = Alphaleonis.Win32.Filesystem.Directory.GetFileIdInfo(folder.FullName);

                Console.WriteLine("\n\tToString(): {0}", fid);


                Assert.IsNotNull(fid);
            }

            Console.WriteLine();
        }
Exemple #16
0
        private void Directory_Move_ThrowUnauthorizedAccessException_UserExplicitDenyOnDestinationFolder(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var srcFolder = tempRoot.CreateTree();
                var dstFolder = tempRoot.CreateDirectory();

                Console.WriteLine("Src Directory Path: [{0}]", srcFolder.FullName);
                Console.WriteLine("Dst Directory Path: [{0}]", dstFolder.FullName);


                var user = (Environment.UserDomainName + @"\" + Environment.UserName).TrimStart('\\');

                var rule = new System.Security.AccessControl.FileSystemAccessRule(user,
                                                                                  System.Security.AccessControl.FileSystemRights.FullControl,
                                                                                  System.Security.AccessControl.InheritanceFlags.ContainerInherit |
                                                                                  System.Security.AccessControl.InheritanceFlags.ObjectInherit,
                                                                                  System.Security.AccessControl.PropagationFlags.None,
                                                                                  System.Security.AccessControl.AccessControlType.Deny);


                // Set DENY for current user.
                var dirSecurity = dstFolder.GetAccessControl();
                dirSecurity.AddAccessRule(rule);
                dstFolder.SetAccessControl(dirSecurity);


                try
                {
                    ExceptionAssert.UnauthorizedAccessException(() => Alphaleonis.Win32.Filesystem.Directory.Move(srcFolder.FullName, dstFolder.FullName, Alphaleonis.Win32.Filesystem.MoveOptions.ReplaceExisting));
                }
                finally
                {
                    // Remove DENY for current user.
                    dirSecurity = dstFolder.GetAccessControl();
                    dirSecurity.RemoveAccessRule(rule);
                    dstFolder.SetAccessControl(dirSecurity);
                }
            }

            Console.WriteLine();
        }
Exemple #17
0
        private void AlphaFS_Directory_Delete_ThrowsDirectoryNotEmptyException_NonEmptyDirectory(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                var file = System.IO.Path.Combine(folder.FullName, tempRoot.RandomTxtFileName);

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);
                Console.WriteLine("Input File Path     : [{0}]", file);

                using (System.IO.File.Create(System.IO.Path.Combine(folder.FullName, file))) { }

                UnitTestAssert.ThrowsException <System.IO.IOException>(() => System.IO.Directory.Delete(folder.FullName));

                UnitTestAssert.ThrowsException <Alphaleonis.Win32.Filesystem.DirectoryNotEmptyException>(() => Alphaleonis.Win32.Filesystem.Directory.Delete(folder.FullName));
            }

            Console.WriteLine();
        }
Exemple #18
0
        private void AlphaFS_Volume_DefineDosDevice_RegularDriveMapping(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();
                var drive  = Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter() + ":";

                Assert.IsFalse(System.IO.Directory.Exists(drive), "The drive exists, but it is expected not to.");


                try
                {
                    Alphaleonis.Win32.Filesystem.Volume.DefineDosDevice(drive, folder.FullName);

                    Assert.IsTrue(System.IO.Directory.Exists(drive), "The drive does not exists, but it is expected to.");


                    var dirInfoSysIO = new System.IO.DriveInfo(drive);

                    var dirInfoAlphaFS = new Alphaleonis.Win32.Filesystem.DriveInfo(drive);

                    UnitTestConstants.Dump(dirInfoSysIO, -21);
                    UnitTestConstants.Dump(dirInfoAlphaFS, -21);


                    Assert.AreEqual(dirInfoSysIO.Name, dirInfoAlphaFS.Name);

                    Assert.AreEqual(dirInfoSysIO.DriveType, dirInfoAlphaFS.DriveType);

                    Assert.AreEqual(dirInfoSysIO.TotalSize, dirInfoAlphaFS.TotalSize);
                }
                finally
                {
                    Alphaleonis.Win32.Filesystem.Volume.DeleteDosDevice(drive);

                    Assert.IsFalse(System.IO.Directory.Exists(drive), "The drive exists, but it is expected not to.");
                }
            }

            Console.WriteLine();
        }
        private void Directory_GetFiles_WithSearchPattern(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]\n", folder.FullName);

                var count   = 0;
                var folders = new[]
                {
                    tempRoot.RandomString, tempRoot.RandomDirectoryName, tempRoot.RandomTxtFileName, tempRoot.RandomString, tempRoot.RandomDirectoryName,
                    tempRoot.RandomTxtFileName, tempRoot.RandomString, tempRoot.RandomDirectoryName, tempRoot.RandomTxtFileName, tempRoot.RandomString
                };


                foreach (var folderName in folders)
                {
                    var newFolder = System.IO.Path.Combine(folder.FullName, folderName);

                    System.IO.File.AppendAllText(newFolder + (count++ % 2 == 0 ? string.Empty : "-uneven"), DateTime.Now.ToString(CultureInfo.CurrentCulture));
                }


                var folderCount = 0;

                foreach (var folderResult in folders)
                {
                    var systemIOCollection = System.IO.Directory.GetFiles(folder.FullName, folderResult, System.IO.SearchOption.AllDirectories);

                    var alphaFSCollection = Alphaleonis.Win32.Filesystem.Directory.GetFiles(folder.FullName, folderResult, System.IO.SearchOption.AllDirectories);

                    Console.WriteLine("\t#{0:000}\t{1}", ++folderCount, folderResult);

                    CollectionAssert.AreEquivalent(systemIOCollection, alphaFSCollection);
                }
            }

            Console.WriteLine();
        }
Exemple #20
0
        public void AlphaFS_Volume_SetVolumeMountPoint_And_DeleteVolumeMountPoint_Local_Success()
        {
            UnitTestAssert.IsElevatedProcess();

            using (var tempRoot = new TemporaryDirectory())
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

                var guid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(UnitTestConstants.SysDrive);


                Console.WriteLine("\nCreate mount point.");

                Alphaleonis.Win32.Filesystem.Volume.SetVolumeMountPoint(folder.FullName, guid);


                Assert.IsTrue(Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumeMountPoints(guid).Any(mountPoint => folder.FullName.EndsWith(mountPoint.TrimEnd('\\'))));



                var lvi = Alphaleonis.Win32.Filesystem.Directory.GetLinkTargetInfo(folder.FullName);

                UnitTestConstants.Dump(lvi, -14);

                Assert.IsTrue(lvi.SubstituteName.StartsWith(Alphaleonis.Win32.Filesystem.Path.NonInterpretedPathPrefix));

                Assert.IsTrue(lvi.SubstituteName.EndsWith(guid.Replace(Alphaleonis.Win32.Filesystem.Path.LongPathPrefix, string.Empty)));



                Console.WriteLine("\nRemove mount point.");

                Alphaleonis.Win32.Filesystem.Volume.DeleteVolumeMountPoint(folder.FullName);

                Assert.IsFalse(Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumeMountPoints(guid).Any(mountPoint => folder.FullName.EndsWith(mountPoint.TrimEnd('\\'))));
            }
        }
Exemple #21
0
        private void AlphaFS_Directory_CopyTimestamps(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folderSrc = tempRoot.CreateRecursiveRandomizedDatesAndAttributesTree(5);
                var folderDst = tempRoot.CreateDirectory();

                Console.WriteLine("Src Directory Path: [{0}]", folderSrc.FullName);
                Console.WriteLine("Dst Directory Path: [{0}]", folderDst);


                var creationTime   = tempRoot.GetRandomFileDate();
                var lastAccessTime = tempRoot.GetRandomFileDate();
                var lastWriteTime  = tempRoot.GetRandomFileDate();


                Alphaleonis.Win32.Filesystem.Directory.SetTimestamps(folderSrc.FullName, creationTime, lastAccessTime, lastWriteTime);

                Assert.AreEqual(System.IO.Directory.GetCreationTimeUtc(folderSrc.FullName), folderSrc.CreationTimeUtc);
                Assert.AreEqual(System.IO.Directory.GetLastAccessTimeUtc(folderSrc.FullName), folderSrc.LastAccessTimeUtc);
                Assert.AreEqual(System.IO.Directory.GetLastWriteTimeUtc(folderSrc.FullName), folderSrc.LastWriteTimeUtc);


                Alphaleonis.Win32.Filesystem.Directory.CopyTimestamps(folderSrc.FullName, folderDst.FullName);


                UnitTestConstants.Dump(folderDst);


                Assert.AreEqual(System.IO.Directory.GetCreationTimeUtc(folderSrc.FullName), folderDst.CreationTimeUtc);
                Assert.AreEqual(System.IO.Directory.GetLastAccessTimeUtc(folderSrc.FullName), folderDst.LastAccessTimeUtc);
                Assert.AreEqual(System.IO.Directory.GetLastWriteTimeUtc(folderSrc.FullName), folderDst.LastWriteTimeUtc);
            }

            Console.WriteLine();
        }
Exemple #22
0
        private void Directory_GetAccessControl(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.CreateDirectory();

                Console.WriteLine("Input Directory Path: [{0}]", folder.FullName);

                var foundRules = false;

                var sysIO            = System.IO.File.GetAccessControl(folder.FullName);
                var sysIOaccessRules = sysIO.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

                var alphaFS            = System.IO.File.GetAccessControl(folder.FullName);
                var alphaFSaccessRules = alphaFS.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

                Console.WriteLine("\n\tSystem.IO rules found: [{0}]\n\tAlphaFS rules found  : [{1}]", sysIOaccessRules.Count, alphaFSaccessRules.Count);


                Assert.AreEqual(sysIOaccessRules.Count, alphaFSaccessRules.Count);


                foreach (var far in alphaFSaccessRules)
                {
                    UnitTestConstants.Dump(far, -17);

                    UnitTestConstants.TestAccessRules(sysIO, alphaFS);

                    foundRules = true;
                }

                Assert.IsTrue(foundRules);
            }

            Console.WriteLine();
        }
        public void AlphaFS_Directory_CreateJunction_FromMappedDrive_ThrowsArgumentException_Netwerk_Success()
        {
            using (var tempRoot = new TemporaryDirectory())
                using (var connection = new Alphaleonis.Win32.Network.DriveConnection(Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempRoot.CreateDirectory().FullName)))
                {
                    var mappedPath = connection.LocalName + @"\" + tempRoot.RandomDirectoryName;

                    Console.WriteLine("Mapped drive [{0}] to [{1}]", connection.LocalName, connection.Share);

                    var target = System.IO.Directory.CreateDirectory(mappedPath);

                    var toDelete = tempRoot.Directory.CreateSubdirectory("ToDelete");

                    var junction = System.IO.Path.Combine(toDelete.FullName, "JunctionPoint");

                    UnitTestAssert.ThrowsException <ArgumentException>(() => Alphaleonis.Win32.Filesystem.Directory.CreateJunction(junction, target.FullName));
                }
        }