public void GetFileNameBasic() { string tempPath = FileMethods.GetTempPath(); using (var directory = DirectoryMethods.CreateDirectoryHandle(tempPath)) { // This will give back the local path (minus the device, eg \Users\... or \Server\Share\...) string name = FileMethods.GetFileName(directory); tempPath.Should().EndWith(Paths.AddTrailingSeparator(name)); } }
public void QueryDosVolumePathBasic() { string tempPath = FileMethods.GetTempPath(); using (var directory = DirectoryMethods.CreateDirectoryHandle(tempPath)) { // This will give back the NT path (\Device\HarddiskVolumen...) string fullName = HandleMethods.GetObjectName(directory); string fileName = FileMethods.GetFileName(directory); string deviceName = fullName.Substring(0, fullName.Length - fileName.Length); string dosVolumePath = DeviceMethods.QueryDosVolumePath(deviceName); tempPath.Should().StartWith(dosVolumePath); tempPath.Should().Be(dosVolumePath + fileName + @"\"); } }
public void GetPipeObjectInfo() { var fileHandle = FileMethods.CreateFileSystemIo( @"\\.\pipe\", 0, // We don't care about read or write, we're just getting metadata with this handle System.IO.FileShare.ReadWrite, System.IO.FileMode.Open, 0, FileFlags.OpenReparsePoint // To avoid traversing links | FileFlags.BackupSemantics); // To open directories string name = HandleMethods.GetObjectName(fileHandle); name.Should().Be(@"\Device\NamedPipe\"); string typeName = HandleMethods.GetObjectType(fileHandle); typeName.Should().Be(@"File"); string fileName = FileMethods.GetFileName(fileHandle); fileName.Should().Be(@"\"); }
public void GetPipeObjectInfoNoTrailingSlash() { var fileHandle = FileMethods.CreateFileSystemIo( @"\\.\pipe", 0, // We don't care about read or write, we're just getting metadata with this handle System.IO.FileShare.ReadWrite, System.IO.FileMode.Open, 0, FileFlags.OpenReparsePoint // To avoid traversing links | FileFlags.BackupSemantics); // To open directories string name = HandleMethods.GetObjectName(fileHandle); name.Should().Be(@"\Device\NamedPipe"); string typeName = HandleMethods.GetObjectType(fileHandle); typeName.Should().Be(@"File"); // Not sure why this is- probably the source of why so many other things go wrong Action action = () => FileMethods.GetFileName(fileHandle); action.ShouldThrow <ArgumentException>().And.HResult.Should().Be(unchecked ((int)0x80070057)); }