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(); }
private void AlphaFS_Directory_GetFileSystemEntryInfo_ThrowDirectoryNotFoundException_FileExistsWithSameNameAsDirectory(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 Directory Path: [{0}]", tempPath); ExceptionAssert.DirectoryNotFoundException(() => Alphaleonis.Win32.Filesystem.Directory.GetFileSystemEntryInfo(tempPath)); Console.WriteLine(); }
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(); } }