示例#1
0
        public void LoadConfig2SubSections()
        {
            var stfConfiguration = new StfConfiguration();
            var conf             = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config1.xml");

            Assert.AreEqual(1, conf.Sections.Count, 1);
            var sectionTotest = conf.Sections["SectionName"];

            Assert.AreEqual("SectionName", sectionTotest.SectionName);
            Assert.AreEqual("SubSectionName1", sectionTotest.DefaultSection);
            Assert.AreEqual(2, sectionTotest.Sections.Count);
            Assert.AreEqual(1, sectionTotest.Keys.Count);
            Assert.AreEqual("config1_key1value", sectionTotest.Keys["k1"].KeyValue);

            // first subkey
            sectionTotest = conf.Sections["SectionName"].Sections["SubSectionName1"];
            Assert.AreEqual(1, sectionTotest.Keys.Count);
            Assert.AreEqual("SubSectionName1", sectionTotest.SectionName);
            Assert.IsTrue(string.IsNullOrEmpty(sectionTotest.DefaultSection));
            Assert.AreEqual("config1_subkey1value", sectionTotest.Keys["sk1"].KeyValue);
            Assert.AreEqual(0, sectionTotest.Sections.Count);

            // second subkey
            sectionTotest = conf.Sections["SectionName"].Sections["SubSectionName2"];
            Assert.AreEqual(1, sectionTotest.Keys.Count);
            Assert.AreEqual("SubSectionName2", sectionTotest.SectionName);
            Assert.IsTrue(string.IsNullOrEmpty(sectionTotest.DefaultSection));
            Assert.AreEqual("config1_subkey2value", sectionTotest.Keys["sk2"].KeyValue);
            Assert.AreEqual(0, sectionTotest.Sections.Count);
        }
示例#2
0
        /// <summary>
        /// The assembly stf configuration.
        /// </summary>
        private void AssembleStfConfigurationBeforePlugins()
        {
            var stfConfigurationFile = Path.Combine(StfConfigDir, @"StfConfiguration.xml");

            if (!File.Exists(stfConfigurationFile))
            {
                KernelLogger.LogInfo($"StfConfiguration file not found - creating default [{stfConfigurationFile}]");

                if (!CreateDefaultStfConfigurationFile(stfConfigurationFile))
                {
                    KernelLogger.LogInfo($"Couldn't create Default Configuration file not found - name [{stfConfigurationFile}]");
                }
            }

            if (File.Exists(stfConfigurationFile))
            {
                KernelLogger.LogInfo($"StfConfiguration created using [{stfConfigurationFile}]");
                StfConfiguration = new StfConfiguration(stfConfigurationFile);
            }
            else
            {
                StfConfiguration = new StfConfiguration();
                KernelLogger.LogInfo($"StfConfiguration created using no file as [{stfConfigurationFile}] doesn't exist");
            }

            // need to be able to control something for plugins - like plugin path:-)
            OverlayStfConfigurationForOneSettingType(StfConfigDir, ConfigurationFileType.Machine);
        }
示例#3
0
        public void ParserSimpleVariable2()
        {
            var stfConfiguration = new StfConfiguration();
            var conf             = stfConfiguration.LoadConfig(@"TestData\Parser\parser1.xml");

            var key2Value = stfConfiguration.GetKeyValue(conf, "SectionName.SubSectionName.k2");

            Assert.AreEqual("config_key2value", key2Value);
        }
示例#4
0
        public void OverLayNullWithSimple()
        {
            var stfConfiguration = new StfConfiguration();
            var conf2            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config2.xml");
            var overLay          = stfConfiguration.OverLay(null, conf2);

            DumpTree(overLay, @"overLay.xml");
            DumpTree(conf2, @"expected.xml");

            Assert.IsTrue(conf2.Identical(conf2, overLay));
        }
