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(); }
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."); } } }
public void AlphaFS_Host_ConnectTo_Share_And_DisconnectFrom_Share_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(); // An Exception is thrown for any error, so no Assert needed. try { Console.WriteLine("Connect to share: [{0}]", folder.FullName); Alphaleonis.Win32.Network.Host.ConnectTo(folder.FullName); } finally { Console.WriteLine("\nDisconnect from share."); Alphaleonis.Win32.Network.Host.DisconnectFrom(folder.FullName); } } }
private void AlphaFS_File_GetFileSystemEntryInfo_DirectoryExistsWithSameNameAsFile_ThrowsFileNotFoundException(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.CreateDirectoryRandomizedAttributes(); Console.WriteLine("Input Directory Path: [{0}]", folder.FullName); UnitTestAssert.ThrowsException <System.IO.FileNotFoundException>(() => Alphaleonis.Win32.Filesystem.File.GetFileSystemEntryInfo(folder.FullName)); } Console.WriteLine(); }
public void AlphaFS_Host_DriveConnection_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(); using (var connection = new Alphaleonis.Win32.Network.DriveConnection(folder.FullName)) { Console.WriteLine("Mapped drive [{0}] to share [{1}]", connection.LocalName, folder.FullName); UnitTestConstants.Dump(connection); Assert.AreEqual(folder.FullName, connection.Share); Assert.IsTrue(System.IO.Directory.Exists(folder.FullName)); } } }
private void AlphaFS_Directory_GetFileSystemEntryInfo(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.CreateDirectoryRandomizedAttributes(); Console.WriteLine("Input Directory Path: [{0}]", folder.FullName); var fsei = Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(folder.FullName); UnitTestConstants.Dump(fsei); 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(folder.FullName, fsei.FullPath, "The paths are not equal, but are expected to be."); } Console.WriteLine(); }
public void AlphaFS_Path_GetMappedUncName() { 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(); using (var connection = new Alphaleonis.Win32.Network.DriveConnection(folder.FullName)) { var driveName = connection.LocalName; Console.WriteLine("Mapped drive letter [{0}] to [{1}]", driveName, folder.FullName); UnitTestConstants.Dump(connection, -9); var connectionName = Alphaleonis.Win32.Filesystem.Path.GetMappedUncName(driveName); Assert.AreEqual(folder.FullName, connectionName); } } }
private void AlphaFS_File_Copy_3ExistingFiles_FromVolumeShadowCopy(bool isNetwork) { var testOk = false; using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.CreateDirectoryRandomizedAttributes(); var dosDevices = Alphaleonis.Win32.Filesystem.Volume.QueryAllDosDevices().Where(device => device.StartsWith("HarddiskVolumeShadowCopy", StringComparison.OrdinalIgnoreCase)).ToArray(); foreach (var dosDevice in dosDevices) { if (testOk) { break; } var shadowSource = Alphaleonis.Win32.Filesystem.Path.GlobalRootDevicePrefix + dosDevice; var sourceFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); var drive = System.IO.Directory.GetDirectoryRoot(sourceFolder).TrimEnd('\\'); var globalRoot = sourceFolder.Replace(drive, shadowSource); var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(globalRoot); Console.WriteLine("Input GlobalRoot Path: [{0}]\n", dirInfo.FullName); if (!dirInfo.Exists) { UnitTestAssert.InconclusiveBecauseFileNotFound("No volume shadow copy found."); } var enumOptions = Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive | Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.SkipReparsePoints; var copyCount = 0; foreach (var fileSource in dirInfo.EnumerateFiles(enumOptions)) { if (copyCount == 3) { break; } var fileCopy = System.IO.Path.Combine(folder.FullName, System.IO.Path.GetFileName(fileSource.FullName)); Console.WriteLine("Copy file #{0}.", copyCount + 1); var cmr = Alphaleonis.Win32.Filesystem.File.Copy(fileSource.FullName, fileCopy, Alphaleonis.Win32.Filesystem.CopyOptions.None); UnitTestConstants.Dump(cmr); Console.WriteLine(); Assert.AreEqual((int)Alphaleonis.Win32.Win32Errors.NO_ERROR, cmr.ErrorCode); testOk = true; copyCount++; } } } Console.WriteLine(); if (!testOk) { UnitTestAssert.InconclusiveBecauseResourcesAreUnavailable(); } }