Beispiel #1
0
        public void EnvironmentChangeFiresPropertyChangeEvents()
        {
            var settings = new SettingsBuilder()
                           .UseSettingsDictionary(_settingsDictionary)
                           .Build <MySettings>(prefix: "");

            //Set up callback to record all property change notifications
            var propertyChangeNotifications = new List <string>();

            settings.PropertyChanged += (sender, args) => propertyChangeNotifications.Add(args.PropertyName);

            //Initial value with no Environment set
            Assert.AreEqual("Key", settings.Key);

            //switching environment changes a
            settings.SetEnvironment("prod");
            Assert.AreEqual("PROD", settings.Key);
            Assert.AreEqual("Key", propertyChangeNotifications.Single());

            //changing env but no properties will change
            settings.SetEnvironment("prod2");
            Assert.AreEqual("PROD", settings.Key);
            //no changes so we shouldn't have received additional events
            Assert.AreEqual("Key", propertyChangeNotifications.Single());
        }
Beispiel #2
0
        public void EnvironmentIsRespected()
        {
            var settings = new SettingsBuilder()
                           .UseSettingsDictionary(_settingsDictionary)
                           .Build();

            //No Configuration, should return unqualified setting
            Assert.AreEqual("Key", settings.Get <string>("Key"));

            settings.SetEnvironment("prod");
            Assert.AreEqual("PROD", settings.Get <string>("Key"));

            settings.SetEnvironment("test");
            Assert.AreEqual("TEST", settings.Get <string>("Key"));
        }