public void SetDefaultProxyTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string proxy = "http://bloxx.dfguk.com:8081";
            bool actual = target.SetDefaultProxy(proxy, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlElement node = (XmlElement)TestConfigFile.SelectSingleNode("//configuration/system.net/defaultProxy/proxy");
            string attribute = node.GetAttribute("proxyaddress");
            Assert.AreEqual(proxy, attribute);
        }
        public void SetCustomConfigSectionValueTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string value = "UAT";
            const string name = "mySetting";
            bool actual = target.SetCustomConfigSectionValue("environmentSetting", name, value, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlNode node = TestConfigFile.SelectSingleNode("//configuration/environmentSetting/*/setting[@name='" + name + "']/value");
            Assert.AreEqual(value, node.InnerText);
        }
        public void SetXMLNodeValueTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestXML); ;
            const string nodePath = "//Configuration/host";
            const string nodeValue = "https://liveserver.datacash.com/Transaction";
            bool actual = target.SetXMLNodeValue(nodePath, nodeValue, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlNode node = TestXML.SelectSingleNode("//Configuration/host");
            Assert.AreEqual(nodeValue, node.InnerText);
        }
        public void SetAppSettingValueTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string key = "CommIdea.AccountId";
            const string value = "10076061";
            bool actual = target.SetAppSettingValue(key, value, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlNode node = TestConfigFile.SelectSingleNode("//appSettings");
            XmlElement Elem = (XmlElement)node.SelectSingleNode(String.Format("//add[@key='{0}']", key));
            string attribute = Elem.GetAttribute("value");
            Assert.AreEqual(value, attribute);
        }
        public void SetServiceEndPointValueTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string endpointName = "DebtService.DebtService";
            const string endpointAddress = "net.msmq://test/private/debtcollection.svc";
            bool actual = target.SetServiceEndPointValue(endpointName, "address", endpointAddress, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlNode node = TestConfigFile.SelectSingleNode("//services");
            XmlElement Elem = (XmlElement)node.SelectSingleNode(String.Format("//service[@name='{0}']/endpoint", endpointName));
            string attribute = Elem.GetAttribute("address");
            Assert.AreEqual("net.msmq://test/private/debtcollection.svc", attribute);
        }
        public void SetConnectionStringValueTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string connectionStringName = "constring1";
            const string encryptedConnectionstringValue = "jqEbONyGO/8RkT+as++JfaZ4ylwmy/aZGa82fFg4DdVbJ0I+Asw6xpzfcpwx+yLzwkldXvoT8Y2RMXek/jwe/Xm0MxoaCOK9V3JPybfqLjsy9Dcb0FXoMDEZpFbA/S9810AU9flBpveHQ7XbGe/4LW0N9Hs+5r1wEdNDrj9fZ0g=";
            bool actual = target.SetConnectionStringValue(connectionStringName, encryptedConnectionstringValue, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlNode node = TestConfigFile.SelectSingleNode("//connectionStrings");
            XmlElement Elem = (XmlElement)node.SelectSingleNode(String.Format("//add[@name='{0}']", connectionStringName));
            string attribute = Elem.GetAttribute("connectionString");
            Assert.AreEqual(encryptedConnectionstringValue, attribute);
        }
        public void SetClientEndpointValueTest()
        {
            List<string> TestLog = new List<string>();
               configUpdater target = new configUpdater(TestConfigFile);
               const string endpointName = "BasicHttpBinding_ICalculator";
               const string endpointAddress = "http://devapp.dfg.local/CalcService/CalculatorService.svc";
               bool actual = target.SetClientEndpointValue(endpointName, endpointAddress, TestLog.Add);
               Assert.AreEqual(true, actual);

               XmlNode node = TestConfigFile.SelectSingleNode("//client");
               XmlElement Elem = (XmlElement)node.SelectSingleNode(String.Format("//endpoint[@name='{0}']", endpointName));
               string attribute = Elem.GetAttribute("address");
               Assert.AreEqual("http://devapp.dfg.local/CalcService/CalculatorService.svc", attribute);
        }
        public void SetCustomConfigSectionAttributeTest()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string configSectionName = "environmentSetting";
            const string attributeName = "environment"; //
            const string attributeValue = "PROD";
            bool actual = target.SetCustomConfigSectionAttribute(configSectionName, attributeName, attributeValue, TestLog.Add);
            Assert.AreEqual(true, actual);

            XmlNode node = TestConfigFile.SelectSingleNode("//configuration");
            XmlElement Elem = (XmlElement)node.SelectSingleNode("//environmentSetting");
            string attribute = Elem.GetAttribute(attributeName);
            Assert.AreEqual("PROD", attribute);
        }
        public void SetServiceBaseAddressValue()
        {
            List<string> TestLog = new List<string>();
            configUpdater target = new configUpdater(TestConfigFile);
            const string configSectionName = "DebtService.DebtService";
            const string attributeName = "baseAddress"; //
            const string attributeValue = "http://*****:*****@name='{0}']", configSectionName));
            XmlElement Elem = (XmlElement)node.SelectSingleNode("//host//baseAddresses//add");
            string attribute = Elem.GetAttribute(attributeName);
            Assert.AreEqual("http://testserver:8742/", attribute);
        }
 public configUpdater Constructor01()
 {
     configUpdater target = new configUpdater();
     return target;
 }
 public configUpdater Constructor(XmlDocument config)
 {
     configUpdater target = new configUpdater(config);
     return target;
 }
 /// <summary>
 /// Iterates through the settings retrieved from the Installer Settings Service, and updates the selected .config file
 /// </summary>
 /// <param name="session">The session object from the installer for log file writing</param>
 /// <param name="settings">A list of settings retrieved from the Installer Settings Service</param>
 /// <param name="configUpdater">Instance of the configUpdater Class to perform the updates on the file</param>
 private static void UpdateConfigurationFile(Action<string> sessionLog, List<ApplicationConfigSettings.Setting> settings, string configPath)
 {
     foreach (ApplicationConfigSettings.Setting setting in settings)
     {
         configUpdater thisConfig = new configUpdater() { docName = Path.Combine(configPath, setting.configFile) };
         bool result = false;
         switch (setting.settingType)
         {
             case ApplicationConfigSettings.SettingType.ConnectionString:
                 result = thisConfig.SetConnectionStringValue(setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Connection String {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Connection String {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.AppSetting:
                 result = thisConfig.SetAppSettingValue(setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("App Setting {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: App Setting {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.ClientEndpoint:
                 result = thisConfig.SetClientEndpointValue(setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Client Endpoint {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Client Endpoint {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.ServiceEndpoint:
                 result = thisConfig.SetServiceEndPointValue(setting.settingName, setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Service Endpoint {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Service Endpoint {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.ConfigurationSetting:
                 result = thisConfig.SetCustomConfigSectionAttribute(setting.settingName, setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Configuration Section {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Configuration Section {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.ConfigurationValue:
                 result = thisConfig.SetCustomConfigSectionValue(setting.settingName, setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Configuration Value {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Configuration Value {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.ServiceBaseAddress:
                 result = thisConfig.SetServiceBaseAddress(setting.settingName, setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Service Base Address {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Service Base Address {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.XMLNodeValue:
                 result = thisConfig.SetXMLNodeValue(setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("XML Node value {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: XML Node value {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.DefaultProxy:
                 result = thisConfig.SetDefaultProxy(setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("Default Proxy value {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: Default Proxy value {0} update failed", setting.settingName));
                 }
                 break;
             case ApplicationConfigSettings.SettingType.XMLNodeAttribute:
                 result = thisConfig.SetXMLNodeAttributeValue(setting.settingName, setting.settingKey, setting.settingValue, sessionLog);
                 if (result)
                 {
                     sessionLog(String.Format("XML Node value {0} updated", setting.settingName));
                 }
                 else
                 {
                     sessionLog(String.Format("Error: XML Node value {0} update failed", setting.settingName));
                 }
                 break;
             default:
                 sessionLog("Error: An unknown setting was found, please check the configuration database");
                 break;
         }
     }
 }