private void Directory_SetCurrentDirectory(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = Environment.SystemDirectory;

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            Console.WriteLine("\tAlphaFS Set Current Directory Path: [{0}]\n", tempPath);

            Alphaleonis.Win32.Filesystem.Directory.SetCurrentDirectory(tempPath, Alphaleonis.Win32.Filesystem.PathFormat.FullPath);


            var sysIoCurrPath   = System.IO.Directory.GetCurrentDirectory();
            var alphaFSCurrPath = Alphaleonis.Win32.Filesystem.Directory.GetCurrentDirectory();

            Console.WriteLine("\tSystem.IO Get Current Directory Path: [{0}]", sysIoCurrPath);
            Console.WriteLine("\tAlphaFS   Get Current Directory Path: [{0}]", alphaFSCurrPath);

            Assert.AreEqual(sysIoCurrPath, alphaFSCurrPath, "The current directories do not match, but are expected to.");


            Console.WriteLine();
        }
        public void AlphaFS_Volume_IsSameVolume()
        {
            UnitTestConstants.PrintUnitTestHeader(false);
            Console.WriteLine();


            var file1   = System.IO.Path.GetTempFileName();
            var file2   = System.IO.Path.GetTempFileName();
            var fileTmp = file2;


            // Same C:
            var isSame = Alphaleonis.Win32.Filesystem.Volume.IsSameVolume(file1, fileTmp);

            Console.WriteLine("On same Volume (Should be True): [{0}]\n\tFile1: [{1}]\n\tFile2: [{2}]", isSame, file1, fileTmp);

            Assert.IsTrue(isSame, "Should be the same volume.");


            // Same C: -> C$
            fileTmp = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(file2);

            isSame = Alphaleonis.Win32.Filesystem.Volume.IsSameVolume(file1, fileTmp);

            Console.WriteLine("\nOn same Volume (Should be True): [{0}]\n\tFile1: [{1}]\n\tFile2: [{2}]", isSame, file1, fileTmp);

            Assert.IsTrue(isSame, "Should be the same volume.");
        }
Example #3
0
        private void AlphaFS_Directory_Move_NonExistingDestinationLogicalDrive_ThrowsDeviceNotReadyException(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var nonExistingDriveLetter = Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter();

            var srcFolder = UnitTestConstants.SysDrive + @"\NonExisting Source Folder";
            var dstFolder = nonExistingDriveLetter + @":\NonExisting Destination Folder";

            if (isNetwork)
            {
                srcFolder = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(srcFolder);
                dstFolder = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(dstFolder);
            }

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


            UnitTestAssert.ThrowsException <Alphaleonis.Win32.Filesystem.DeviceNotReadyException>(() => Alphaleonis.Win32.Filesystem.Directory.Move(srcFolder, dstFolder, Alphaleonis.Win32.Filesystem.MoveOptions.CopyAllowed));

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

            Console.WriteLine();
        }
        private void Path_CheckSupportedPathFormat_CatchArgumentException_PathStartsWithColon()
        {
            UnitTestConstants.PrintUnitTestHeader(false);
            Console.WriteLine();


            var gotException = false;


            const string invalidPath = @":AAAAAAAAAA";

            Console.WriteLine("Invalid Path: [{0}]", invalidPath);


            try
            {
                Alphaleonis.Win32.Filesystem.Path.CheckSupportedPathFormat(invalidPath, true, true);
            }
            catch (Exception ex)
            {
                var exType = ex.GetType();

                gotException = exType == typeof(ArgumentException);

                Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exType.Name, ex.Message);
            }


            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");


            Console.WriteLine();
        }
Example #5
0
        private void VolumeInfo_InitializeInstance(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);


            var cnt = 0;

            foreach (var drive in Directory.GetLogicalDrives())
            {
                var tempPath = drive;
                if (isNetwork)
                {
                    tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
                }

                try
                {
                    var volInfo = Volume.GetVolumeInfo(tempPath);
                    Console.WriteLine("\n#{0:000}\tLogical Drive: [{1}]", ++cnt, tempPath);
                    UnitTestConstants.Dump(volInfo, -26);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("#{0:000}\tLogical Drive: [{1}]\n\tCaught: {2}: {3}", ++cnt, tempPath, ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                }
                Console.WriteLine();
            }

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

            Console.WriteLine();
        }
