Пример #1
0
        private void DumpClassOpenResourceInfo(string host, string share)
        {
            Console.WriteLine("\n=== TEST ===");
            var tempPath = Path.LocalToUnc(share);

            Console.WriteLine("\nNetwork.Host.EnumerateOpenResources() from host: [{0}]", tempPath);

            System.IO.Directory.SetCurrentDirectory(tempPath);

            UnitTestConstants.StopWatcher(true);
            var cnt = 0;

            foreach (var openResource in Host.EnumerateOpenResources(host, null, null, false))
            {
                if (UnitTestConstants.Dump(openResource, -11))
                {
                    Console.Write("\n");
                    cnt++;
                }
            }

            Console.WriteLine(UnitTestConstants.Reporter());

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

            Console.WriteLine();
        }
Пример #2
0
        private void DumpClassByHandleFileInfo(bool isLocal)
        {
            Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network);
            var tempPath = Path.GetTempPath("File.GetFileInfoByHandle()-" + Path.GetRandomFileName());

            if (!isLocal)
            {
                tempPath = Path.LocalToUnc(tempPath);
            }

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

            var stream = File.Create(tempPath);

            stream.WriteByte(1);

            UnitTestConstants.StopWatcher(true);
            var bhfi = File.GetFileInfoByHandle(stream.SafeFileHandle);

            Console.WriteLine(UnitTestConstants.Reporter());

            Assert.IsTrue(UnitTestConstants.Dump(bhfi, -18));

            Assert.AreEqual(System.IO.File.GetCreationTimeUtc(tempPath), bhfi.CreationTimeUtc);
            Assert.AreEqual(System.IO.File.GetLastAccessTimeUtc(tempPath), bhfi.LastAccessTimeUtc);
            Assert.AreEqual(System.IO.File.GetLastWriteTimeUtc(tempPath), bhfi.LastWriteTimeUtc);

            stream.Close();

            File.Delete(tempPath, true);
            Assert.IsFalse(File.Exists(tempPath), "Cleanup failed: File should have been removed.");
            Console.WriteLine();
        }
        private void Directory_Move_Rename_DifferentCasingDirectory(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folderSrc = System.IO.Directory.CreateDirectory(System.IO.Path.Combine(tempRoot.Directory.FullName, "Existing Source Folder"));

                var upperCaseFolderName = System.IO.Path.GetFileName(folderSrc.FullName).ToUpperInvariant();

                var destFolder = System.IO.Path.Combine(folderSrc.Parent.FullName, upperCaseFolderName);

                Console.WriteLine("Input Directory Path: [{0}]\n", folderSrc.FullName);
                Console.WriteLine("\tRename folder [{0}] to [{1}]", folderSrc.Name, upperCaseFolderName);


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


                var upperDirInfo = new System.IO.DirectoryInfo(destFolder);

                UnitTestConstants.Dump(upperDirInfo);


                Assert.AreEqual(upperCaseFolderName, upperDirInfo.Name, "The source folder name is not uppercase, but is expected to.");
            }


            Console.WriteLine();
        }
        public void AlphaFS_Host_EnumerateOpenResources_Local_Success()
        {
            UnitTestAssert.IsElevatedProcess();
            UnitTestConstants.PrintUnitTestHeader(false);

            var host = Environment.MachineName;

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


            var count = 0;

            foreach (var openResourceInfo in Alphaleonis.Win32.Network.Host.EnumerateOpenResources(host, null, null, false))
            {
                UnitTestConstants.Dump(openResourceInfo);

                Assert.IsNotNull(openResourceInfo);

                count++;

                Console.WriteLine();
            }


            if (count == 0)
            {
                UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty();
            }
        }
        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();
        }
