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(); }
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."); } }
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(); }
public void AlphaFS_Path_LocalToUnc() { Console.WriteLine("Path.LocalToUnc()"); Console.WriteLine("\nInput Path: [{0}]\n", UnitTestConstants.SysRoot); var cnt = 0; UnitTestConstants.StopWatcher(true); foreach (var path2 in Directory.EnumerateFileSystemEntries(UnitTestConstants.SysRoot)) { var uncPath = Path.LocalToUnc(path2); Console.WriteLine("\t#{0:000}\tLocal: [{1}]\t\t\tUNC: [{2}]", ++cnt, path2, uncPath); Assert.IsTrue(Path.IsUncPath(uncPath)); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } Console.WriteLine(); }
public void AlphaFS_Directory_HasInheritedPermissions() { Console.WriteLine("Directory.HasInheritedPermissions()\n"); var searchPattern = Path.WildcardStarMatchAll; var searchOption = SearchOption.TopDirectoryOnly; var cnt = 0; UnitTestConstants.StopWatcher(true); foreach (var dir in Directory.EnumerateDirectories(UnitTestConstants.SysRoot, searchPattern, searchOption)) { try { var hasIp = Directory.HasInheritedPermissions(dir); if (hasIp) { Console.WriteLine("\t#{0:000}\t[{1}]\t\tDirectory has inherited permissions: [{2}]", ++cnt, hasIp, dir); } Assert.AreEqual(hasIp, HasInheritedPermissions(dir)); } catch (Exception ex) { Console.Write("\t#{0:000}\tCaught {1} for directory: [{2}]\t[{3}]\n", cnt, ex.GetType().FullName, dir, ex.Message.Replace(Environment.NewLine, " ")); } } Console.Write("\n{0}", UnitTestConstants.Reporter()); }
private void DumpGetProperties(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); var path = isLocal ? UnitTestConstants.SysRoot32 : Path.LocalToUnc(UnitTestConstants.SysRoot32); Console.WriteLine("\n\tAggregated properties of file system objects from Directory: [{0}]\n", path); UnitTestConstants.StopWatcher(true); var props = Directory.GetProperties(path, DirectoryEnumerationOptions.FilesAndFolders | DirectoryEnumerationOptions.Recursive | DirectoryEnumerationOptions.ContinueOnException); var report = UnitTestConstants.Reporter(); var total = props["Total"]; var file = props["File"]; var size = props["Size"]; var cnt = 0; foreach (var key in props.Keys) { Console.WriteLine("\t\t#{0:000}\t{1, -17} = [{2}]", ++cnt, key, props[key]); } Console.WriteLine("\n\t{0}", report); if (cnt == 0) { Assert.Inconclusive("Nothing is enumerated, but it is expected."); } Assert.IsTrue(total > 0, "0 Objects."); Assert.IsTrue(file > 0, "0 Files."); Assert.IsTrue(size > 0, "0 Size."); Console.WriteLine(); }
public void AlphaFS_Path_GetMappedConnectionName() { Console.WriteLine("Path.GetMappedConnectionName()"); var cnt = 0; UnitTestConstants.StopWatcher(true); foreach (var drive in Directory.GetLogicalDrives().Where(drive => new DriveInfo(drive).IsUnc)) { ++cnt; UnitTestConstants.StopWatcher(true); var gmCn = Path.GetMappedConnectionName(drive); var gmUn = Path.GetMappedUncName(drive); Console.WriteLine("\n\tMapped drive: [{0}]\tGetMappedConnectionName(): [{1}]", drive, gmCn); Console.WriteLine("\tMapped drive: [{0}]\tGetMappedUncName() : [{1}]", drive, gmUn); Assert.IsTrue(!string.IsNullOrWhiteSpace(gmCn)); Assert.IsTrue(!string.IsNullOrWhiteSpace(gmUn)); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated because no mapped drives were found."); } }
public void AlphaFS_Volume_QueryAllDosDevices() { Console.WriteLine("Volume.QueryAllDosDevices()"); UnitTestConstants.StopWatcher(true); IEnumerable <string> query = Volume.QueryAllDosDevices("sort").ToArray(); var report = UnitTestConstants.Reporter(true); Console.WriteLine("\nRetrieved: [{0}] items.{1}\n", query.Count(), report); var cnt = 0; foreach (var dosDev in query) { Console.WriteLine("#{0:000}\t{1}", ++cnt, dosDev); } if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } Assert.IsTrue(query.Any()); }
public void AlphaFS_Host_EnumerateDfsLinks_Network_Success() { UnitTestConstants.PrintUnitTestHeader(true); Console.WriteLine(); var cnt = 0; var noDomainConnection = true; UnitTestConstants.StopWatcher(true); try { foreach (var dfsNamespace in Alphaleonis.Win32.Network.Host.EnumerateDomainDfsRoot()) { noDomainConnection = false; Console.Write("\n#{0:000}\tDFS Root: [{1}]\n", ++cnt, dfsNamespace); var cnt2 = 0; try { foreach (var dfsInfo in Alphaleonis.Win32.Network.Host.EnumerateDfsLinks(dfsNamespace).OrderBy(d => d.EntryPath)) { Console.Write("\n\t#{0:000}\tDFS Link: [{1}]", ++cnt2, dfsInfo.EntryPath); } } catch (NetworkInformationException ex) { Console.WriteLine("NetworkInformationException #1: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\nCaught (UNEXPECTED #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine(); } } catch (NetworkInformationException ex) { Console.WriteLine("NetworkInformationException #2: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\nCaught (UNEXPECTED #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } if (noDomainConnection) { Assert.Inconclusive("Test ignored because the computer is either not connected to a domain or no DFS root exists."); } else if (cnt == 0) { Assert.Inconclusive("Nothing is enumerated, but it is expected."); } Console.WriteLine(); }
private void File_CreateHardlink_And_EnumerateHardlinks(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); var tempPath = System.IO.Path.GetTempPath(); using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name)) { var hardlinkFolder = System.IO.Path.Combine(rootDir.Directory.FullName, "Hardlinks"); System.IO.Directory.CreateDirectory(hardlinkFolder); var file = System.IO.Path.Combine(rootDir.Directory.FullName, "OriginalFile.txt"); Console.WriteLine("\nInput File Path: [{0}]\n", file); // Create original file with text content. System.IO.File.WriteAllText(file, UnitTestConstants.TextHelloWorld); // Create a random number of hardlinks to the original file. var numCreate = new Random().Next(1, 20); var hardlinks = new List <string>(); Console.WriteLine("Created {0} hardlinks:", numCreate + 1); for (var i = 0; i < numCreate; i++) { var newfile = System.IO.Path.Combine(hardlinkFolder, i + "-Hardlink-" + UnitTestConstants.GetRandomFileNameWithDiacriticCharacters() + ".txt"); Alphaleonis.Win32.Filesystem.File.CreateHardlink(newfile, file); hardlinks.Add(newfile); } var cnt = 0; foreach (var hardLink in Alphaleonis.Win32.Filesystem.File.EnumerateHardlinks(file)) { Console.WriteLine("\t\t#{0:000}\tHardlink: [{1}]", ++cnt, hardLink); } Assert.AreEqual(numCreate + 1, cnt); using (var stream = System.IO.File.OpenRead(file)) { UnitTestConstants.StopWatcher(true); var bhfi = Alphaleonis.Win32.Filesystem.File.GetFileInfoByHandle(stream.SafeFileHandle); Assert.AreEqual(numCreate + 1, bhfi.NumberOfLinks); Console.WriteLine("\n\n\tByHandleFileInfo for Input Path, see property: NumberOfLinks"); UnitTestConstants.Dump(bhfi, -18); } } Console.WriteLine(); }
public void AlphaFS_Host_EnumerateDfsLinks() { Console.WriteLine("Network.Host.EnumerateDfsLinks()"); var cnt = 0; var noDomainConnection = true; UnitTestConstants.StopWatcher(true); try { foreach (var dfsNamespace in Host.EnumerateDomainDfsRoot()) { noDomainConnection = false; Console.Write("\n#{0:000}\tDFS Root: [{1}]\n", ++cnt, dfsNamespace); var cnt2 = 0; try { foreach (var dfsInfo in Host.EnumerateDfsLinks(dfsNamespace).OrderBy(d => d.EntryPath)) { Console.Write("\n\t#{0:000}\tDFS Link: [{1}]", ++cnt2, dfsInfo.EntryPath); } } catch (NetworkInformationException ex) { Console.WriteLine("\n\tNetworkInformationException #1: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught (unexpected #1) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine(); } } catch (NetworkInformationException ex) { Console.WriteLine("\n\tNetworkInformationException #2: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } catch (Exception ex) { Console.WriteLine("\n\tCaught (unexpected #2) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\n\n{0}", UnitTestConstants.Reporter(true)); if (noDomainConnection) { Assert.Inconclusive("Test ignored because the computer is probably not connected to a domain."); } else if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } Console.WriteLine(); }
public void Path_GetExtension_NullOrEmpty_Success() { Assert.IsNull(System.IO.Path.GetExtension(null)); Assert.IsNull(Alphaleonis.Win32.Filesystem.Path.GetExtension(null)); Assert.AreEqual("", System.IO.Path.GetExtension("")); Assert.AreEqual("", Alphaleonis.Win32.Filesystem.Path.GetExtension("")); var pathCnt = 0; var errorCnt = 0; var skipAssert = false; UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { string expected = null; string actual = null; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]", ++pathCnt, path); // System.IO try { expected = System.IO.Path.GetExtension(path); } catch (Exception ex) { skipAssert = ex is ArgumentException; Console.WriteLine("\tCaught [System.IO] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t System.IO : [{0}]", expected ?? "null"); // AlphaFS try { actual = Alphaleonis.Win32.Filesystem.Path.GetExtension(path); if (!skipAssert) { Assert.AreEqual(expected, actual); } } catch (Exception ex) { errorCnt++; Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t AlphaFS : [{0}]", actual ?? "null"); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); Assert.AreEqual(0, errorCnt, "Encountered paths where AlphaFS != System.IO"); }
public void Directory_GetParent() { Console.WriteLine("Directory.GetParent()"); var pathCnt = 0; var errorCnt = 0; UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { string expected = null; string actual = null; var skipAssert = false; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]", ++pathCnt, path); // System.IO try { var result = System.IO.Directory.GetParent(path); expected = result == null ? null : result.FullName; } catch (Exception ex) { skipAssert = ex is ArgumentException; Console.WriteLine("\tCaught [System.IO] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t System.IO : [{0}]", expected ?? "null"); // AlphaFS try { var result = Directory.GetParent(path); actual = result == null ? null : result.FullName; if (!skipAssert) { Assert.AreEqual(expected, actual); } } catch (Exception ex) { errorCnt++; Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t AlphaFS : [{0}]", actual ?? "null"); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); Assert.AreEqual(0, errorCnt, "Encountered paths where AlphaFS != System.IO"); }
public void Path_IsPathRooted_LocalAndNetwork_Success() { UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { var action = Alphaleonis.Win32.Filesystem.Path.IsPathRooted(path); Console.WriteLine("\tIsPathRooted: [{0}]\t\tInput Path: [{1}]", action, path); Assert.AreEqual(System.IO.Path.IsPathRooted(path), action); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); }
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 }
public void Path_GetInvalidPathChars_NET() { Console.WriteLine("Path.GetInvalidPathChars()"); Console.WriteLine("\nThe .NET method is used.\n"); UnitTestConstants.StopWatcher(true); foreach (var c in Path.GetInvalidPathChars()) { Console.WriteLine("\tChar: [{0}]", c); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); }
public void AlphaFS_Path_GetLongPath() { Console.WriteLine("Path.GetLongPath()"); var pathCnt = 0; var errorCnt = 0; UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { string actual = null; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]", ++pathCnt, path); // AlphaFS try { actual = Path.GetLongPath(path); if (Path.IsUncPath(path)) { Assert.IsTrue(actual.StartsWith(Path.LongPathUncPrefix), "Path should start with a long unc path prefix."); } else { var c = path[0]; if (!Path.IsPathRooted(path) && ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) { Assert.IsFalse(actual.StartsWith(Path.LongPathPrefix), "Path should not start with a long path prefix."); } else { if (!Path.IsPathRooted(path) && !Utils.IsNullOrWhiteSpace(Path.GetDirectoryName(path))) { Assert.IsTrue(actual.StartsWith(Path.LongPathUncPrefix), "Path should start with a long path prefix."); } } } } catch (Exception ex) { Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); errorCnt++; } Console.WriteLine("\t AlphaFS : [{0}]", actual ?? "null"); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); Assert.AreEqual(0, errorCnt, "No errors were expected."); }
public void Path_HasExtension_NET() { Console.WriteLine("Path.HasExtension()"); Console.WriteLine("\nThe .NET method is used.\n"); UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { var action = Path.HasExtension(path); Console.WriteLine("\tHasExtension: [{0}]\t\tInput Path: [{1}]", action, path); Assert.AreEqual(System.IO.Path.HasExtension(path), action); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); }
private void DumpEnumerateFileIdBothDirectoryInfo(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); var tempPath = UnitTestConstants.SysRoot; if (!isLocal) { tempPath = Path.LocalToUnc(tempPath); } var searchPattern = Path.WildcardStarMatchAll; var directories = Directory.CountFileSystemObjects(tempPath, searchPattern, DirectoryEnumerationOptions.Folders); var files = Directory.CountFileSystemObjects(tempPath, searchPattern, DirectoryEnumerationOptions.Files); Console.WriteLine("\nInput Directory Path: [{0}]\tCounted: Directories = [{1}] Files = [{2}]", tempPath, directories, files); var foundFse = false; long numDirectories = 0; long numFiles = 0; UnitTestConstants.StopWatcher(true); foreach (var fibdi in Directory.EnumerateFileIdBothDirectoryInfo(tempPath)) { if ((fibdi.FileAttributes & FileAttributes.Directory) != 0) { numDirectories++; } else { numFiles++; } foundFse = UnitTestConstants.Dump(fibdi, -22); } var report = UnitTestConstants.Reporter(); Console.WriteLine("\n\tEnumerated: Directories = [{0}] Files = [{1}]\t{2}", numDirectories, numFiles, report); if (!foundFse) { Assert.Inconclusive("Nothing is enumerated, but it is expected."); } var matchAll = directories == numDirectories && files == numFiles; Assert.IsTrue(matchAll, "Number of directories and/or files don't match."); Console.WriteLine(); }
private void DumpOpenConnectionInfo(string host) { Console.WriteLine("\n=== TEST ==="); Console.WriteLine("\nNetwork.Host.EnumerateOpenResources() from host: [{0}]", host); UnitTestConstants.StopWatcher(true); foreach (var connectionInfo in Host.EnumerateOpenConnections(host, "IPC$", false)) { UnitTestConstants.Dump(connectionInfo, -16); } Console.WriteLine(UnitTestConstants.Reporter(true)); Console.WriteLine(); }
public void Path_Combine() { Console.WriteLine("Path.Combine()"); var pathCnt = 0; var errorCnt = 0; UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { foreach (var path2 in UnitTestConstants.InputPaths) { string expected = null; string actual = null; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]\tCombine with: [{2}]", ++pathCnt, path, path2); // System.IO try { expected = System.IO.Path.Combine(path, path2); } catch (Exception ex) { Console.WriteLine("\tCaught [System.IO] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t System.IO : [{0}]", expected ?? "null"); // AlphaFS try { actual = Path.Combine(path, path2); Assert.AreEqual(expected, actual); } catch (Exception ex) { errorCnt++; Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t AlphaFS : [{0}]", actual ?? "null"); } } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); Assert.AreEqual(0, errorCnt, "Encountered paths where AlphaFS != System.IO"); }
private void DumpGetDirectoryNameWithoutRoot(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); const string neDir = "Non-Existing Directory"; const string sys32 = "system32"; var fullPath = Path.Combine(Environment.SystemDirectory, neDir); if (!isLocal) { fullPath = Path.LocalToUnc(fullPath); } UnitTestConstants.StopWatcher(true); var directoryNameWithoutRoot = Path.GetDirectoryNameWithoutRoot(fullPath); Console.WriteLine("\nInput Path: [{0}]\n\tGetDirectoryNameWithoutRoot() (Should be: [{1}]): [{2}]", fullPath, sys32, directoryNameWithoutRoot); Assert.IsTrue(directoryNameWithoutRoot.Equals(sys32, StringComparison.OrdinalIgnoreCase)); fullPath = Path.Combine(fullPath, "Non-Existing file.txt"); if (!isLocal) { fullPath = Path.LocalToUnc(fullPath); } UnitTestConstants.StopWatcher(true); directoryNameWithoutRoot = Path.GetDirectoryNameWithoutRoot(fullPath); Console.WriteLine("\nInput Path: [{0}]\n\tGetDirectoryNameWithoutRoot() (Should be: [{1}]): [{2}]", fullPath, neDir, directoryNameWithoutRoot); Assert.IsTrue(directoryNameWithoutRoot.Equals(neDir, StringComparison.OrdinalIgnoreCase)); fullPath = UnitTestConstants.SysRoot; if (!isLocal) { fullPath = Path.LocalToUnc(fullPath); } UnitTestConstants.StopWatcher(true); directoryNameWithoutRoot = Path.GetDirectoryNameWithoutRoot(fullPath); Console.WriteLine("\nInput Path: [{0}]\n\tGetDirectoryNameWithoutRoot() (Should be: [null]): [{1}]", fullPath, directoryNameWithoutRoot ?? "null"); Assert.AreEqual(null, directoryNameWithoutRoot); Console.WriteLine("\n"); }
public void AlphaFS_Path_IsUncPath() { Console.WriteLine("Path.IsUncPath()"); var pathCnt = 0; var errorCnt = 0; var uncPathCnt = 0; UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { var actual = false; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]", ++pathCnt, path); // AlphaFS try { var expected = path.StartsWith(Path.UncPrefix, StringComparison.OrdinalIgnoreCase); actual = Path.IsUncPath(path); if (!(!path.StartsWith(Path.GlobalRootPrefix, StringComparison.OrdinalIgnoreCase) || !path.StartsWith(Path.VolumePrefix, StringComparison.OrdinalIgnoreCase))) { Assert.AreEqual(expected, actual); } if (actual) { uncPathCnt++; } } catch (Exception ex) { errorCnt++; Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\tAlphaFS : [{0}]", actual); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); // Hand counted 32 True's. Assert.AreEqual(32, uncPathCnt, "Number of UNC paths do not match.", errorCnt); Assert.AreEqual(0, errorCnt, "No errors were expected."); }
private void DumpGetUniqueVolumeNameForPath(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===\n", isLocal ? "LOCAL" : "NETWORK"); var cnt = 0; var testedSystemDrive = false; UnitTestConstants.StopWatcher(true); // Get Logical Drives from UnitTestConstants.Local Host. foreach (var drive in Directory.GetLogicalDrives()) { var tempPath = isLocal ? drive : Path.LocalToUnc(drive); Console.WriteLine("#{0:000}\tInput Path : [{1}]", ++cnt, tempPath); var result = Volume.GetUniqueVolumeNameForPath(tempPath); Console.WriteLine("\tGetUniqueVolumeNameForPath(): [{0}]", result ?? "null"); var deviceName = Volume.GetVolumeDeviceName(tempPath); Console.WriteLine("\tGetVolumeDeviceName() : [{0}]", deviceName ?? "null"); result = null; try { result = Volume.GetVolumeGuid(tempPath); } catch {} Console.WriteLine("\tGetVolumeGuid() : [{0}]\n", result ?? "null"); // At least the system drive should contain valid data. if (isLocal && drive.TrimEnd('\\').Equals(UnitTestConstants.SysDrive)) { Assert.IsFalse(deviceName != null && deviceName.StartsWith(@"\\Device\", StringComparison.OrdinalIgnoreCase)); testedSystemDrive = true; } } Console.WriteLine("\t{0}\n", UnitTestConstants.Reporter(true)); if (isLocal) { if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } Assert.IsTrue(testedSystemDrive); } }
private void DumpEnumerateDrives(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); var host = UnitTestConstants.LocalHost; if (isLocal) { var nonX = Path.GetRandomFileName(); var caughtException = false; Console.WriteLine("\nEnumerating drives from (non-existing) host: [{0}]\n", nonX); UnitTestConstants.StopWatcher(true); try { Host.EnumerateDrives(nonX, false).Any(); } catch (Exception ex) { caughtException = true; Console.Write("Caught (expected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\n{0}\n", UnitTestConstants.Reporter(true)); Assert.IsTrue(caughtException, "No Exception was caught."); Console.Write("\n"); } Console.WriteLine("Enumerating drives from host: [{0}]\n", host); var cnt = 0; UnitTestConstants.StopWatcher(true); foreach (var drive in Host.EnumerateDrives(host, true)) { Console.WriteLine("\t#{0:000}\tDrive: [{1}]", ++cnt, drive); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } Console.WriteLine(); }
private void DumpGetDriveFormat(bool isLocal) { Console.WriteLine("=== TEST {0} ===\n", isLocal ? "LOCAL" : "NETWORK"); var cnt = 0; // Get Logical Drives from Environment. foreach (var drv in Directory.GetLogicalDrives(false, true)) { UnitTestConstants.StopWatcher(true); try { // GetDriveType() can read an empty cdrom drive. // SetCurrentDirectory() wil fail on an empty cdrom drive. System.IO.Directory.SetCurrentDirectory(drv); } catch (Exception ex) { Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } var drive = isLocal ? drv : Path.LocalToUnc(drv); UnitTestConstants.StopWatcher(true); var driveInfo = new DriveInfo(drive); Console.WriteLine("#{0:000}\tInput Path : [{1}]", ++cnt, drive); Console.WriteLine("\tGetDriveFormat(): [{0}]", driveInfo.DriveFormat); Console.WriteLine("\tGetDriveType() : [{0}]", driveInfo.DriveType); Console.WriteLine("\tIsReady() : [{0}]", driveInfo.IsReady); Console.WriteLine("\tIsVolume() : [{0}]\n", driveInfo.IsVolume); if (isLocal) { Assert.AreEqual(new System.IO.DriveInfo(drive).IsReady, driveInfo.IsReady, "IsReady AlphaFS != System.IO"); } } Console.WriteLine("{0}\n\n", UnitTestConstants.Reporter(true)); if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } }
private void DumpGetAssociation(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); var path = isLocal ? UnitTestConstants.SysRoot : Path.LocalToUnc(UnitTestConstants.SysRoot); Console.WriteLine("\nInput Directory Path: [{0}]\n", path); var cnt = 0; foreach (var file in Directory.EnumerateFiles(path)) { var association = Shell32.GetFileAssociation(file); var contentType = Shell32.GetFileContentType(file); var defaultIconPath = Shell32.GetFileDefaultIcon(file); var friendlyAppName = Shell32.GetFileFriendlyAppName(file); var friendlyDocName = Shell32.GetFileFriendlyDocName(file); var openWithApp = Shell32.GetFileOpenWithAppName(file); var verbCommand = Shell32.GetFileVerbCommand(file); Console.WriteLine("\t#{0:000}\t[{1}]\n", ++cnt, file); Console.WriteLine("\t\tGetFileAssociation() : [{0}]", association); Console.WriteLine("\t\tGetFileContentType() : [{0}]", contentType); Console.WriteLine("\t\tGetFileDefaultIcon() : [{0}]", defaultIconPath); Console.WriteLine("\t\tGetFileFriendlyAppName(): [{0}]", friendlyAppName); Console.WriteLine("\t\tGetFileFriendlyDocName(): [{0}]", friendlyDocName); Console.WriteLine("\t\tGetFileOpenWithAppName(): [{0}]", openWithApp); Console.WriteLine("\t\tGetFileVerbCommand() : [{0}]", verbCommand); UnitTestConstants.StopWatcher(true); var shell32Info = Shell32.GetShell32Info(file); var report = UnitTestConstants.Reporter(true); var cmd = "print"; verbCommand = shell32Info.GetVerbCommand(cmd); Console.WriteLine("\n\t\tShell32Info.GetVerbCommand(\"{0}\"): [{1}]", cmd, verbCommand); UnitTestConstants.Dump(shell32Info, -15); Console.WriteLine("\n\t{0}\n\n", report); } Console.WriteLine("\n"); Assert.IsTrue(cnt > 0, "No entries enumerated."); }
private void DumpGetVolumePathName(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===\n", isLocal ? "LOCAL" : "NETWORK"); var tempPath = UnitTestConstants.LocalHostShare; Console.WriteLine("Input Path: [{0}]", tempPath); UnitTestConstants.StopWatcher(true); var volumePathName = Volume.GetVolumePathName(UnitTestConstants.LocalHostShare); var report = UnitTestConstants.Reporter(true); Console.WriteLine("\n\tGetVolumePathName(): [{0}]", volumePathName); Console.WriteLine("\n\t{0}\n", report); if (isLocal) { Assert.IsTrue(tempPath.StartsWith(volumePathName)); } Assert.IsTrue(volumePathName.EndsWith(Path.DirectorySeparator)); }
public void AlphaFS_Volume_EnumerateVolumes() { Console.WriteLine("Volume.EnumerateVolumes()"); Console.WriteLine("\nShould give the same (or more) enumeration as \"mountvol.exe\"\n"); var cnt = 0; UnitTestConstants.StopWatcher(true); foreach (var volume in Volume.EnumerateVolumes()) { Console.WriteLine("#{0:000}\tVolume: [{1}]\n", ++cnt, volume); Console.WriteLine("\tVolume() class methods that accept a volume guid as input argument:\n"); Console.WriteLine("\t\tIsReady() : [{0}]", Volume.IsReady(volume)); Console.WriteLine("\t\tIsVolume() : [{0}]", Volume.IsVolume(volume)); Console.WriteLine("\t\tGetDiskFreeSpace() : [{0}]", Volume.GetDiskFreeSpace(volume).AvailableFreeSpaceUnitSize); var result = Volume.GetDriveFormat(volume); Console.WriteLine("\t\tGetDriveFormat() : [{0}]", result ?? "null"); Console.WriteLine("\t\tGetDriveType() : [{0}]", Volume.GetDriveType(volume)); Console.WriteLine("\t\tGetVolumeLabel() : [{0}]", Volume.GetVolumeLabel(volume)); Console.WriteLine("\t\tGetVolumeDisplayName() : [{0}]", Volume.GetVolumeDisplayName(volume)); foreach (var displayName in Volume.EnumerateVolumePathNames(volume)) { Console.WriteLine("\t\tEnumerateVolumePathNames(): [{0}]", displayName); Assert.IsTrue(!string.IsNullOrWhiteSpace(displayName)); } Console.WriteLine(); } Console.WriteLine("\t{0}\n", UnitTestConstants.Reporter(true)); if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } }
public void AlphaFS_Path_GetRegularPath() { Console.WriteLine("Path.GetRegularPath()"); var pathCnt = 0; var errorCnt = 0; UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { string actual = null; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]", ++pathCnt, path); // AlphaFS try { actual = Path.GetRegularPath(path); if (actual.StartsWith(Path.GlobalRootPrefix, StringComparison.OrdinalIgnoreCase) || actual.StartsWith(Path.VolumePrefix, StringComparison.OrdinalIgnoreCase)) { continue; } Assert.IsFalse(actual.StartsWith(Path.LongPathPrefix, StringComparison.OrdinalIgnoreCase)); } catch (Exception ex) { errorCnt++; Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t AlphaFS : [{0}]", actual ?? "null"); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); Assert.AreEqual(0, errorCnt, "No errors were expected."); }