Example #6
0
        private void Directory_Delete_CatchArgumentException_PathContainsInvalidCharacters(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var folder = System.IO.Path.GetTempPath() + @"ThisIs<My>Folder";

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


            var gotException = false;

            try
            {
                Alphaleonis.Win32.Filesystem.Directory.Delete(folder);
            }
            catch (Exception ex)
            {
                var exName = ex.GetType().Name;
                gotException = exName.Equals("ArgumentException", StringComparison.OrdinalIgnoreCase);
                Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
            }
            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

            Console.WriteLine();
        }
        private void Shell32_GetFileIcon(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var file = UnitTestConstants.NotepadExe;

            if (isNetwork)
            {
                file = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(UnitTestConstants.NotepadExe);
            }


            Console.WriteLine("\nInput File Path: {0}", file);


            var icon = IntPtr.Zero;

            try
            {
                icon = Alphaleonis.Win32.Filesystem.Shell32.GetFileIcon(file, Alphaleonis.Win32.Filesystem.Shell32.FileAttributes.SmallIcon | Alphaleonis.Win32.Filesystem.Shell32.FileAttributes.AddOverlays);
                Console.WriteLine("\n\tIcon Handle: [{0}]", icon);

                Assert.AreNotEqual(icon, IntPtr.Zero, "The file does not contain an icon, but is expected to.");
            }
            finally
            {
                Alphaleonis.Win32.Filesystem.Shell32.DestroyIcon(icon);
            }

            Console.WriteLine();
        }
        private void EnumerateShares(string host)
        {
            UnitTestConstants.PrintUnitTestHeader(false);

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


            var cnt = 0;

            foreach (var shareInfo in Alphaleonis.Win32.Network.Host.EnumerateShares(host, true))
            {
                //Console.WriteLine("\n\t#{0:000}\tShare: [{1}]", ++cnt, shareInfo);

                if (UnitTestConstants.Dump(shareInfo, -18))
                {
                    cnt++;
                }

                Console.WriteLine();
            }

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

            Console.WriteLine();
        }
        private void Directory_GetFileSystemEntryInfo(bool isNetwork)
        {
            var path = UnitTestConstants.SysRoot;

            if (!System.IO.Directory.Exists(path))
            {
                Assert.Inconclusive("Test ignored because {0} was not found.", path);
            }


            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = path;

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


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

            var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath);

            UnitTestConstants.Dump(fsei, -19);


            Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));
            Assert.IsTrue((fsei.Attributes & System.IO.FileAttributes.Directory) != 0, "The Directory attribute is not found, but is expected.");
            Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

            Console.WriteLine();
        }
Example #10
0
        private void AlphaFS_Volume_GetDriveFormat(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);


            var logicalDriveCount = 0;

            foreach (var driveInfo in System.IO.DriveInfo.GetDrives())
            {
                var driveName = isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(driveInfo.Name) : driveInfo.Name;

                Console.Write("#{0:000}\tInput Logical Drive Path: [{1}]", ++logicalDriveCount, driveName);


                var driveFormat = Alphaleonis.Win32.Filesystem.Volume.GetDriveFormat(driveName);

                Console.WriteLine("\t\tDrive Format: [{0}]", driveFormat);


                // Some USB drives do not report drive format when path is UNC.

                if (!Alphaleonis.Utils.IsNullOrWhiteSpace(driveFormat))
                {
                    Assert.AreEqual(driveInfo.DriveFormat, driveFormat);
                }
            }


            Assert.IsTrue(logicalDriveCount > 0, "No logical drives enumerated, but it is expected.");


            Console.WriteLine();
        }
        public void AlphaFS_Host_EnumerateNetworks_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);


            var networkCount = 0;

            foreach (var networkInfo in Host.EnumerateNetworks().OrderBy(network => network.Name))
            {
                Console.WriteLine("#{0:000}\tNetwork: [{1}]", ++networkCount, networkInfo.Name);


                UnitTestConstants.Dump(networkInfo, -21);


                if (null != networkInfo.Connections)
                {
                    foreach (var connectionInfo in networkInfo.Connections)
                    {
                        UnitTestConstants.Dump(connectionInfo.NetworkInterface, -20, true);
                    }
                }


                Console.WriteLine();
            }


            if (networkCount == 0)
            {
                UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty();
            }
        }
