Ejemplo n.º 1
0
 public static bool IsValidPath(string fileName)
 {
     if (string.IsNullOrWhiteSpace(fileName))
     {
         return(false);
     }
     if (fileName.IndexOfAny(FilePath.GetInvalidPathChars()) >= 0)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        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)));
            }
        }
Ejemplo n.º 4
0
 public void InvalidCharactersAreCloned()
 {
     Assert.AreNotSame(FilePath.GetInvalidFileNameChars(), FilePath.GetInvalidFileNameChars());
     Assert.AreNotSame(FilePath.GetInvalidPathChars(), FilePath.GetInvalidPathChars());
 }
Ejemplo n.º 5
0
 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("#%")));
 }