コード例 #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>()));
            }
        }
コード例 #2
0
ファイル: SnConfigTests.cs プロジェクト: pcodex/sn-tools
        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();
        }
コード例 #3
0
 public void SnConfig_TypeConversion_Error1()
 {
     using (InMemoryConfigProvider.Create(TestAppSettings, TestConfigSections))
     {
         // type conversion error
         SnConfig.GetValue <int>("feature1", "key1");
     }
 }
コード例 #4
0
ファイル: SnConfigTests.cs プロジェクト: pcodex/sn-tools
        public void SnConfig_TypeConversion_Error1()
        {
            void Test()
            {
                // type conversion error
                SnConfig.GetValue <int>("feature1", "key1");
            }

            using (new ConfigurationSwindler(CreateTestConfigurationForMemory()))
                Test();
        }
コード例 #5
0
ファイル: SnConfigTests.cs プロジェクト: pcodex/sn-tools
        public void SnConfig_Legacy_ConnectionString()
        {
            void Test()
            {
                Assert.AreEqual("csvalue1", SnConfig.GetValue <string>("connectionStrings", "cs1"));
                Assert.AreEqual("csvalue1", SnConfig.GetValue <string>("ConnectionStrings", "cs1"));
            }

            using (new ConfigurationSwindler(new SnLegacyConfiguration()))
                Test();
        }
コード例 #6
0
ファイル: SnConfigTests.cs プロジェクト: pcodex/sn-tools
        public void SnConfig_SectionName_Subsection()
        {
            void Test()
            {
                Assert.AreEqual("subvalue1", SnConfig.GetValue <string>("sensenet/subsection", "key1"));
                Assert.AreEqual("subvalue1", SnConfig.GetValue <string>("sensenet:subsection", "key1"));
            }

            using (new ConfigurationSwindler(CreateTestConfigurationForMemory()))
                Test();
            using (new ConfigurationSwindler(new SnLegacyConfiguration()))
                Test();
        }
コード例 #7
0
        public void SnConfig_SectionName_TypeConversion()
        {
            using (InMemoryConfigProvider.Create(TestAppSettings, TestConfigSections))
            {
                Assert.AreEqual(456, SnConfig.GetValue <int>("feature1", "key2"));
                Assert.AreEqual(3.4, SnConfig.GetValue <double>("feature1", "key3"));
                Assert.AreEqual(ConfigEnum.Value2, SnConfig.GetValue <ConfigEnum>("feature1", "key6"));

                var a1 = SnConfig.GetList <string>("feature1", "key4");
                Assert.IsTrue(a1.SequenceEqual(new [] { "d", "e", "f" }));

                var a2 = SnConfig.GetList <int>("feature1", "key5");
                Assert.IsTrue(a2.SequenceEqual(new[] { 7, 8, 9 }));
            }
        }
コード例 #8
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>()));
            }
        }
コード例 #9
0
ファイル: SnConfigTests.cs プロジェクト: pcodex/sn-tools
        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"));
            }
        }
コード例 #10
0
ファイル: SnConfigTests.cs プロジェクト: pcodex/sn-tools
        public void SnConfig_SectionName_TypeConversion()
        {
            void Test()
            {
                Assert.AreEqual(456, SnConfig.GetValue <int>("feature1", "key2"));
                Assert.AreEqual(3.4, SnConfig.GetValue <double>("feature1", "key3"));
                Assert.AreEqual(ConfigEnum.Value2, SnConfig.GetValue <ConfigEnum>("feature1", "key6"));

                var a1 = SnConfig.GetList <string>("feature1", "key4");

                Assert.IsTrue(a1.SequenceEqual(new [] { "d", "e", "f" }));

                var a2 = SnConfig.GetList <int>("feature1", "key5");

                Assert.IsTrue(a2.SequenceEqual(new[] { 7, 8, 9 }));
            }

            using (new ConfigurationSwindler(CreateTestConfigurationForMemory()))
                Test();
            using (new ConfigurationSwindler(CreateTestConfigurationForJson()))
                Test();
            using (new ConfigurationSwindler(new SnLegacyConfiguration()))
                Test();
        }