Example #12
0
        private void File_Copy_WithProgress(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);
            Console.WriteLine();


            var tempPath = UnitTestConstants.TempFolder;

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                // Min: 1 bytes, Max: 10485760 = 10 MB.
                var fileLength = new Random().Next(1, 10485760);
                var fileSource = UnitTestConstants.CreateFile(rootDir.Directory.FullName, fileLength);
                var fileCopy   = rootDir.RandomFileFullPath;

                Console.WriteLine("Src File Path: [{0:N0} ({1}) [{2}]", fileLength, Alphaleonis.Utils.UnitSizeToText(fileLength), fileSource);
                Console.WriteLine("Dst File Path: [{0}]", fileCopy);

                Assert.IsTrue(System.IO.File.Exists(fileSource.FullName), "The file does not exists, but is expected to.");



                // Allow copy to overwrite an existing file.
                const Alphaleonis.Win32.Filesystem.CopyOptions copyOptions = Alphaleonis.Win32.Filesystem.CopyOptions.None;

                // The copy progress handler.
                var callback = new Alphaleonis.Win32.Filesystem.CopyMoveProgressRoutine(FileCopyProgressHandler);

                Console.WriteLine();


                // You can pass any piece of data to userProgressData. This data can be accessed from the callback method.
                // Specify file length for assertion.
                var userProgressData = fileLength;


                var copyResult = Alphaleonis.Win32.Filesystem.File.Copy(fileSource.FullName, fileCopy, copyOptions, callback, userProgressData);

                UnitTestConstants.Dump(copyResult, -18);


                Assert.IsTrue(System.IO.File.Exists(fileCopy), "The file does not exists, but is expected to.");


                var fileLen = new System.IO.FileInfo(fileCopy).Length;

                Assert.AreEqual(fileLength, fileLen, "The file copy is: {0} bytes, but is expected to be: {1} bytes.", fileLen, fileLength);

                Assert.IsTrue(System.IO.File.Exists(fileSource.FullName), "The original file does not exist, but is expected to.");
            }


            Console.WriteLine();
        }
        private void File_Compress_And_Decompress(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "File.Compress_Decompress"))
            {
                var file = rootDir.RandomFileFullPath + ".txt";
                Console.WriteLine("\nInput File Path: [{0}]]", file);

                using (System.IO.File.CreateText(file)) { }


                Alphaleonis.Win32.Filesystem.File.Compress(file);
                FileAssert.IsCompressed(file);

                Alphaleonis.Win32.Filesystem.File.Decompress(file);
                FileAssert.IsNotCompressed(file);
            }

            Console.WriteLine();
        }
Example #14
0
        private void Shell32Info_InitializeInstance(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "Shell32Info.Initialize_Instance"))
            {
                var file = rootDir.RandomFileFullPath + ".txt";

                var shell32Info = new Alphaleonis.Win32.Filesystem.Shell32Info(file);

                Assert.IsTrue(shell32Info != null);

                UnitTestConstants.Dump(shell32Info, -15);
            }

            Console.WriteLine();
        }
Example #15
0
        private void Directory_Delete_CatchDirectoryNotFoundException_NonExistingDirectory(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath() + "Directory.Delete-" + System.IO.Path.GetRandomFileName();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }

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


            var gotException = false;

            try
            {
                Alphaleonis.Win32.Filesystem.Directory.Delete(tempPath);
            }
            catch (Exception ex)
            {
                var exName = ex.GetType().Name;
                gotException = exName.Equals("DirectoryNotFoundException", StringComparison.OrdinalIgnoreCase);
                Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
            }
            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

            Console.WriteLine();
        }
Example #16
0
        private void File_Delete_CatchFileNotFoundException_NonExistingFile(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath() + "File.Delete-" + System.IO.Path.GetRandomFileName();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }

            Console.WriteLine("\nInput File Path: [{0}]", tempPath);


            var gotException = false;

            try
            {
                Alphaleonis.Win32.Filesystem.File.Delete(tempPath);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(gotException, "An exception occurred, but is expected not to: " + ex.Message);
            }

            Console.WriteLine();
        }
Example #17
0
        private void Directory_Delete_CatchDirectoryNotFoundException_NonExistingDriveLetter(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var folder = Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter() + @":\NonExistingDriveLetter";

            if (isNetwork)
            {
                folder = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(folder);
            }

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


            var gotException = false;

            try
            {
                Alphaleonis.Win32.Filesystem.Directory.Delete(folder);
            }
            catch (Exception ex)
            {
                // Local: DirectoryNotFoundException.
                // UNC: IOException.

                var exName = ex.GetType().Name;
                gotException = exName.Equals(isNetwork ? "IOException" : "DirectoryNotFoundException", StringComparison.OrdinalIgnoreCase);
                Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
            }
            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

            Console.WriteLine();
        }
Example #18
0
        private void File_Delete(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "File.Delete"))
            {
                var file = UnitTestConstants.CreateFile(rootDir.Directory.FullName);
                Console.WriteLine("\nInput File Path: [{0}]", file);


                Alphaleonis.Win32.Filesystem.File.Delete(file.FullName);

                Assert.IsFalse(Alphaleonis.Win32.Filesystem.File.Exists(file.FullName), "The file exists, but is expected not to be.");
            }

            Console.WriteLine();
        }
