Esempio n. 1
0
        public void BasicTest()
        {
            var ocs = new ObjectConfigStore(() => new Config()
            {
                Settings = new[]
                {
                    new ConfigSetting("a", "1"),
                    new ConfigSetting("b", "2"),
                    new ConfigSetting("c", "3"),
                }
            });

            var client = new ConfigClient(ocs, ConfigSettingScope.Global);

            Assert.AreEqual(3, client.GetAll().Count);
            Assert.AreEqual("1", client.Get("a"));
            Assert.AreEqual("2", client.Get("b"));
            Assert.AreEqual("3", client.Get("c"));
        }
Esempio n. 2
0
        public void BasicScopingTest()
        {
            var ocs = new ObjectConfigStore(() => new Config()
            {
                Settings = new[]
                {
                    new ConfigSetting("a", "1"),
                    new ConfigSetting("b", "2")
                    {
                        Scope = ConfigSettingScope.ForApp("X")
                    },
                    new ConfigSetting("b", "3")
                    {
                        Scope = ConfigSettingScope.ForApp("Y")
                    },
                }
            });

            #region Global
            var globalClient = new ConfigClient(ocs, ConfigSettingScope.Global);

            Assert.AreEqual(1, globalClient.GetAll().Count);
            Assert.AreEqual("1", globalClient.Get("a"));
            #endregion

            #region App X
            var appXClient = new ConfigClient(ocs, ConfigSettingScope.ForApp("X"));

            Assert.AreEqual(2, appXClient.GetAll().Count);
            Assert.AreEqual("1", appXClient.Get("a"));
            Assert.AreEqual("2", appXClient.Get("b"));
            #endregion

            #region App Y
            var appYClient = new ConfigClient(ocs, ConfigSettingScope.ForApp("Y"));

            Assert.AreEqual(2, appYClient.GetAll().Count);
            Assert.AreEqual("1", appYClient.Get("a"));
            Assert.AreEqual("3", appYClient.Get("b"));
            #endregion
        }
Esempio n. 3
0
        public void BasicReferencesTest()
        {
            var ocs = new ObjectConfigStore(() => new Config()
            {
                Settings = new[]
                {
                    new ConfigSetting("a", "1"),
                    new ConfigSetting("b", "2${a}")
                }
            });

            var globalClient = new ConfigClient(ocs, ConfigSettingScope.Global);

            Assert.AreEqual("21", globalClient.Get("b"));
        }
Esempio n. 4
0
        public void MultiLevelReferencesTest()
        {
            var ocs = new ObjectConfigStore(() => new Config()
            {
                Settings = new[]
                {
                    new ConfigSetting("a", "1"),
                    new ConfigSetting("b", "2${a}"),
                    new ConfigSetting("c", "${a}+${b}"),
                }
            });

            var globalClient = new ConfigClient(ocs, ConfigSettingScope.Global);

            Assert.AreEqual("1+21", globalClient.Get("c"));
        }
Esempio n. 5
0
        public void LoadConfigsTest()
        {
            var client = new ConfigClient("1", "2", "http://");

            client.LoadConfigs(null);

            var item = client.Get("x");

            Assert.IsNull(item);
            var item1 = client["x"];

            Assert.IsNull(item1);

            var items = client.GetGroup("x");

            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, 0);

            var configs = new List <ConfigItem>();

            client.LoadConfigs(configs);
            item = client.Get("x");
            Assert.IsNull(item);
            item1 = client["x"];
            Assert.IsNull(item1);

            items = client.GetGroup("x");
            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, 0);

            configs = new List <ConfigItem>()
            {
                new ConfigItem
                {
                    key   = "a",
                    value = "b",
                }
            };
            client.LoadConfigs(configs);
            item = client.Get("x");
            Assert.IsNull(item);
            item1 = client["x"];
            Assert.IsNull(item1);

            items = client.GetGroup("x");
            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, 0);

            item = client.Get("a");
            Assert.IsNotNull(item);
            Assert.AreEqual("b", item);
            item1 = client["a"];
            Assert.IsNotNull(item1);
            Assert.AreEqual("b", item1);

            configs = new List <ConfigItem>()
            {
                new ConfigItem
                {
                    key   = "a",
                    value = "b",
                },
                new ConfigItem
                {
                    key   = "a1",
                    value = "b1",
                    group = "g"
                }
            };
            client.LoadConfigs(configs);
            item = client.Get("x");
            Assert.IsNull(item);
            item1 = client["x"];
            Assert.IsNull(item);

            items = client.GetGroup("x");
            Assert.IsNotNull(items);
            Assert.AreEqual(items.Count, 0);

            item = client.Get("a");
            Assert.IsNotNull(item);
            Assert.AreEqual("b", item);
            item1 = client["a"];
            Assert.IsNotNull(item1);
            Assert.AreEqual("b", item1);

            item = client.Get("g:a1");
            Assert.IsNotNull(item);
            Assert.AreEqual("b1", item);
            item1 = client["g:a1"];
            Assert.IsNotNull(item1);

            items = client.GetGroup("g");
            Assert.IsNotNull(items);
            Assert.AreEqual(1, items.Count);

            var config = items[0];

            Assert.IsNotNull(config);
            Assert.AreEqual(config.value, "b1");
        }