public void AppOnlyBoundSettingTest()
        {
            var envScope = ConfigSettingScope.ForEnvironment("DEV");
            var appScope = ConfigSettingScope.ForApp("APP1");

            var all = new[]
            {
                new ConfigSetting("a", "1"),
                new ConfigSetting("b", "2"),
                new ConfigSetting("c", "3"),

                new ConfigSetting("a", "4")
                {
                    Scope = envScope,
                },

                new ConfigSetting("a", "5")
                {
                    Scope = appScope,
                },
            };

            var effectiveGlobal = EffectiveSettingsEvaluator.GetEffectiveAsDict(all, ConfigSettingScope.Global);
            var effectiveForEnv = EffectiveSettingsEvaluator.GetEffectiveAsDict(all, envScope);
            var effectiveForApp = EffectiveSettingsEvaluator.GetEffectiveAsDict(all, appScope);

            Assert.AreEqual("1", effectiveGlobal["a"].Definition);
            Assert.AreEqual("4", effectiveForEnv["a"].Definition);
            Assert.AreEqual("5", effectiveForApp["a"].Definition);
        }
Exemple #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
        }