示例#5
0
        public void TestSetValueOnExistingKey()
        {
            var stfConfiguration = new StfConfiguration(@"TestData\Defaulting\NoDefaultSection.xml");

            StfAssert.IsFalse("Trying to set non existing value",
                              stfConfiguration.SetConfigValue("Users.Ulrich.FortyTwo", "New_Ulrich"));

            string configValue;

            StfAssert.IsFalse("Can't get value", stfConfiguration.TryGetKeyValue("Users.Ulrich.FortyTwo", out configValue));
        }
示例#6
0
        public void OverLayConfigConfigOneSectionWithinOneSectionWithinOneSection()
        {
            var stfConfiguration = new StfConfiguration();
            var conf1            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigOneSectionWithinOneSectionWithinOneSection.xml");
            var conf2            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigOneSectionWithinOneSectionWithinOneSection.xml");
            var overLay          = stfConfiguration.OverLay(conf1, conf2);

            DumpTree(overLay, @"overLay.xml");
            DumpTree(conf2, @"expected.xml");

            Assert.IsTrue(conf2.Identical(conf2, overLay));
        }
示例#7
0
        public void LoadConfigTwoSectionsSideBySide()
        {
            var stfConfiguration = new StfConfiguration();
            var conf             = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigTwoSectionsSideBySide.xml");

            var sectionTotest = conf.Sections["SectionNameFirst"];

            Assert.AreEqual("SectionNameFirst", sectionTotest.SectionName);

            sectionTotest = conf.Sections["SectionNameSecond"];
            Assert.AreEqual("SectionNameSecond", sectionTotest.SectionName);
        }
示例#8
0
        public void LoadConfigOneSectionWithinOneSection()
        {
            var stfConfiguration = new StfConfiguration();
            var conf             = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigOneSectionWithinOneSection.xml");

            var sectionTotest = conf.Sections["SectionNameOuter"];

            Assert.AreEqual("SectionNameOuter", sectionTotest.SectionName);

            sectionTotest = sectionTotest.Sections["SectionNameInner"];
            Assert.AreEqual("SectionNameInner", sectionTotest.SectionName);
        }
示例#9
0
        public void OverLay23()
        {
            var stfConfiguration = new StfConfiguration();
            var conf2            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config2.xml");
            var conf3            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config3.xml");
            var conf23           = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config23.xml");
            var overLay          = stfConfiguration.OverLay(conf2, conf3);

            DumpTree(overLay, @"overLay.xml");
            DumpTree(conf23, @"expected.xml");

            Assert.IsTrue(conf2.Identical(conf23, overLay));
        }
示例#10
0
        public void OverLayConfigWithDuplicatedSection()
        {
            var stfConfiguration = new StfConfiguration();
            var conf1            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigWithDuplicatedSection.xml");
            var conf2            = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigWithDuplicatedSectionOverlay.xml");
            var overLay          = stfConfiguration.OverLay(conf1, conf2);
            var confExpected     = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\ConfigWithDuplicatedSectionExpected.xml");

            DumpTree(overLay, @"overLay.xml");
            DumpTree(confExpected, @"confExpected.xml");

            StfAssert.IsTrue("Comparing", confExpected.Identical(confExpected, overLay));
        }
示例#11
0
        /// <summary>
        /// The set config.
        /// </summary>
        /// <typeparam name="T">
        /// The configuration object that needs to have config values set
        /// </typeparam>
        /// <returns>
        /// The configuration object where properties has been set by the stf configuration
        /// </returns>
        protected T SetConfig <T>() where T : class, new()
        {
            if (StfConfiguration == null)
            {
                return(default(T));
            }

            var configObject = new T();

            StfConfiguration.LoadUserConfiguration(configObject);

            return(configObject);
        }
示例#12
0
        public void LoadConfig1Section2Keys()
        {
            var stfConfiguration = new StfConfiguration();
            var conf             = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config3.xml");

            var sectionTotest = conf.Sections["SectionName"];

            Assert.AreEqual("SectionName", sectionTotest.SectionName);
            Assert.AreEqual(0, sectionTotest.Sections.Count);
            Assert.AreEqual(2, sectionTotest.Keys.Count);
            Assert.AreEqual("config3_key2value", sectionTotest.Keys["k2"].KeyValue);
            Assert.AreEqual("config3_key3value", sectionTotest.Keys["k3"].KeyValue);
        }
