Exemplo n.º 1
0
        public void GetConfig_FallbackAppConfigProvider_NotInstalledByDefault()
        {
            ConfigHub sut = new ConfigHub();
            string    val = sut.GetSetting("testSettingValue");

            Assert.Null(val);
        }
Exemplo n.º 2
0
        public void GetConfig_FallbackProvider_CalledForAllRequests()
        {
            Dictionary <string, bool> testSettings = new Dictionary <string, bool>();

            // Used to avoid issue where changing collection below causes fault.
            List <string> settingNames = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                string next = "testsetting" + i.ToString();
                testSettings.Add(next, false);
                settingNames.Add(next);
            }

            ConfigHub sut = new ConfigHub();

            sut.RegisterFallbackProvider((pName) => {
                if (testSettings.ContainsKey(pName))
                {
                    testSettings[pName] = true;
                }
                return(null);
            });

            foreach (var v in settingNames)
            {
                sut.GetSetting(v);
            }

            foreach (var test in testSettings.Keys)
            {
                Assert.True(testSettings[test], "The setting " + test + " was not hit");
            }
        }
Exemplo n.º 3
0
        public void GetConfig_NoProvider_ReturnsNullIfNotRequired()
        {
            ConfigHub sut = new ConfigHub();
            string    res = sut.GetSetting("arflebarfle");

            Assert.Null(res);
        }
Exemplo n.º 4
0
        public void GetConfig_FallbackAppConfigProvider_Returnsconfiguration()
        {
            ConfigHub sut = new ConfigHub();

            sut.AddDefaultAppConfigFallback();
            string val = sut.GetSetting("testSettingValue");

            Assert.Equal("arfleBARFLEgloop", val);
        }
Exemplo n.º 5
0
        public void GetConfig_FallbackAppConfigProvider_IsCaseInsensitive()
        {
            ConfigHub sut = new ConfigHub();

            sut.AddDefaultAppConfigFallback();
            string val = sut.GetSetting("TESTsEttInGvAlUe");

            Assert.Equal("arfleBARFLEgloop", val);
        }
Exemplo n.º 6
0
        public void EmptyDirectory_DefaultsToCurrent()
        {
            b.Info.Flow();

            ConfigHub sut = new ConfigHub();

            var cd = sut.Test_GetDirectoryName(string.Empty);

            Assert.False(string.IsNullOrWhiteSpace(cd));
        }
Exemplo n.º 7
0
        public void GetSetting_ThrowsInfNullSetting()
        {
            b.Info.Flow();

            ConfigHub sut = new ConfigHub();

            Assert.Throws <ArgumentNullException>(() => {
                sut.GetSetting(null);
            });
        }
Exemplo n.º 8
0
        public void GetConfig_FallbackAppConfig_NestedIsEmptyWhenNotPresent()
        {
            string    combinedString = "ARFLEUSBarfleyGloopify";
            ConfigHub sut            = new ConfigHub();

            sut.AddDefaultAppConfigFallback();

            string val = sut.GetSetting("testSettingSubValue2");

            Assert.Equal(combinedString, val);
        }
Exemplo n.º 9
0
        public void GetConfig_FallbackAppConfig_SupportsNestedReplacements()
        {
            string    combinedString = "contactinatedIntoARFLEUSBarfleyGloopify";
            ConfigHub sut            = new ConfigHub();

            sut.AddDefaultAppConfigFallback();

            string val = sut.GetSetting("testSettingSubValue");

            Assert.Equal(combinedString, val);
        }
Exemplo n.º 10
0
        public void GetConfig_CustomType_ReturnsCorrectly()
        {
            ConfigHub sut = new ConfigHub();

            sut.RegisterProvider <TestMessage>("settingVal", () => {
                return(new TestMessage("HelloWorld"));
            });
            TestMessage result = sut.GetSetting <TestMessage>("settingVal");

            Assert.Equal("HelloWorld", result.Data);
        }
Exemplo n.º 11
0
        public void GetConfig_GetSetting_SpecificOveridesFallback()
        {
            ConfigHub sut = new ConfigHub();

            sut.AddDefaultAppConfigFallback();
            sut.RegisterProvider("testSettingSubValue2", () => {
                return("NothingHere");
            });
            string val = sut.GetSetting("testSettingSubValue2");

            Assert.Equal("NothingHere", val);
        }
Exemplo n.º 12
0
        public void GetTypedSetting_FromFallback_ReturnsBool()
        {
            ConfigHub sut = new ConfigHub();

            sut.AddMachineFallbackProvider(ConfigHub.DefaultMachineName, (settingName) => {
                return("true");
            });

            bool val = sut.GetSetting <bool>("SettingName");

            Assert.True(val, "The incorrect value was returned");
        }
