Exemple #1
0
 public Runner(Variables variables, List<string> includedScripts = null, bool demoMode = false, bool quietMode = false)
 {
     Variables = variables;
     IncludedScripts = includedScripts ?? new List<string>();
     DemoMode = demoMode;
     CurrentSection = null;
     QuietMode = quietMode;
 }
        public void Define_variable_and_read_its_value()
        {
            var variables = new Variables();
            variables.Set("hello", "world!");

            var actualValue = variables.ReplaceVariables("%hello%");
            Assert.AreEqual("world!", actualValue);
        }
        public void PATH_WEBCONFIG_refers_to_webconfig_file()
        {
            var webConfig = Prepare.WebConfig();
            var variables = new Variables();

            var actualFileName = variables.ReplaceVariables("%path_webconfig%");

            Assert.AreEqual(webConfig, actualFileName);
        }
        public void DB_is_database_value_extracted_from_connection_string()
        {
            Prepare.WebConfig();
            var variables = new Variables();

            var actualDb = variables.ReplaceVariables("%db%");

            Assert.AreEqual(@"xyz", actualDb);
        }
        public void CONNECTION_STRING_NAME_is_AppDatabase_by_default()
        {
            Prepare.WebConfig();
            var variables = new Variables();

            var actualConnectionStringName = variables.ReplaceVariables("%connection_string_name%");

            Assert.AreEqual("AppDatabase", actualConnectionStringName);
        }
        public void CONNECTION_STRING_is_AppDatabase_value_in_webconfig()
        {
            Prepare.WebConfig();
            var variables = new Variables();

            var actualConnectionStringName = variables.ReplaceVariables("%connection_string%");

            Assert.AreEqual(@"Server=.\SQLEXPRESS; uid=App; password=VERY_SECURE_PASSWORD; MultipleActiveResultSets=True; Database=xyz;", actualConnectionStringName);
        }
        public void PATH_WEB_refers_to_website_folder()
        {
            var webConfig = Prepare.WebConfig();
            var variables = new Variables();

            var actualPath = variables.ReplaceVariables("%path_web%");
            var expectedPath = Path.GetDirectoryName(webConfig);

            Assert.AreEqual(expectedPath, actualPath);
        }
        public void Overrid_system_variables()
        {
            Prepare.WebConfig();

            var variables = new Variables();
            variables.Set("connection_string_name", "WiredContactDatabase");

            var actualDatabase = variables.ReplaceVariables("%db%");
            Assert.AreEqual("XYZ_2012_11_19", actualDatabase);
        }
        public void Define_variable_in_script_and_read_its_value()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", @"
            [define]
            some_var=value
            ");

            Assert.AreEqual("value", variables.Get("some_var"));
        }
        public void Undefined_variable_should_not_have_value()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", @"
            [define]
            some_var=value
            some_var=
            ");
            variables.Get("some_var");
        }
        public void Operatorless_filter()
        {
            Prepare.Database();
            var variables = new Variables();
            variables.Set(Variables.CONNECTION_STRING, DatabaseUtil.ConnectionString);
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", "[database]\nCustomers['John Smith'].Age = 80");

            var johnSmithAge = DatabaseUtil.Execute<int?>("SELECT TOP 1 age FROM Customers WHERE name ='John Smith'");

            Assert.AreEqual(80, johnSmithAge);
        }
        public void Set_to_NULL()
        {
            Prepare.Database();
            var variables = new Variables();
            variables.Set(Variables.CONNECTION_STRING, DatabaseUtil.ConnectionString);
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", "[database]\nCustomers[id='11111111-0000-0000-0000-000000000000'].Age = NULL");

            var johnSmithAge = DatabaseUtil.Execute<object>("SELECT TOP 1 age FROM Customers WHERE name ='John Smith'");

            Assert.IsTrue(Convert.IsDBNull(johnSmithAge));
        }
        public void Comments_have_no_effect()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", @"
            [define]
            some_var=value1
            #some_var=value2

            ");
            Assert.AreEqual("value1", variables.Get("some_var"));
        }
        public static string GetConnectionString(Variables variables, string name)
        {
            var doc = XDocument.Load(variables.Get(Variables.PATH_WEBCONFIG));
            var node = doc.XPathSelectElement(String.Format("/configuration/connectionStrings/add[@name='{0}']", name));
            if (node == null)
                throw new Exception("Cannot find a connection string with name " + name);

            var attribute = node.Attribute("connectionString");
            if (attribute == null)
                throw new Exception("No connectionString attribute found in connection string node");

            return attribute.Value;
        }
        public void External_sql_file()
        {
            Prepare.Database();
            Prepare.Script("setTo90.sql", "UPDATE Customers SET Age=90 WHERE Name='John Smith'");
            var variables = new Variables();
            variables.Set(Variables.CONNECTION_STRING, DatabaseUtil.ConnectionString);
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", "[database]\nExec setTo90.sql");

            var johnSmithAge = DatabaseUtil.Execute<int?>("SELECT TOP 1 age FROM Customers WHERE name ='John Smith'");

            Assert.AreEqual(90, johnSmithAge);
        }
        public void NotEqual_filter()
        {
            Prepare.Database();
            var variables = new Variables();
            variables.Set(Variables.CONNECTION_STRING, DatabaseUtil.ConnectionString);
            var runner = new Runner(variables);

            runner.ExecScript("DummyFileName", "[database]\nCustomers[id<>'11111111-0000-0000-0000-000000000000'].Age = 0");

            var johnDoeAge = DatabaseUtil.Execute<int>("SELECT TOP 1 age FROM Customers WHERE name ='John Doe'");
            var johnSmithAge = DatabaseUtil.Execute<int>("SELECT TOP 1 age FROM Customers WHERE name ='John Smith'");

            Assert.AreEqual(0, johnDoeAge); // must be changed
            Assert.AreEqual(35, johnSmithAge); // must be intact
        }
        public void Variables_from_included_script_should_exist()
        {
            var variables = new Variables();
            var runner = new Runner(variables);

            Prepare.Script("common.deploy", @"
            [define]
            some_var=value
            ");

            runner.ExecScript("DummyFileName", @"
            include common.deploy
            ");

            Assert.AreEqual("value", variables.Get("some_var"));
        }
 public static void UpdateSetting(
     Variables variables,
     string key,
     string value,
     bool quietMode = false)
 {
     UpdateNodeAttribute(
         variables,
         nodePath: String.Format("/configuration/appSettings/add[@key='{0}']", key),
         // Setting nodeDisplayName in this way allows
         // an error message like 'Cannot find setting Email.Ssl'
         // or info like 'Set setting Email.Ssl value to true'
         nodeDisplayName: "setting " + key,
         attributeName: "value",
         value: value,
         quietMode: quietMode);
 }
        /// <summary>
        /// Updates value of an attribute in the given node (by xpath) or creates the attribute
        /// </summary>
        public static void UpdateNodeAttribute(
            Variables variables,
            string nodePath,
            string nodeDisplayName,
            string attributeName,
            string value,
            bool quietMode = false)
        {
            var doc = XDocument.Load(variables.Get(Variables.PATH_WEBCONFIG));
            var nodes = doc.XPathSelectElements(nodePath);
            if (nodes.Count() == 0)
                throw new Exception(String.Format("Cannot find {0}", nodeDisplayName));

            foreach (var node in nodes)
            {
                if (!quietMode) Console.WriteLine(" Set {0} {1} to {2}", nodeDisplayName, attributeName, value);
                node.SetAttributeValue(attributeName, value);
            }

            doc.Save(variables.Get(Variables.PATH_WEBCONFIG));
        }
Exemple #20
0
        static void Main(string[] args)
        {
            try
            {
                Arguments = Arguments.Create(args);
                if (Arguments.PrintHelp)
                {
                    PrintHelp();
                    return;
                }

                Variables = new Variables();
                if (Arguments.PrintVariables)
                {
                    PrintVariables();
                    return;
                }

                if (Arguments.Scripts.Count == 0)
                {
                    // if no command line argument, execute:
                    // _start.deploy
                    // %server%.deploy
                    // _other.deploy (if above server file not found)
                    // _finish.deploy

                    RunIfExist("_start.deploy");

                    if (!RunIfExist(Variables.Get(Variables.SERVER) + ".deploy"))
                    {
                        RunIfExist("_other.deploy");
                    }

                    RunIfExist("_finish.deploy");

                }
                else
                {
                    foreach (var script in Arguments.Scripts)
                    {
                        if (!RunIfExist(script))
                            throw new Exception("Cannot find script:" + script);
                    }
                }

            }
            catch (ScriptException err)
            {
                Console.Error.WriteLine("{0}:{1} {2}", err.ScriptName, err.LineNumber, err.Message);
            }
            catch (Exception err)
            {
                Console.Error.WriteLine(Arguments.DebugMode ? err.ToString() : err.Message);
            }

            if (!Arguments.Quiet)
            {
                Console.WriteLine("\nDone. Press any key.");
                Console.ReadKey();
            }
        }
 public static IEnumerable<string> PossibleSettingKeys(Variables variables)
 {
     var doc = XDocument.Load(variables.Get(Variables.PATH_WEBCONFIG));
     return doc.XPathSelectElements("/configuration/appSettings/add").Select(n =>
         n.Attribute("key").Value);
 }
        public void SERVER_refers_to_machine_name()
        {
            var machineName = Prepare.Machine();
            var variables = new Variables();

            var actualMachine = variables.ReplaceVariables("%server%");

            Assert.AreEqual(machineName, actualMachine);
        }
 public DatabaseManager(Variables variables, bool quietMode)
 {
     Variables = variables;
     QuietMode = quietMode;
 }