public void GetFullPathNameForCurrent() { string fullPath = FileMethods.GetFullPathName("."); fullPath.Length.Should().BeGreaterThan(2); fullPath[1].Should().Be(':'); }
public void ValidateKnownRelativeBehaviors(string value, string expected) { // Set the current directory to D: and the hidden env for C:'s last current directory ProcessDesktopMethods.SetEnvironmentVariable(@"=C:", @"C:\Users"); using (new TempCurrentDirectory(@"D:\")) { FileMethods.GetFullPathName(value).Should().Be(expected); } }
public void ValidateKnownRelativeBehaviors(string value, string expected) { // TODO: Need to modify to work with actually present drives and skip if there // isn't more than one. // Set the current directory to D: and the hidden env for C:'s last current directory ProcessMethods.SetEnvironmentVariable(@"=C:", @"C:\Users"); using (new TempCurrentDirectory(@"E:\")) { FileMethods.GetFullPathName(value).Should().Be(expected); } }
public void GetFullPathNameLongPathBehaviors() { // ERROR_FILENAME_EXCED_RANGE (206) // GetFullPathName will fail if the passed in patch is longer than short.MaxValue - 2, even if the path will normalize below that value. // FileMethods.GetFullPathName(PathGenerator.CreatePathOfLength(@"C:\..\..\..\..", short.MaxValue - 2)); // ERROR_INVALID_NAME (123) // GetFullPathName will fail if the passed in path normalizes over short.MaxValue - 2 // FileMethods.GetFullPathName(new string('a', short.MaxValue - 2)); FileMethods.GetFullPathName(PathGenerator.CreatePathOfLength(FileMethods.GetTempPath(), short.MaxValue - 2)); // Works // NativeMethods.FileManagement.GetFullPathName(PathGenerator.CreatePathOfLength(@"C:\", short.MaxValue - 2)); }
public void OpenFileWithTrailingSeparator() { using (var cleaner = new TestFileCleaner()) { string testFile = cleaner.CreateTestFile(nameof(OpenFileWithTrailingSeparator)); string fullName = FileMethods.GetFullPathName(Paths.AddTrailingSeparator(testFile)); FindOperation <string> find = new FindOperation <string>(testFile); Action action = () => find.FirstOrDefault(); action.ShouldThrow <ArgumentException>().And.HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_INVALID_PARAMETER)); action = () => FileMethods.CreateFile(Paths.AddTrailingSeparator(testFile), CreationDisposition.OpenExisting, DesiredAccess.ReadAttributes); action.ShouldThrow <WInteropIOException>().And.HResult.Should().Be((int)ErrorMacros.HRESULT_FROM_WIN32(WindowsError.ERROR_INVALID_NAME)); } }
public void GetFullPathBasic() { string tempPath = FileMethods.GetTempPath(); FileMethods.GetFullPathName(tempPath).Should().NotBeNullOrWhiteSpace(); }
public void ValidateKnownFixedBehaviors(string value, string expected) { FileMethods.GetFullPathName(value).Should().Be(expected, $"source was {value}"); }
public void FullPathErrorCases(string value) { Action action = () => FileMethods.GetFullPathName(value); action.ShouldThrow <System.IO.IOException>(); }