Пример #1
0
        public void WriteTest()
        {
            string fileName = string.Empty; 
            fileName = "temp.appsettings";
            ConfigTempFile target = new ConfigTempFile(fileName); 
            string key = string.Empty; 
            object oldVal = null; 
            object newVal = null; 
            Exception ex = null;
            try
            {
                target.Write(key, oldVal, newVal);
            }
            catch (Exception e)
            {
                ex = e;
            }
            Assert.IsNotNull(ex, "出现异常!");

            ex = null;
            key = "lala";
            oldVal = "gaga";
            newVal = "haha";
            try
            {
                target.Write(key, oldVal, newVal);
            }
            catch (Exception e)
            {
                ex = e;
            }
            Assert.IsNull(ex);
        }
Пример #2
0
 /// <summary>
 /// 从Bean对应的文件中读取键值对 加载进内存
 /// </summary>
 protected override void Load()
 {
     file = new ConfigTempFile(filename);
     if (file.Exists())
         SetNameValues(file.FullFileName);
 }
Пример #3
0
        public void GetTest()
        {
            string fileName = string.Empty;
            fileName = "temp.appsettings";
            ConfigTempFile target = new ConfigTempFile(fileName); 
            string key = string.Empty;
            object actual;
            //key不存在,抛出异常
            bool ret = false;
            try
            {
                actual = target.Get(key);
            }
            catch (Exception)
            {
                ret = true;
            }
            Assert.IsTrue(ret);
            //key不存在
            key = "abc";
            actual = target.Get(key);
            Assert.IsNull(actual);

            //key存在本地的临时文件中
            //key = "test";
            //actual = target.Get(key);
            //Assert.AreNotEqual(expected, actual);
        }
Пример #4
0
 /// <summary>
 /// 根据文件名得到文件实例
 /// </summary>
 /// <param name="fileName">文件名</param>
 /// <returns>实例文件对象</returns>
 public FileBase GetFileInstance(string fileName)
 {
     FileBase file = null;
     fileName = FormatFileNameToName(fileName);
     if (!readers.TryGetValue(fileName, out file))
     {
         if (CheckDirExistsFile(FileConst.TempDir, fileName))
         {
             //临时目录找到,实例化临时文件对象
             file = new ConfigTempFile(fileName);
         }
         else if (CheckDirExistsFile(FileConst.ConfigDir, fileName))
         {
             //配置目录找到,实例化配置文件对象
             file = new ConfigDirFile(fileName);
         }
         else if (CheckDirExistsFile(FileConst.RuntimeDir, fileName))
         {
             //运行时目录找到,实例化运行时文件对象
             file = new ConfigRunDirFile(fileName);
         }
         if (file != null)
         {
             readers.TryAdd(fileName, file);
         }
     }
     return file;
 }