示例#13
0
        public void LoadConfig1Section1Key()
        {
            var stfConfiguration = new StfConfiguration();
            var conf             = stfConfiguration.LoadConfig(@"TestData\ConfigOverlay\Config2.xml");

            Assert.AreEqual(1, conf.Sections.Count);
            var sectionTotest = conf.Sections["SectionName"];

            Assert.AreEqual("SectionName", sectionTotest.SectionName);
            Assert.AreEqual(0, sectionTotest.Sections.Count);
            Assert.AreEqual(1, sectionTotest.Keys.Count);
            Assert.AreEqual("config2_key1value", sectionTotest.Keys["k1"].KeyValue);
        }
示例#14
0
        public void TestDefaultNoDefaultSection()
        {
            // Load a configuration in StfConfiguration
            var stfConfiguration = new StfConfiguration(@"TestData\Defaulting\NoDefaultSection.xml");

            var uUsername = stfConfiguration.GetKeyValue("Users.Ulrich.Username");
            var uPassword = stfConfiguration.GetKeyValue("Users.Ulrich.Password");
            var kUsername = stfConfiguration.GetKeyValue("Users.Kasper.Username");
            var kPassword = stfConfiguration.GetKeyValue("Users.Kasper.Password");

            StfAssert.AreEqual("Username is Ulrich", "User_Ulrich", uUsername);
            StfAssert.AreEqual("Password for Ulrich is U777", "U777", uPassword);
            StfAssert.AreEqual("Username is Kasper", "User_Kasper", kUsername);
            StfAssert.AreEqual("Password for Kasper is K999", "K999", kPassword);
        }