Exemplo n.º 13
0
        public void Directory_FullConfigStringRetrieval()
        {
            b.Info.Flow();


            ConfigHub sut = new ConfigHub();

            sut.AddDirectoryFallbackProvider("%PLISKYAPPROOT%\\Config", "tests.xml");
            var str = sut.GetSetting("testconstr", true);

            Assert.Equal("CONSTR-Value", str);
        }
Exemplo n.º 14
0
        public void GetTypedSetting_FromFallback_ReturnsDouble()
        {
            ConfigHub sut = new ConfigHub();

            sut.AddMachineFallbackProvider(ConfigHub.DefaultMachineName, (settingName) => {
                return("1236754");
            });

            double val = sut.GetSetting <double>("SettingName");

            Assert.Equal(1236754, val);
        }
Exemplo n.º 15
0
        public void Crypto_DecryptNeeded_NoCrypto_ThrowsException()
        {
            ConfigHub sut = new ConfigHub();

            sut.RegisterProvider("CryptoTest", () => {
                return("xxx");
            });

            Assert.Throws <ConfigHubConfigurationFailureException> (() =>
                                                                    sut.GetSetting <string>("CryptoTest", false, true)
                                                                    );
        }
Exemplo n.º 16
0
        public void RegisterMachineFallback_DuplicateName_CausesException()
        {
            ConfigHub sut         = new ConfigHub();
            string    MachineName = "MachineName";

            sut.AddMachineFallbackProvider(MachineName, (settingName) => {
                return("Hello");
            });
            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.AddMachineFallbackProvider(MachineName, (settingName) => {
                return("Hello");
            }));
        }
Exemplo n.º 17
0
        public void DateTime_Setting_Works()
        {
            b.Info.Flow();
            DateTime expected = new DateTime(2019, 1, 1);

            ConfigHub sut = new ConfigHub();

            sut.RegisterProvider <DateTime>(ConfigHub.DateTimeSettingName, () => {
                return(expected);
            });

            Assert.Equal <DateTime>(expected, sut.GetNow());
        }
Exemplo n.º 18
0
        public void GetTypedSetting_DoesExecuteFallback()
        {
            ConfigHub sut = new ConfigHub();
            bool      fallbackExecuted = false;

            sut.AddMachineFallbackProvider(ConfigHub.DefaultMachineName, (settingName) => {
                fallbackExecuted = true;
                return("0");
            });

            int val = sut.GetSetting <int>("Test");

            Assert.True(fallbackExecuted, "The fallback was not execued");
        }
Exemplo n.º 19
0
        public void GetConfig_SingleProvider_ReturnsCorrectly()
        {
            string returnString = "arflebarflegloop";

            ConfigHub sut = new ConfigHub();

            sut.RegisterProvider("test", () => {
                return(returnString);
            });

            string actual = sut.GetSetting("test");

            Assert.Equal(returnString, actual);
        }
Exemplo n.º 20
0
        public void Directory_ResolvesEnvironmentVariable()
        {
            b.Info.Flow();

            var par = Environment.GetEnvironmentVariable("PLISKYAPPROOT");

            Assert.NotNull(par);  // Validation check that this machine is configured correct.

            ConfigHub sut = new ConfigHub();

            var dn = sut.Test_GetDirectoryName("%PLISKYAPPROOT%\\MyDir");

            Assert.Equal(par + "\\MyDir", dn);
        }
Exemplo n.º 21
0
        public void Crypto_DecryptorPresent_NoChangeNonEncrypted()
        {
            string           inputVal = "xxx";
            ConfigHub        sut      = new ConfigHub();
            MockSimpleCrypto msc      = new MockSimpleCrypto();

            sut.RegisterProvider("CryptoTest", () => {
                return(inputVal);
            });

            sut.CryptoProvider = msc;
            var s = sut.GetSetting <string>("CryptoTest", false, false);

            Assert.Equal(s, inputVal);
        }
Exemplo n.º 22
0
        public void Crypto_DecryptorPresent_ChangesValue()
        {
            ConfigHub        sut = new ConfigHub();
            MockSimpleCrypto msc = new MockSimpleCrypto();

            sut.RegisterProvider("CryptoTest", () => {
                return("xxx");
            });

            sut.CryptoProvider = msc;
            var s = sut.GetSetting <string>("CryptoTest", false, true);

            Assert.NotNull(s);
            Assert.Equal(msc.AlwaysThisValue, s);
        }
