public static bool IsValidPath(string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { return(false); } if (fileName.IndexOfAny(FilePath.GetInvalidPathChars()) >= 0) { return(false); } return(true); }
public static bool IsValidPath(string fileName) { if (String.IsNullOrEmpty(fileName) || fileName.Trim() == string.Empty) { return(false); } if (fileName.IndexOfAny(FilePath.GetInvalidPathChars()) >= 0) { return(false); } return(true); }
public void InvalidPathCharsTests() { Assert.True(FileService.IsValidPath("./relative_file"), "Relative path string"); Assert.True(FileService.IsValidPath("/path/to/file"), "Absolute unix path string"); Assert.True(FileService.IsValidPath("Drive:\\some\\path\\here"), "Absolute windows path string"); Assert.False(FileService.IsValidPath(""), "Empty string"); Assert.False(FileService.IsValidPath(" "), "Whitespace string"); // Test strings containing an invalid character. foreach (var c in FilePath.GetInvalidPathChars()) { Assert.False(FileService.IsValidPath(c.ToString()), string.Format("String with {0} (charcode: {1})", Char.IsControl(c) ? "<Control Char>" : c.ToString(), Convert.ToInt32(c))); } }
public void InvalidCharactersAreCloned() { Assert.AreNotSame(FilePath.GetInvalidFileNameChars(), FilePath.GetInvalidFileNameChars()); Assert.AreNotSame(FilePath.GetInvalidPathChars(), FilePath.GetInvalidPathChars()); }
public void InvalidCharactersTests() { // Assert compatibility so we know something changed over here. Assert.That(FilePath.GetInvalidFileNameChars(), Is.EquivalentTo(Path.GetInvalidFileNameChars().Concat("#%"))); Assert.That(FilePath.GetInvalidPathChars(), Is.EquivalentTo(Path.GetInvalidPathChars().Concat("#%"))); }