Пример #6
0
        private void DirectoryInfo_FolderName255Characters(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.Directory.FullName;

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


                // System.IO: 244, anything higher throws System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
                // AlphaFS  : 255, anything higher throws System.IO.PathTooLongException.
                var subFolder = new string('b', 255);


                var local = Alphaleonis.Win32.Filesystem.Path.Combine(folder, subFolder);
                var unc   = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(local);
                Console.WriteLine("SubFolder length: {0}, total path length: {1}", subFolder.Length, isNetwork ? unc.Length : local.Length);

                // Success.
                var di1 = new Alphaleonis.Win32.Filesystem.DirectoryInfo(isNetwork ? unc : local);

                // Fail.
                //var di1 = new System.IO.DirectoryInfo(local);


                di1.Create();
                Assert.IsTrue(di1.Exists);


                UnitTestConstants.Dump(di1, -17);
            }

            Console.WriteLine();
        }
Пример #7
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 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();
        }
Пример #9
0
        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))
            {
                if (UnitTestConstants.Dump(shareInfo, -18))
                {
                    count++;
                }

                Console.WriteLine();
            }

            if (count == 0)
            {
                UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty();
            }
        }
        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();
        }
Пример #11
0
        private void AlphaFS_Shell32_GetFileAssociation(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var inputPath = Environment.SystemDirectory;

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

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


            var cnt = 0;

            foreach (var file in System.IO.Directory.EnumerateFiles(inputPath))
            {
                var shell32Info = Alphaleonis.Win32.Filesystem.Shell32.GetShell32Info(file);

                // Not much of a test...
                Assert.IsNotNull(shell32Info);

                UnitTestConstants.Dump(shell32Info, -15);

                if (++cnt == 5)
                {
                    break;
                }
            }

            Console.WriteLine();

            Assert.IsTrue(cnt > 0, "No entries enumerated.");
        }
Пример #12
0
        private void AlphaFS_Directory_GetFileSystemEntryInfo(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = Environment.SystemDirectory;

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

            Console.WriteLine("Input 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();
        }
        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);


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


                Console.WriteLine();
            }


            if (networkCount == 0)
            {
                UnitTestAssert.InconclusiveBecauseResourcesAreUnavailable();
            }
        }
        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("\n#{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)
            {
                Assert.Inconclusive("No networks enumerated, but it is expected.");
            }
        }
        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();
        }
Пример #16
0
        private void AlphaFS_File_GetFileInfoByHandle(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var file = tempRoot.CreateFile();

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


                using (var fs = file.Open(FileMode.Open))
                {
                    var bhfi = Alphaleonis.Win32.Filesystem.File.GetFileInfoByHandle(fs.SafeFileHandle);


                    Assert.IsTrue(UnitTestConstants.Dump(bhfi, -18));

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

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

                    Assert.AreEqual(file.LastWriteTimeUtc, bhfi.LastWriteTimeUtc);

                    Assert.AreEqual(file.Length, bhfi.FileSize);
                }
            }

            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();
        }
Пример #18
0
        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.InconclusiveBecauseEnumerationIsEmpty();
            }
        }
Пример #19
0
        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();
            }
        }
Пример #20
0
        public void AlphaFS_Host_EnumerateSessions_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);

            var host = Environment.MachineName;

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


            var sessionCount = 0;

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

                UnitTestConstants.Dump(sessionsInfo);

                Assert.IsNotNull(sessionsInfo);

                sessionCount++;

                Console.WriteLine();
            }


            if (sessionCount == 0)
            {
                UnitTestAssert.InconclusiveBecauseResourcesAreUnavailable();
            }
        }
        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();
        }
Пример #22
0
        public void DriveInfo_GetDrives_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);


            var drives = Alphaleonis.Win32.Filesystem.DriveInfo.GetDrives().ToList();

            foreach (var drive in drives)
            {
                Console.WriteLine("Logical Drive: [{0}]", drive.Name);

                UnitTestConstants.Dump(drive, -21);


                if (null != drive.DiskSpaceInfo)
                {
                    UnitTestConstants.Dump(drive.DiskSpaceInfo, -26, true);
                }


                Console.WriteLine();
            }


            Assert.IsTrue(drives.Count > 0);

            Assert.AreEqual(drives[0].Name[0], UnitTestConstants.SysDrive[0]);
        }
Пример #23
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();
        }