示例#15
0
        public void MakeCopyTests()
        {
            var stfConfiguration = new StfConfiguration();

            var configFiles = Directory.EnumerateFiles(".", "config*.xml");

            foreach (var configFile in configFiles)
            {
                var conf     = stfConfiguration.LoadConfig(configFile);
                var confCopy = conf.MakeCopy();

                DumpTree(conf, "Original" + configFile.Replace(@".\", string.Empty));
                DumpTree(confCopy, "Copy" + configFile.Replace(@".\", string.Empty));

                Assert.IsTrue(conf.Identical(conf, confCopy));
            }
        }
示例#16
0
        public void ReflectionTestMethod1()
        {
            var tmc1 = new TestMethod1Class
            {
                PropPublicString1 = "pupStr1",
                PropPublicString2 = "pupStr2"
            };

            // Load a configuration in StfConfiguration
            var stfConfiguration = new StfConfiguration(@"TestData\Reflection\Reflection1.xml");

            // Load that (resolved) configuration into the User Object
            var props = stfConfiguration.LoadUserConfiguration(tmc1);

            Assert.IsTrue(props.Count > 0, "Props collection is empty");
            Assert.AreEqual("config_key1value", tmc1.PropPublicString1);
            Assert.AreEqual("config_key2value", tmc1.PropPublicString2);
        }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StfKernel"/> class.
        /// </summary>
        public StfKernel()
        {
            StfTextUtils = new StfTextUtils();

            // setup needed kernel directories
            KernelSetupKernelDirectories();

            // lets get a logger and a configuration
            var uniqueKernelLoggerFilename = StfTextUtils.AppendUniquePartToFileName("KernelLogger.html");
            var kernelLoggerFilename       = Path.Combine(StfKernelLogDir, uniqueKernelLoggerFilename);
            var kernelLoggerConfiguration  = new StfLoggerConfiguration
            {
                LogTitle    = "KernelLog",
                LogFileName = kernelLoggerFilename,
                LogLevel    = StfLogLevel.Internal
            };

            KernelLogger = new StfLogger(kernelLoggerConfiguration);

            // get the initial configuration together - at this point in time: Only the kernel configuration
            AssembleStfConfigurationBeforePlugins();

            // Any plugins for us?
            PluginLoader = new StfPluginLoader(KernelLogger, StfConfiguration);
            PluginLoader.RegisterInstance(typeof(StfConfiguration), StfConfiguration);

            if (StfConfiguration.TryGetKeyValue("Configuration.StfKernel.PluginPath", out var pluginPath))
            {
                // TODO: Check for existing config file. If file not found then create default template configuration
                PluginLoader.LoadStfPlugins(pluginPath);
            }

            AssembleStfConfigurationAfterPlugins();

            // now all configurations are loaded, we can set the Environment.
            StfConfiguration.Environment = StfConfiguration.DefaultEnvironment;

            LoadConfigurationForStfTypes();
            DumpStfConfiguration();

            KernelLogger.LogKeyValue("Stf Root", StfRoot, "The Stf Root directory");
        }
示例#18
0
        public void TestDefaultDefaultSectionWithVariables()
        {
            System.Environment.SetEnvironmentVariable("STFUSERNAME", "Bent");

            // Load a configuration in StfConfiguration
            var stfConfiguration = new StfConfiguration(@"TestData\Defaulting\DefaultSectionWithVariable.xml");

            var dUsername = stfConfiguration.GetKeyValue("Users.Username");
            var dPassword = stfConfiguration.GetKeyValue("Users.Password");

            StfAssert.AreEqual("Default Username is User_Bent", "User_Bent", dUsername);
            StfAssert.AreEqual("Default Password is K999", "B42", dPassword);

            var uUsername = stfConfiguration.GetKeyValue("Users.Ulrich.Username");
            var uPassword = stfConfiguration.GetKeyValue("Users.Ulrich.Password");
            var kUsername = stfConfiguration.GetKeyValue("Users.Kasper.Username");
            var kPassword = stfConfiguration.GetKeyValue("Users.Kasper.Password");

            StfAssert.AreEqual("Username is User_Ulrich", "User_Ulrich", uUsername);
            StfAssert.AreEqual("Password for Ulrich is U777", "U777", uPassword);
            StfAssert.AreEqual("Username is Kasper", "User_Kasper", kUsername);
            StfAssert.AreEqual("Password for Kasper is K999", "K999", kPassword);
        }
示例#19
0
        public void TestSetValue()
        {
            // Load a configuration in StfConfiguration
            var stfConfiguration = new StfConfiguration(@"TestData\Defaulting\NoDefaultSection.xml");

            var uUsername = stfConfiguration.GetKeyValue("Users.Ulrich.Username");
            var uPassword = stfConfiguration.GetKeyValue("Users.Ulrich.Password");
            var kUsername = stfConfiguration.GetKeyValue("Users.Kasper.Username");
            var kPassword = stfConfiguration.GetKeyValue("Users.Kasper.Password");

            StfAssert.AreEqual("Username is Ulrich", "User_Ulrich", uUsername);
            StfAssert.AreEqual("Password for Ulrich is U777", "U777", uPassword);
            StfAssert.AreEqual("Username is Kasper", "User_Kasper", kUsername);
            StfAssert.AreEqual("Password for Kasper is K999", "K999", kPassword);

            StfAssert.IsTrue("Setting config value", stfConfiguration.SetConfigValue("Users.Ulrich.Username", "New_Ulrich"));
            StfAssert.AreEqual("Username for Ulrich updated", "New_Ulrich",
                               stfConfiguration.GetKeyValue("Users.Ulrich.Username"));

            StfAssert.IsTrue("Setting config value", stfConfiguration.SetConfigValue("Users.Ulrich.Password", "Super1234"));
            StfAssert.AreEqual("Password for Ulrich updated", "Super1234",
                               stfConfiguration.GetKeyValue("Users.Ulrich.Password"));
        }