예제 #1
0
        /// <summary>
        /// 保存测试
        /// </summary>
        public void SaveTest()
        {
            var config = new CatLib.Config.Config();

            config.AddLocator(new CodeConfigLocator());
            config.Set("123", "abc");
            config.Save();
        }
예제 #2
0
        public void GetWithUndefinedTypeConverterTest()
        {
            var config = new CatLib.Config.Config();

            config.AddLocator(new CodeConfigLocator());
            config.Set("123", "123");
            Assert.AreEqual(null, config.Get <ConfigTests>("123"));
        }
예제 #3
0
        public void GetUndefinedTest()
        {
            var config = new CatLib.Config.Config();

            config.AddLocator(new CodeConfigLocator());
            config.Set("123", "123");

            Assert.AreEqual(null, config["222"]);
        }
예제 #4
0
        public void CanNotFindCoverterTest()
        {
            var config = new CatLib.Config.Config();

            config.AddLocator(new CodeConfigLocator());
            ExceptionAssert.Throws <ConverterException>(() =>
            {
                config.Set("123", new ConfigTests());
            });
        }
예제 #5
0
        public void ExceptionConverterTest()
        {
            var config = new CatLib.Config.Config();

            config.AddLocator(new CodeConfigLocator());
            config.Set("123", "abc");

            ExceptionAssert.Throws <ArgumentException>(() =>
            {
                Assert.AreEqual(null, config.Get("123", 0));
            });
        }
예제 #6
0
        public void ConfigUnitSettingTest()
        {
            var config = new CatLib.Config.Config();

            config.AddConverter(typeof(string), new StringStringConverter());
            config.AddLocator(new UnitySettingLocator());

            Assert.AreEqual(null, config.Get <string>("test"));
            config.Set("test", "test");
            Assert.AreEqual("test", config.Get <string>("test"));

            config.Set("test", "222");
            Assert.AreEqual("222", config.Get <string>("test"));

            config.Save();
        }
예제 #7
0
        /// <summary>
        /// 注册管理器
        /// </summary>
        private void RegisterManager()
        {
            App.Singleton <ConfigManager>().Alias <IConfigManager>().OnResolving((bind, obj) =>
            {
                var configManager = obj as ConfigManager;
                if (configManager == null)
                {
                    return(null);
                }

                configManager.Extend(() =>
                {
                    var config = new Config();
                    config.AddLocator(new CodeConfigLocator());
                    return(config);
                });

                return(configManager);
            }).Alias("config.manager");
        }