コード例 #1
0
        private void EnumerateOpenResources(string host)
        {
            UnitTestConstants.PrintUnitTestHeader(false);

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            Console.WriteLine("\nConnected to Host: [{0}]", host);


            var cnt = 0;

            foreach (var openResourceInfo in Alphaleonis.Win32.Network.Host.EnumerateOpenResources(host, null, null, false))
            {
                if (UnitTestConstants.Dump(openResourceInfo, -11))
                {
                    cnt++;
                }

                Console.WriteLine();
            }


            if (cnt == 0)
            {
                Assert.Inconclusive("Nothing is enumerated, but it is expected. Try another server name if applicable.");
            }

            Console.WriteLine();
        }
コード例 #2
0
        public void AlphaFS_File_CreateHardlink_And_EnumerateHardlinks_Local_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            File_CreateHardlink_And_EnumerateHardlinks(false);
        }
コード例 #3
0
        public void DirectoryInfo_MoveTo_DelayUntilReboot_Local_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            DirectoryInfo_MoveTo_DelayUntilReboot(false);
        }
コード例 #4
0
ファイル: File_Create.cs プロジェクト: jdstroy/AlphaFS
        public void File_Create_WithFileSecurity_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            File_Create_WithFileSecurity(false);
            File_Create_WithFileSecurity(true);
        }
コード例 #5
0
        public void Directory_SetAccessControl_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            Directory_SetAccessControl(false);
            Directory_SetAccessControl(true);
        }
コード例 #6
0
        public void AlphaFS_File_SetTimestampsXxx_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            File_SetTimestampsXxx(false);
            File_SetTimestampsXxx(true);
        }
コード例 #7
0
        public void AlphaFS_Volume_GetVolumeInfo_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            Volume_GetVolumeInfo_FromLogicalDrive(false);
            Volume_GetVolumeInfo_FromLogicalDrive(true);
        }
コード例 #8
0
        public void AlphaFS_File_CreateSymbolicLink_And_GetLinkTargetInfo_LocalUNC_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            File_CreateSymbolicLink_GetLinkTargetInfo(false);
            File_CreateSymbolicLink_GetLinkTargetInfo(true);
        }
コード例 #9
0
        public void AlphaFS_Directory_CreateSymbolicLink_And_GetLinkTargetInfo_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            Directory_CreateSymbolicLink_And_GetLinkTargetInfo(false);
            Directory_CreateSymbolicLink_And_GetLinkTargetInfo(true);
        }
コード例 #10
0
        public void AlphaFS_Directory_CreateSymbolicLink_CatchIOException_FileExistsWithSameNameAsDirectory_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            Directory_CreateSymbolicLink_CatchIOException_FileExistsWithSameNameAsDirectory(false);
            Directory_CreateSymbolicLink_CatchIOException_FileExistsWithSameNameAsDirectory(true);
        }
コード例 #11
0
        public void AlphaFS_Class_Network_OpenConnectionInfo()
        {
            Console.WriteLine("Class Network.OpenConnectionInfo()");

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            DumpOpenConnectionInfo(UnitTestConstants.LocalHost);
        }
コード例 #12
0
        public void AlphaFS_Class_Network_OpenResourceInfo()
        {
            Console.WriteLine("Class Network.OpenResourceInfo()");

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            DumpClassOpenResourceInfo(UnitTestConstants.LocalHost, UnitTestConstants.LocalHostShare);
        }
コード例 #13
0
        public void Directory_CreateDirectory_WithDirectorySecurity_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            Directory_CreateDirectory_WithDirectorySecurity(false);
            Directory_CreateDirectory_WithDirectorySecurity(true);
        }
コード例 #14
0
        public void AlphaFS_File_Copy_CopySymbolicLink_SourceIsASymbolicLink_TargetMustAlsoBeASymbolicLink_LocalAndNetwork_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            File_Copy_CopySymbolicLink_SourceIsASymbolicLink_TargetMustAlsoBeASymbolicLink(false);
            File_Copy_CopySymbolicLink_SourceIsASymbolicLink_TargetMustAlsoBeASymbolicLink(true);
        }