Пример #24
0
        public void AlphaFS_Host_ConnectDrive_And_DisconnectDrive_Network_Success()
        {
            using (var tempRoot = new TemporaryDirectory(true))
            {
                // Randomly test the share where the local folder possibly has the read-only and/or hidden attributes set.

                var folder = tempRoot.CreateDirectoryRandomizedAttributes();

                var drive = Alphaleonis.Win32.Filesystem.DriveInfo.GetFreeDriveLetter() + ":";


                try
                {
                    Console.WriteLine("Connect drive [{0}] to share [{1}]", drive, folder.FullName);

                    Alphaleonis.Win32.Network.Host.ConnectDrive(drive, folder.FullName);

                    UnitTestConstants.Dump(new System.IO.DriveInfo(drive), -18);

                    Assert.IsTrue(System.IO.Directory.Exists(drive), "The drive does not exists, but is expected to.");
                }
                finally
                {
                    Console.WriteLine("\nDisconnect drive from share.");

                    Alphaleonis.Win32.Network.Host.DisconnectDrive(drive);

                    Assert.IsFalse(System.IO.Directory.Exists(drive), "The drive exists, but is expected not to.");
                }
            }
        }
Пример #25
0
        public void AlphaFS_Class_Network_ShareInfo()
        {
            Console.WriteLine("Class Network.ShareInfo()");

            var host = UnitTestConstants.LocalHost;

            Console.WriteLine("\n=== TEST ===");
            Console.Write("\nNetwork.Host.EnumerateShares() from host: [{0}]\n", host);

            var cnt = 0;

            UnitTestConstants.StopWatcher(true);
            foreach (var share in Host.EnumerateShares(host, true))
            {
                Console.WriteLine("\n\t#{0:000}\tShare: [{1}]", ++cnt, share);
                UnitTestConstants.Dump(share, -18);
            }

            Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true));

            if (cnt == 0)
            {
                Assert.Inconclusive("Nothing was enumerated, but it was expected.");
            }
        }
Пример #26
0
        private void AlphaFS_Directory_CopyTimestamps(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder1 = tempRoot.CreateDirectoryRandomizedAttributes();

                Thread.Sleep(1500);

                var folder2 = tempRoot.CreateDirectoryRandomizedAttributes();


                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);


                UnitTestConstants.Dump(folder1, -17);
                UnitTestConstants.Dump(folder2, -17);


                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();
        }
Пример #27
0
        private void Directory_GetFileInfoByHandle(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}]]", folder);


                var dirInfo = new System.IO.DirectoryInfo(folder);
                dirInfo.Create();


                var bhfi = Alphaleonis.Win32.Filesystem.Directory.GetFileInfoByHandle(dirInfo.FullName);
                Assert.IsTrue(UnitTestConstants.Dump(bhfi, -18));


                Assert.AreEqual(dirInfo.CreationTimeUtc, bhfi.CreationTimeUtc);
                Assert.AreEqual(dirInfo.LastAccessTimeUtc, bhfi.LastAccessTimeUtc);
                Assert.AreEqual(dirInfo.LastWriteTimeUtc, bhfi.LastWriteTimeUtc);
            }

            Console.WriteLine();
        }
Пример #28
0
        public void AlphaFS_Host_EnumerateNetworkConnections_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);


            var networkConnectionCount = 0;

            foreach (var networkConnection in Host.EnumerateNetworkConnections().OrderBy(networkConnection => networkConnection.NetworkInfo.Name))
            {
                Console.WriteLine("#{0:000}\tNetwork: [{1}]", ++networkConnectionCount, networkConnection.NetworkInfo.Name);


                UnitTestConstants.Dump(networkConnection, -21);

                UnitTestConstants.Dump(networkConnection.NetworkInfo, -21, true);

                UnitTestConstants.Dump(networkConnection.NetworkInterface, -20, true);


                Console.WriteLine();
            }


            if (networkConnectionCount == 0)
            {
                UnitTestAssert.InconclusiveBecauseEnumerationIsEmpty();
            }
        }
Пример #29
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();
        }
Пример #30
0
        public void AlphaFS_Host_GetServerStatistics_Local_Success()
        {
            UnitTestConstants.PrintUnitTestHeader(false);

            var serverStatistics = Alphaleonis.Win32.Network.Host.GetServerStatistics();

            UnitTestConstants.Dump(serverStatistics, -22);
        }