Exemplo n.º 23
0
        public void Directory_FullConfigStringRetrievalCrypto()
        {
            b.Info.Flow();
            const string PLAINTEXT = "ItAllWorked";

            ConfigHub sut = new ConfigHub();
            var       mcr = new MockSimpleCrypto();

            mcr.AddDecryption("CONSTR-Value", PLAINTEXT);
            sut.CryptoProvider = mcr;
            sut.AddDirectoryFallbackProvider("%PLISKYAPPROOT%\\Config", "tests.xml");
            var str = sut.GetSetting("testconstr", true, true);

            Assert.Equal(PLAINTEXT, str);
        }
Exemplo n.º 24
0
        public void Directory_DoubleFallbackWorks()
        {
            b.Info.Flow();


            ConfigHub sut = new ConfigHub();

            sut.InjectBilge(b);
            sut.AddDirectoryFallbackProvider("C:\\DoesNotExistAtAll", "tests.xml");
            sut.AddDirectoryFallbackProvider("%PLISKYAPPROOT%\\Config", "tests.xml");

            var str = sut.GetSetting("testconstr", true);

            Assert.Equal("CONSTR-Value", str);
        }
Exemplo n.º 25
0
        public void GetConfig_TwoProviders_SpecificOverridesFallback()
        {
            ConfigHub sut = new ConfigHub();

            sut.RegisterFallbackProvider((pName) => {
                return("result1");
            });

            sut.RegisterProvider("value1", () => {
                return("result2");
            });

            string actual = sut.GetSetting("value1");

            Assert.Equal("result2", actual);
        }
Exemplo n.º 26
0
        public void GetConfig_DirectoryFallbackProvider_Works()
        {
            const string testData = "bannana";
            string       tmp      = Path.GetTempPath() + Environment.MachineName + ".chcfg";

            uth.RegisterTemporaryFilename(tmp);
            XDocument x = new XDocument();

            x.Add(new XElement("chub_settings", new XElement("settings", new XElement("monkeyfish", testData))));
            x.Save(tmp);
            ConfigHub sut = new ConfigHub();

            sut.AddDirectoryFallbackProvider(Path.GetTempPath());
            var res = sut.GetSetting("monkeyfish", true);

            Assert.Equal(testData, res);
        }
Exemplo n.º 27
0
        public void RegisterMachineFallback_CallBackOccursForThisMachine()
        {
            ConfigHub sut         = new ConfigHub();
            string    MachineName = Environment.MachineName;
            string    expected    = "Hello";
            bool      executed    = false;

            sut.AddMachineFallbackProvider(MachineName, (settingName) => {
                executed = true;
                return(expected);
            });

            string result = sut.GetSetting("TestSettingName");

            Assert.True(executed, "The handler should have been executed");
            Assert.Equal(expected, result);
        }
Exemplo n.º 28
0
        public void Bug_AppTagMarkerIncludesExeName()
        {
            b.Info.Flow();

            // This bug was because "ToLower" was used in the settings therefore the connectionString could not be found
            // as it wasnt lowercase in the file.  This is currently failing as have fixed the file.

            // TODO - Implement case insensitivity option.
            ConfigHub sut = new ConfigHub();

            sut.InjectBilge(b);

            string output = ConfigHub.Current.Test_GetDirectoryName("[APP]");

            Assert.NotNull(output);
            Assert.False(output.EndsWith(".dll"));
        }
Exemplo n.º 29
0
 public static bool UpdateTasksList(string oldName, string newName)
 {
     try
     {
         ConfigHub confValue = tasksList[oldName];
         tasksList.Remove(oldName);
         AddTaskEntry(newName, confValue);
         EventLogViewModel.AddNewRegistry("Updated " + oldName + " name",
                                          DateTime.Now, typeof(CoreTask).Name, "MEDIUM");
         return(true);
     }
     catch (Exception e)
     {
         EventLogViewModel.AddNewRegistry("Error during updating " + oldName + " name",
                                          DateTime.Now, typeof(CoreTask).Name, "ERROR");
         return(false);
     }
 }
Exemplo n.º 30
0
        public void GetConfig_FallbackProvider_ReturnsCorrectly()
        {
            string returnString = "arflebarflegloop";

            ConfigHub sut = new ConfigHub();

            sut.RegisterFallbackProvider((pname) => {
                if (pname == "test1")
                {
                    return(returnString);
                }
                return(null);
            });

            string actual = sut.GetSetting("test1");

            Assert.Equal(returnString, actual);
        }