Exemple #1
0
 public static bool IsValidFileName(string fileName)
 {
     if (string.IsNullOrWhiteSpace(fileName))
     {
         return(false);
     }
     if (fileName.IndexOfAny(FilePath.GetInvalidFileNameChars()) >= 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #2
0
 public static bool IsValidFileName(string fileName)
 {
     if (String.IsNullOrEmpty(fileName) || fileName.Trim() == string.Empty)
     {
         return(false);
     }
     if (fileName.IndexOfAny(FilePath.GetInvalidFileNameChars()) >= 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #3
0
        public void InvalidFileCharsTests()
        {
            Assert.True(FileService.IsValidFileName("file"), "File without extension");
            Assert.True(FileService.IsValidFileName("text.txt"), "File with extension");
            Assert.True(FileService.IsValidFileName(".gitignore"), "Dot file");

            Assert.False(FileService.IsValidFileName(""), "Empty string");
            Assert.False(FileService.IsValidFileName("  "), "Whitespace string");

            // Test strings containing an invalid character.
            foreach (var c in FilePath.GetInvalidFileNameChars())
            {
                Assert.False(FileService.IsValidFileName(c.ToString()),
                             string.Format("String with {0} (charcode: {1})", Char.IsControl(c) ? "<Control Char>" : c.ToString(), Convert.ToInt32(c)));
            }
        }
Exemple #4
0
 public void InvalidCharactersAreCloned()
 {
     Assert.AreNotSame(FilePath.GetInvalidFileNameChars(), FilePath.GetInvalidFileNameChars());
     Assert.AreNotSame(FilePath.GetInvalidPathChars(), FilePath.GetInvalidPathChars());
 }
Exemple #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("#%")));
 }