Ejemplo n.º 1
0
        public void SnConfig_SectionName_NonExistingValue()
        {
            using (InMemoryConfigProvider.Create(TestAppSettings, TestConfigSections))
            {
                // existing section, no key
                Assert.IsNull(SnConfig.GetValue <string>("feature1", "NO-KEY"));
                // no section, no key
                Assert.IsNull(SnConfig.GetValue <string>("NO-feature", "NO-KEY"));
                Assert.IsNull(SnConfig.GetValue <string>((string)null, "NO-KEY"));

                // default values
                Assert.AreEqual("DEFAULT", SnConfig.GetValue("feature1", "NO-KEY", "DEFAULT"));
                Assert.AreEqual(99, SnConfig.GetValue("feature1", "NO-KEY", 99));
                Assert.AreEqual(99.9, SnConfig.GetValue("feature1", "NO-KEY", 99.9));
                Assert.IsTrue(SnConfig.GetList("feature1", "NO-KEY", new List <string> {
                    "a", "b"
                })
                              .SequenceEqual(new List <string> {
                    "a", "b"
                }));

                // empty list
                Assert.IsNull(SnConfig.GetList <string>("feature1", "NO-KEY"));
                Assert.IsTrue(SnConfig.GetList("feature1", "NO-KEY", new List <string>(0)).SequenceEqual(new List <string>()));
                Assert.IsTrue(SnConfig.GetListOrEmpty <string>("feature1", "NO-KEY").SequenceEqual(new List <string>()));
            }
        }
Ejemplo n.º 2
0
        public void SnConfig_SectionName_NonExistingValue()
        {
            void Test()
            {
                // existing section, no key
                Assert.IsNull(SnConfig.GetValue <string>("feature1", "NO-KEY"));
                // no section, no key
                Assert.IsNull(SnConfig.GetValue <string>("NO-feature", "NO-KEY"));
                Assert.IsNull(SnConfig.GetValue <string>(null, "NO-KEY"));

                // default values
                Assert.AreEqual("DEFAULT", SnConfig.GetValue("feature1", "NO-KEY", "DEFAULT"));
                Assert.AreEqual(99, SnConfig.GetValue("feature1", "NO-KEY", 99));
                Assert.AreEqual(99.9, SnConfig.GetValue("feature1", "NO-KEY", 99.9));
                Assert.IsTrue(SnConfig.GetList("feature1", "NO-KEY", new List <string> {
                    "a", "b"
                })
                              .SequenceEqual(new List <string> {
                    "a", "b"
                }));

                // empty list
                Assert.IsNull(SnConfig.GetList <string>("feature1", "NO-KEY"));
                Assert.IsTrue(SnConfig.GetList("feature1", "NO-KEY", new List <string>(0)).SequenceEqual(new List <string>()));
                Assert.IsTrue(SnConfig.GetListOrEmpty <string>("feature1", "NO-KEY").SequenceEqual(new List <string>()));
            }

            using (new ConfigurationSwindler(CreateTestConfigurationForMemory()))
                Test();
            using (new ConfigurationSwindler(CreateTestConfigurationForJson()))
                Test();
            using (new ConfigurationSwindler(new SnLegacyConfiguration()))
                Test();
        }
Ejemplo n.º 3
0
        public void SnConfig_SectionName_ExistingValue()
        {
            using (InMemoryConfigProvider.Create(TestAppSettings, TestConfigSections))
            {
                // from section
                Assert.AreEqual("value999", SnConfig.GetValue <string>("feature1", "key1"));
                // from appSettings directly
                Assert.AreEqual("value1", SnConfig.GetValue <string>((string)null, "key1"));
                // from appSettings fallback
                Assert.AreEqual("qwe", SnConfig.GetValue <string>("feature1", "keyX"));

                // empty, but existing key
                Assert.IsTrue(SnConfig.GetList <string>("feature1", "key7").SequenceEqual(new List <string>()));
                Assert.IsTrue(SnConfig.GetListOrEmpty <string>("feature1", "key7").SequenceEqual(new List <string>()));
            }
        }
Ejemplo n.º 4
0
        public void SnConfig_SectionName_ExistingValue()
        {
            void Test()
            {
                // from section
                Assert.AreEqual("value999", SnConfig.GetValue <string>("feature1", "key1"));
                // from root settings directly
                Assert.AreEqual("value1", SnConfig.GetValue <string>(null, "key1"));

                // empty, but existing key
                Assert.IsTrue(SnConfig.GetList <string>("feature1", "key7").SequenceEqual(new List <string>()));
                Assert.IsTrue(SnConfig.GetListOrEmpty <string>("feature1", "key7").SequenceEqual(new List <string>()));
            }

            using (new ConfigurationSwindler(CreateTestConfigurationForMemory()))
            {
                Test();

                // In new environments there should be no fallback: keyX does not exist under feature1.
                Assert.IsNull(SnConfig.GetValue <string>("feature1", "keyX"));
            }
            using (new ConfigurationSwindler(CreateTestConfigurationForJson()))
            {
                Test();

                // In new environments there should be no fallback: keyX does not exist under feature1.
                Assert.IsNull(SnConfig.GetValue <string>("feature1", "keyX"));
            }

            using (new ConfigurationSwindler(new SnLegacyConfiguration()))
            {
                Test();

                // legacy behavior in old environments: appSettings fallback
                Assert.AreEqual("qwe", SnConfig.GetValue <string>("feature1", "keyX"));
            }
        }