コード例 #15
0
        public void AlphaFS_Volume_EnumerateVolumeMountPoints()
        {
            Console.WriteLine("Volume.EnumerateVolumeMountPoints()");

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            #region Logical Drives

            var cnt = 0;
            Console.WriteLine("\nLogical Drives\n");

            // Get Logical Drives from UnitTestConstants.Local Host, .IsReady Drives only.
            foreach (var drive in Directory.GetLogicalDrives(false, true))
            {
                try
                {
                    // Logical Drives --> Volumes --> Volume Mount Points.
                    var uniqueVolName = Volume.GetUniqueVolumeNameForPath(drive);

                    if (!string.IsNullOrWhiteSpace(uniqueVolName) && !uniqueVolName.Equals(drive, StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (var mountPoint in Volume.EnumerateVolumeMountPoints(uniqueVolName).Where(mp => !string.IsNullOrWhiteSpace(mp)))
                        {
                            UnitTestConstants.StopWatcher(true);

                            string guid = null;
                            try { guid = Volume.GetVolumeGuid(Path.Combine(drive, mountPoint)); }
                            catch (Exception ex)
                            {
                                Console.WriteLine("\n\tCaught (unexpected #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                            }

                            Console.WriteLine("\t#{0:000}\tLogical Drive: [{1}]\tGUID: [{2}]\n\t\tDestination  : [{3}]\n\t{4}", ++cnt, drive, guid ?? "null", mountPoint, UnitTestConstants.Reporter(true));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\n\tCaught (unexpected #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                }
            }


            if (cnt == 0)
            {
                Assert.Inconclusive("No Volume Mount Points found.");
            }

            #endregion // Logical Drives
        }
コード例 #16
0
        public void AlphaFS_Host_GetWorkstationStatistics_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            var workstationStat = Alphaleonis.Win32.Network.Host.GetWorkstationStatistics();

            UnitTestConstants.Dump(workstationStat, -36);
        }
コード例 #17
0
        public void AlphaFS_Volume_SetVolumeMountPoint_And_DeleteVolumeMountPoint_Local_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            UnitTestConstants.PrintUnitTestHeader(false);


            var tempPath = UnitTestConstants.TempFolder;

            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                var dirInfo = System.IO.Directory.CreateDirectory(rootDir.RandomDirectoryFullPath);

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


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



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

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


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



                var lvi = Alphaleonis.Win32.Filesystem.Directory.GetLinkTargetInfo(dirInfo.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(dirInfo.FullName);

                Assert.IsFalse(Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumeMountPoints(guid).Any(mountPoint => dirInfo.FullName.EndsWith(mountPoint.TrimEnd('\\'))));
            }
        }
        public void AlphaFS_Volume_EnumerateVolumeMountPoints_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);
            Console.WriteLine();

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            var cnt = 0;

            Console.WriteLine("Logical Drives\n");

            // Get Logical Drives from UnitTestConstants.Local Host, .IsReady Drives only.
            foreach (var drive in Alphaleonis.Win32.Filesystem.Directory.GetLogicalDrives(false, true))
            {
                try
                {
                    // Logical Drives --> Volumes --> Volume Mount Points.
                    var uniqueVolName = Alphaleonis.Win32.Filesystem.Volume.GetUniqueVolumeNameForPath(drive);

                    if (!Alphaleonis.Utils.IsNullOrWhiteSpace(uniqueVolName) && !uniqueVolName.Equals(drive, StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (var mountPoint in Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumeMountPoints(uniqueVolName).Where(mp => !Alphaleonis.Utils.IsNullOrWhiteSpace(mp)))
                        {
                            string guid = null;
                            try { guid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(System.IO.Path.Combine(drive, mountPoint)); }
                            catch (Exception ex)
                            {
                                Console.WriteLine("\n\tCaught (UNEXPECTED #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                            }

                            Console.WriteLine("\t#{0:000}\tLogical Drive: [{1}]\tGUID: [{2}]\n\t\tDestination  : [{3}]\n", ++cnt, drive, guid ?? "null", mountPoint);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\n\tCaught (UNEXPECTED #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                }
            }


            if (cnt == 0)
            {
                Assert.Inconclusive("No Volume Mount Points found.");
            }
        }
コード例 #19
0
        public void AlphaFS_Host_EnumerateDrives_Network_Success()
        {
            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            UnitTestConstants.PrintUnitTestHeader(true);

            var host = UnitTestConstants.LocalHost;

            var drives = Alphaleonis.Win32.Network.Host.EnumerateDrives(host, true).ToList();

            foreach (var driveInfo in drives)
            {
                Console.WriteLine("\nHost Local Drive: [{0}]", driveInfo.Name);


                UnitTestConstants.Dump(driveInfo, -21);
                UnitTestConstants.Dump(driveInfo.DiskSpaceInfo, -26, true);
                UnitTestConstants.Dump(driveInfo.VolumeInfo, -26, true);


                Assert.IsNull(driveInfo.DosDeviceName);
                Assert.IsNull(driveInfo.VolumeInfo.Guid);

                Console.WriteLine();
            }


            Assert.IsTrue(drives.Count > 0, "Nothing is enumerated, but it is expected.");


            // \\localhost\C$

            host = Alphaleonis.Win32.Network.Host.GetUncName() + Alphaleonis.Win32.Filesystem.Path.DirectorySeparator +
                   UnitTestConstants.SysDrive[0] + Alphaleonis.Win32.Filesystem.Path.NetworkDriveSeparator +
                   Alphaleonis.Win32.Filesystem.Path.DirectorySeparator;

            Assert.AreEqual(drives[0].Name, host);
        }
コード例 #20
0
        public void SetVolumeLabel()
        {
            Console.WriteLine("Volume.SetVolumeLabel()");

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            const string newLabel = "ÂĽpĥæƑŞ ŠëtVőlümèĻāßƩl() Ťest";
            const string template = "\nSystem Drive: [{0}]\tCurrent Label: [{1}]";
            string       drive    = UnitTestConstants.SysDrive;

            #region Get Label

            string originalLabel = Volume.GetVolumeLabel(drive);
            Console.WriteLine(template, drive, originalLabel);

            Assert.IsTrue(originalLabel.Equals(Volume.GetVolumeLabel(drive)));

            #endregion // Get Label

            #region Set Label

            bool   isLabelSet   = false;
            string currentLabel = Volume.GetVolumeLabel(drive);
            try
            {
                Volume.SetVolumeLabel(drive, newLabel);
                isLabelSet = true;

                Console.WriteLine(template, drive, newLabel);
                Console.WriteLine("Set label.");
                Assert.IsTrue(!currentLabel.Equals(newLabel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            Assert.IsTrue(isLabelSet);

            #endregion // Set Label

            #region Remove Label

            bool isLabelRemoved = false;
            try
            {
                Volume.DeleteVolumeLabel(drive);
                isLabelRemoved = true;

                currentLabel = Volume.GetVolumeLabel(drive);

                Console.WriteLine(template, drive, currentLabel);
                Console.WriteLine("Removed label.");
                Assert.IsTrue(currentLabel.Equals(string.Empty));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            Assert.IsTrue(isLabelRemoved);

            #endregion // Remove Label

            #region Restore Label

            isLabelSet = false;
            try
            {
                Volume.SetVolumeLabel(drive, originalLabel);
                isLabelSet = true;

                currentLabel = Volume.GetVolumeLabel(drive);

                Console.WriteLine(template, drive, currentLabel);
                Console.WriteLine("Restored label.");
                Assert.IsTrue(currentLabel.Equals(originalLabel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            Assert.IsTrue(isLabelSet);

            #endregion // Restore Label
        }
コード例 #21
0
        public void AlphaFS_Volume_SetVolumeLabel_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);
            Console.WriteLine();

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            const string newLabel = "ÂĽpĥæƑŞ ŠëtVőlümèĻāßƩl() Ťest";
            const string template = "\nSystem Drive: [{0}]\tCurrent Label: [{1}]";
            var          drive    = UnitTestConstants.SysDrive;


            #region Get Label

            var originalLabel = Alphaleonis.Win32.Filesystem.Volume.GetVolumeLabel(drive);
            Console.WriteLine(template, drive, originalLabel);

            Assert.IsTrue(originalLabel.Equals(Alphaleonis.Win32.Filesystem.Volume.GetVolumeLabel(drive)));

            #endregion // Get Label


            #region Set Label

            var isLabelSet   = false;
            var currentLabel = Alphaleonis.Win32.Filesystem.Volume.GetVolumeLabel(drive);
            try
            {
                Alphaleonis.Win32.Filesystem.Volume.SetVolumeLabel(drive, newLabel);
                isLabelSet = true;

                Console.WriteLine(template, drive, newLabel);
                Console.WriteLine("Set label.");
                Assert.IsTrue(!currentLabel.Equals(newLabel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nCaught (UNEXPECTED) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            Assert.IsTrue(isLabelSet);

            #endregion // Set Label


            #region Remove Label

            var isLabelRemoved = false;
            try
            {
                Alphaleonis.Win32.Filesystem.Volume.DeleteVolumeLabel(drive);
                isLabelRemoved = true;

                currentLabel = Alphaleonis.Win32.Filesystem.Volume.GetVolumeLabel(drive);

                Console.WriteLine(template, drive, currentLabel);
                Console.WriteLine("Removed label.");
                Assert.IsTrue(currentLabel.Equals(string.Empty));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nCaught (UNEXPECTED) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            Assert.IsTrue(isLabelRemoved);

            #endregion // Remove Label


            #region Restore Label

            isLabelSet = false;
            try
            {
                Alphaleonis.Win32.Filesystem.Volume.SetVolumeLabel(drive, originalLabel);
                isLabelSet = true;

                currentLabel = Alphaleonis.Win32.Filesystem.Volume.GetVolumeLabel(drive);

                Console.WriteLine(template, drive, currentLabel);
                Console.WriteLine("Restored label.");
                Assert.IsTrue(currentLabel.Equals(originalLabel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nCaught (UNEXPECTED) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            Assert.IsTrue(isLabelSet);

            #endregion // Restore Label
        }
コード例 #22
0
        public void AlphaFS_Volume_DefineDosDevice()
        {
            Console.WriteLine("Volume.DefineDosDevice()");

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            #region Regular Drive Mapping

            var drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar);
            UnitTestConstants.StopWatcher(true);

            // Create Regular drive mapping.
            var actionIsTrue = false;
            try
            {
                Volume.DefineDosDevice(drive, TempFolder);
                actionIsTrue = true;
            }
            catch
            {
            }

            Console.WriteLine("\nCreated Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", actionIsTrue, drive, TempFolder, UnitTestConstants.Reporter(true));
            Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been created.");

            var di      = new DriveInfo(drive);
            var diSysIo = new System.IO.DriveInfo(drive);

            try
            {
                Assert.IsTrue(UnitTestConstants.Dump(di, -21));

                // A Regular drive mapping that should be visible immediately in Explorer.
                // Seems to be invisible in Explorer on Windows 8, but visibile in an elevated cmd shell.
                //Assert.IsTrue(Directory.Exists(_driveLetter), "Drive letter not visible.");

                Console.WriteLine("\nDrive Letter: [{0}]\tGetVolumeDevice(): [{1}]", drive, Volume.GetVolumeDeviceName(drive));
                Assert.AreEqual(diSysIo.IsReady, di.IsReady);
            }
            finally
            {
                UnitTestConstants.StopWatcher(true);

                // Remove Regular drive mapping.
                actionIsTrue = false;
                try
                {
                    Volume.DeleteDosDevice(drive);
                    actionIsTrue = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nRemoved Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\n\t{2}\n", actionIsTrue, drive, UnitTestConstants.Reporter(true));
                Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been removed.");
                Assert.IsFalse(Directory.Exists(drive), "Drive letter should not be visible.");
            }

            #endregion // Regular Drive Mapping

            #region Symbolic Link Drive Mapping

            try
            {
                drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(true), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar);
                UnitTestConstants.StopWatcher(true);

                // Create Symbolic Link.
                var createSymbolicLink = false;
                try
                {
                    Volume.DefineDosDevice(drive, TempFolder, DosDeviceAttributes.RawTargetPath);
                    createSymbolicLink = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nCreated Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", createSymbolicLink, drive, TempFolder, UnitTestConstants.Reporter(true));
                Assert.IsTrue(createSymbolicLink);

                di = new DriveInfo(drive);
                Assert.IsTrue(UnitTestConstants.Dump(di, -21));

                // The link is created in the NT Device Name namespace and thus not visibile in Explorer.

                // Remove Symbolic Link, no exact match: fail.
                UnitTestConstants.StopWatcher(true);

                var removeSymbolicLink = false;
                try
                {
                    Volume.DeleteDosDevice(drive, "NonExistingFolder", true);
                    removeSymbolicLink = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be False): [{0}]\nDrive letter: [{1}] has NOT been set free.\tNo exactMatch MS-DOS device name found.\n\t{2}", removeSymbolicLink, drive, UnitTestConstants.Reporter(true));
                Assert.IsFalse(removeSymbolicLink);
            }
            finally
            {
                UnitTestConstants.StopWatcher(true);

                // Remove Symbolic Link, exact match: success.
                var removeSymbolicLink = false;
                try
                {
                    Volume.DeleteDosDevice(drive, TempFolder, true);
                    removeSymbolicLink = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\tFound exactMatch MS-DOS device name.\n\t{2}", removeSymbolicLink, drive, UnitTestConstants.Reporter(true));
                Assert.IsTrue(removeSymbolicLink);
                Assert.IsFalse(Directory.Exists(drive));
            }

            #endregion // Symbolic Link Drive Mapping
        }
コード例 #23
0
        public void AlphaFS_Volume_SetVolumeMountPoint()
        {
            Console.WriteLine("Volume.SetVolumeMountPoint()");

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }

            #region Logical Drives

            var cnt        = 0;
            var destFolder = Path.Combine(TempFolder, "Volume.SetVolumeMountPoint()-" + Path.GetRandomFileName());
            Directory.CreateDirectory(destFolder);

            var guid = Volume.GetUniqueVolumeNameForPath(UnitTestConstants.SysDrive);

            try
            {
                UnitTestConstants.StopWatcher(true);

                Volume.SetVolumeMountPoint(destFolder, guid);
                Console.WriteLine(
                    "\t#{0:000}\tSystem Drive: [{1}]\tGUID: [{2}]\n\t\tDestination : [{3}]\n\t\tCreated Mount Point.\n\t{4}",
                    ++cnt, UnitTestConstants.SysDrive, guid, destFolder, UnitTestConstants.Reporter(true));

                Console.WriteLine("\n");
                AlphaFS_Volume_EnumerateVolumeMountPoints();

                Console.WriteLine("\n\nFile.GetLinkTargetInfo()");

                var lti = File.GetLinkTargetInfo(destFolder);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(lti.PrintName));
                Assert.IsTrue(!string.IsNullOrWhiteSpace(lti.SubstituteName));
                Assert.IsTrue(UnitTestConstants.Dump(lti, -14), "Unable to dump object.");

                // Cleanup.
                UnitTestConstants.StopWatcher(true);
                var deleteOk = false;
                try
                {
                    Volume.DeleteVolumeMountPoint(destFolder);
                    deleteOk = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                }

                Console.WriteLine("\n\nVolume.DeleteVolumeMountPoint() (Should be True): [{0}]\tFolder: [{1}]\n{2}\n",
                                  deleteOk, destFolder, UnitTestConstants.Reporter());

                Directory.Delete(destFolder, true, true);
                Assert.IsTrue(deleteOk && !Directory.Exists(destFolder));

                AlphaFS_Volume_EnumerateVolumeMountPoints();
            }
            catch (Exception ex)
            {
                cnt = 0;

                Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
            }
            finally
            {
                // Always remove mount point.
                // Experienced: CCleaner deletes through mount points!
                try { Volume.DeleteVolumeMountPoint(destFolder); }
                catch { }
            }

            if (cnt == 0)
            {
                Assert.Inconclusive("Nothing was enumerated, but it was expected.");
            }

            #endregion // Logical Drives
        }
コード例 #24
0
        public void AlphaFS_Volume_DefineDosDevice_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);
            Console.WriteLine();

            if (!UnitTestConstants.IsAdmin())
            {
                Assert.Inconclusive();
            }


            var TempFolder = UnitTestConstants.TempFolder;


            #region Regular Drive Mapping

            var drive = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter(), Alphaleonis.Win32.Filesystem.Path.VolumeSeparatorChar, Alphaleonis.Win32.Filesystem.Path.DirectorySeparatorChar);

            // Create Regular drive mapping.
            var actionIsTrue = false;
            try
            {
                Alphaleonis.Win32.Filesystem.Volume.DefineDosDevice(drive, TempFolder);
                actionIsTrue = true;
            }
            catch
            {
            }

            Console.WriteLine("Created Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]", actionIsTrue, drive, TempFolder);

            Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been created.");


            var di      = new Alphaleonis.Win32.Filesystem.DriveInfo(drive);
            var diSysIo = new System.IO.DriveInfo(drive);

            try
            {
                Assert.IsTrue(UnitTestConstants.Dump(di, -21));

                Assert.AreEqual(diSysIo.IsReady, di.IsReady);
            }
            finally
            {
                // Remove Regular drive mapping.
                actionIsTrue = false;
                try
                {
                    Alphaleonis.Win32.Filesystem.Volume.DeleteDosDevice(drive);
                    actionIsTrue = true;
                }
                catch
                {
                }


                Console.WriteLine();
                Console.WriteLine("Removed Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.", actionIsTrue, drive);
                Console.WriteLine();

                Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been removed.");

                Assert.IsFalse(System.IO.Directory.Exists(drive), "Drive letter should not be visible.");
            }

            #endregion // Regular Drive Mapping


            #region Symbolic Link Drive Mapping

            try
            {
                drive = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter(true), Alphaleonis.Win32.Filesystem.Path.VolumeSeparatorChar, Alphaleonis.Win32.Filesystem.Path.DirectorySeparatorChar);
                UnitTestConstants.StopWatcher(true);

                // Create Symbolic Link.
                var createSymbolicLink = false;
                try
                {
                    Alphaleonis.Win32.Filesystem.Volume.DefineDosDevice(drive, TempFolder, Alphaleonis.Win32.Filesystem.DosDeviceAttributes.RawTargetPath);
                    createSymbolicLink = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nCreated Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]", createSymbolicLink, drive, TempFolder);

                Assert.IsTrue(createSymbolicLink);


                di = new Alphaleonis.Win32.Filesystem.DriveInfo(drive);
                Assert.IsTrue(UnitTestConstants.Dump(di, -21));

                // The link is created in the NT Device Name namespace and thus not visibile in Explorer.

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

                var removeSymbolicLink = false;
                try
                {
                    Alphaleonis.Win32.Filesystem.Volume.DeleteDosDevice(drive, "NonExistingFolder", true);
                    removeSymbolicLink = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be False): [{0}]\nDrive letter: [{1}] has NOT been set free.\tNo exactMatch MS-DOS device name found.", removeSymbolicLink, drive);

                Assert.IsFalse(removeSymbolicLink);
            }
            finally
            {
                // Remove Symbolic Link, exact match: success.
                var removeSymbolicLink = false;
                try
                {
                    Alphaleonis.Win32.Filesystem.Volume.DeleteDosDevice(drive, TempFolder, true);
                    removeSymbolicLink = true;
                }
                catch
                {
                }

                Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\tFound exactMatch MS-DOS device name.", removeSymbolicLink, drive);

                Assert.IsTrue(removeSymbolicLink);

                Assert.IsFalse(System.IO.Directory.Exists(drive));
            }

            #endregion // Symbolic Link Drive Mapping
        }