Example #19
0
        private void FileSystemEntryInfo_File_InitializeInstance(bool isNetwork)
        {
            if (!System.IO.File.Exists(UnitTestConstants.NotepadExe))
            {
                Assert.Inconclusive("Test ignored because {0} was not found.", UnitTestConstants.NotepadExe);
            }


            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = UnitTestConstants.NotepadExe;

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            Console.WriteLine("\nInput File Path: [{0}]", tempPath);

            var fsei = Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath);

            UnitTestConstants.Dump(fsei, -17);

            Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));
            Assert.IsTrue(fsei.Attributes != System.IO.FileAttributes.Directory, "The directory attribute is found, but is not expected.");
            Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

            Console.WriteLine();
        }
Example #20
0
        private void Directory_Move_CatchArgumentException_PathStartsWithColon(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var folderSrc = @":AAAAAAAAAA";

            Console.WriteLine("\nSrc Directory Path: [{0}]", folderSrc);


            var gotException = false;

            try
            {
                Alphaleonis.Win32.Filesystem.Directory.Move(folderSrc, string.Empty);
            }
            catch (Exception ex)
            {
                var exName = ex.GetType().Name;
                gotException = exName.Equals("ArgumentException", StringComparison.OrdinalIgnoreCase);
                Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
            }
            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

            Console.WriteLine();
        }
        private void AlphaFS_File_GetFileSystemEntryInfo(bool isNetwork)
        {
            var path = System.IO.Path.Combine(Environment.SystemDirectory, "notepad.exe");

            if (!System.IO.File.Exists(path))
            {
                UnitTestAssert.InconclusiveBecauseFileNotFound(path);
            }


            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = path;

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }

            Console.WriteLine("Input File Path: [{0}]", tempPath);

            var fsei = Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(tempPath);

            UnitTestConstants.Dump(fsei, -19);

            Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));
            Assert.IsTrue(fsei.Attributes != System.IO.FileAttributes.Directory, "The directory attribute is found, but is not expected.");
            Assert.AreEqual(tempPath, fsei.FullPath, "The paths are not equal, but are expected to be.");

            Console.WriteLine();
        }
Example #22
0
        private void Directory_Move_Rename(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "Directory.Move (Rename)"))
            {
                var folderSrc = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(rootDir.Directory.FullName, "Source-") + System.IO.Path.GetRandomFileName());
                var folderDst = new System.IO.DirectoryInfo(System.IO.Path.Combine(rootDir.Directory.FullName, "Destination-") + System.IO.Path.GetRandomFileName());

                Console.WriteLine("\nInput Directory Path: [{0}]", folderSrc.FullName);
                Console.WriteLine("\nRename folder: [{0}] to: [{1}]", folderSrc.Name, folderDst.Name);


                Assert.IsTrue(folderSrc.Exists, "The source folder does not exist which was not expected.");
                Assert.IsFalse(folderDst.Exists, "The destination folder exists which was not expected.");

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

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

                Assert.IsFalse(folderSrc.Exists, "The source folder exists which was not expected.");
                Assert.IsTrue(folderDst.Exists, "The destination folder does not exists which was not expected.");
            }

            Console.WriteLine();
        }
Example #23
0
        private void AlphaFS_Directory_EnumerateFileSystemEntryInfos_TypeFileSystemEntryInfo(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = Environment.SystemDirectory;

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }

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


            var count = 0;

            foreach (var fsei in Alphaleonis.Win32.Filesystem.Directory.EnumerateFileSystemEntryInfos <Alphaleonis.Win32.Filesystem.FileSystemEntryInfo>(tempPath))
            {
                Assert.IsTrue(fsei.GetType().IsEquivalentTo(typeof(Alphaleonis.Win32.Filesystem.FileSystemEntryInfo)));
                count++;
            }


            Assert.IsTrue(count > 0, "Nothing is enumerated, but it is expected.");
        }
        public void AlphaFS_Host_EnumerateShares_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);

            var host = Environment.MachineName;

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


            var count = 0;

            foreach (var shareInfo in Alphaleonis.Win32.Network.Host.EnumerateShares(host, true))
            {
                UnitTestConstants.Dump(shareInfo);

                Assert.IsNotNull(shareInfo);

                count++;

                Console.WriteLine();
            }

            if (count == 0)
            {
                UnitTestAssert.InconclusiveBecauseResourcesAreUnavailable();
            }
        }
        private void EnumerateOpenConnections(string host, string share)
        {
            //UnitTestAssert.IsElevatedProcess(); // In User mode nothing is enumerated.
            UnitTestConstants.PrintUnitTestHeader(false);

            Console.WriteLine("Connected to Share: [{0}\\{1}]", host, share);


            var count = 0;

            foreach (var openConnectionInfo in Alphaleonis.Win32.Network.Host.EnumerateOpenConnections(host, share, true))
            {
                UnitTestConstants.Dump(openConnectionInfo);

                Assert.IsNotNull(openConnectionInfo);

                count++;

                Console.WriteLine();
            }


            if (count == 0)
            {
                UnitTestAssert.InconclusiveBecauseResourcesAreUnavailable();
            }
        }
