Esempio n. 1
0
 public CaseModel Func_UseFilePath()
 {
     return(new CaseModel()
     {
         NameSign = @"准备使用文件路径",
         ExeEvent = () => {
             KeyString[] paths = new KeyString[] {
                 new KeyString()
                 {
                     Key = null,
                     Value = string.Empty, // 为空, 默认跳过
                 },
                 new KeyString()
                 {
                     Key = string.Empty, // 目录为空, 默认为 "/"
                     Value = "name.yts",
                 },
                 new KeyString()
                 {
                     Key = "qqqq/sss/",
                     Value = string.Empty, // 为空, 默认跳过
                 },
                 new KeyString()
                 {
                     Key = "ttt/rrr/",
                     Value = "name.yts",
                 },
                 new KeyString()
                 {
                     Key = "uuu/iii/",
                     Value = "/eee/name.yts", // 过滤非法字符为: eeename.yts
                 },
                 new KeyString()
                 {
                     Key = "/",
                     Value = "fff.yts",
                 },
                 new KeyString()
                 {
                     Key = "/aaa",
                     Value = "aaa.yts",
                 },
                 new KeyString()
                 {
                     Key = "/rrr/xxx",
                     Value = "aaa.yts",
                 },
                 new KeyString()
                 {
                     Key = "/rrr/xxx/",
                     Value = "hhh.yts",
                 },
                 new KeyString()
                 {
                     Key = "/vvv/yyy",
                     Value = "\\rr/www/aaa.yts", // 过滤非法字符为: rrwwwaaa.yts
                 },
             };
             foreach (KeyString item in paths)
             {
                 string absfilepath = PathHelp.CreateUseFilePath("/test_PathHelp/" + item.Key, item.Value);
                 if (CheckData.IsStringNull(absfilepath))
                 {
                     if (CheckData.IsStringNull(item.Key) || CheckData.IsStringNull(item.Value))
                     {
                         continue;
                     }
                     else
                     {
                         Console.WriteLine("结果为空, 两个参数都不为空, 不合理", item.Key);
                         Console.WriteLine("directory: {0}", item.Key);
                         Console.WriteLine(" filename: {0}", item.Value);
                         Console.WriteLine(" abs_file: {0}", absfilepath);
                         return false;
                     }
                 }
                 PathHelp.CreateFileExists(absfilepath);
                 if (!File.Exists(absfilepath))
                 {
                     Console.WriteLine("文件并没有被创建", item.Key);
                     Console.WriteLine("directory: {0}", item.Key);
                     Console.WriteLine(" filename: {0}", item.Value);
                     Console.WriteLine(" abs_file: {0}", absfilepath);
                     return false;
                 }
             }
             return true;
         },
     });
 }