Example #26
0
        private void Directory_IsEmpty_ContainsAFile_IsFalse(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                var folder = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(rootDir.Directory.FullName, "Empty Folder"));
                Console.WriteLine("\nInput Directory Path: [{0}]", folder.FullName);


                // Create file and test again.
                var file = System.IO.Path.Combine(folder.FullName, "a_file.txt");

                using (System.IO.File.Create(file))
                    Console.WriteLine("\n\tCreated File: [{0}]", file);


                Assert.IsFalse(Alphaleonis.Win32.Filesystem.Directory.IsEmpty(folder.FullName), "It is expected that the folder is not empty.");
            }

            Console.WriteLine();
        }
Example #27
0
        private void AlphaFS_Directory_CreateDirectory_NonExistingDriveLetter_ThrowsIOExceptionOrDeviceNotReadyException(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var folder = Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter() + @":\NonExistingDriveLetter";

            if (isNetwork)
            {
                folder = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(folder);
            }

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


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


            // Local: IOException.
            // UNC: IOException or DeviceNotReadyException.
            // The latter occurs when a removable drive is already removed but there's still a cached reference.

            var caught = UnitTestAssert.TestException <System.IO.IOException>(() => Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(folder));

            if (!caught)
            {
                caught = UnitTestAssert.TestException <Alphaleonis.Win32.Filesystem.DeviceNotReadyException>(() => Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(folder));
            }


            Assert.IsTrue(caught);

            Console.WriteLine();
        }
Example #28
0
        private void Directory_Delete_CatchNotSupportedException_PathContainsColon(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var colonText = @"\My:FolderPath";
            var folder    = (isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(UnitTestConstants.LocalHostShare) : UnitTestConstants.SysDrive + @"\dev\test") + colonText;

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


            var gotException = false;

            try
            {
                Alphaleonis.Win32.Filesystem.Directory.Delete(folder);
            }
            catch (Exception ex)
            {
                var exName = ex.GetType().Name;
                gotException = exName.Equals("NotSupportedException", StringComparison.OrdinalIgnoreCase);
                Console.WriteLine("\n\tCaught Exception: [{0}] Message: [{1}]", exName, ex.Message);
            }
            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");

            Console.WriteLine();
        }
        private void Directory_CountFileSystemObjects_FoldersAndFiles_Recursive(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                var folder = rootDir.RandomDirectoryFullPath;
                Console.WriteLine("\nInput Directory Path: [{0}]\n", folder);

                const int expectedFso = 200;
                UnitTestConstants.CreateDirectoriesAndFiles(folder, 100, false, false, false);


                var fsoCount = Alphaleonis.Win32.Filesystem.Directory.CountFileSystemObjects(folder, "*", Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.FilesAndFolders | Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive);

                Console.WriteLine("\tTotal file system objects = [{0}]", fsoCount);

                Assert.AreEqual(expectedFso, fsoCount, string.Format(CultureInfo.InvariantCulture, "The number of file system objects: {0} is not equal than expected: {1}", expectedFso, fsoCount));
            }

            Console.WriteLine();
        }
        private void Path_CheckSupportedPathFormat_CatchNotSupportedException_PathContainsColon(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);
            Console.WriteLine();


            var gotException = false;


            const string colonText = @"\My:FilePath";

            var invalidPath = (isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(UnitTestConstants.TempFolder) : UnitTestConstants.TempFolder + @"\dev\test") + colonText;

            Console.WriteLine("Invalid Path: [{0}]", invalidPath);


            try
            {
                Alphaleonis.Win32.Filesystem.Path.CheckSupportedPathFormat(invalidPath, true, true);
            }
            catch (Exception ex)
            {
                var exType = ex.GetType();

                gotException = exType == typeof(NotSupportedException);

                Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exType.Name, ex.Message);
            }


            Assert.IsTrue(gotException, "The exception is not caught, but is expected to.");


            Console.WriteLine();
        }