private void LoadTestScripts(string folder)
        {
            if (!Directory.Exists(folder))
            {
                return;
            }

            DirectoryInfo directoryInfo = new DirectoryInfo(folder);

            var scriptFilePaths = from file in directoryInfo.GetFiles("*" + SqlExtension)
                                  where SqlExtension.Equals(file.Extension, StringComparison.OrdinalIgnoreCase)
                                  select file.FullName;

            foreach (string scriptFile in scriptFilePaths)
            {
                try
                {
                    string contents = RuleTestUtils.ReadFileToString(scriptFile);
                    TestScripts.Add(Tuple.Create(contents, Path.GetFileName(scriptFile)));
                    Console.WriteLine($"Test file '{scriptFile}' loaded successfully");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error reading from file {scriptFile} with message '{ex.Message}'");
                    Console.WriteLine("Execution will continue...");
                }
            }
        }
示例#2
0
        private void LoadTestScripts()
        {
            // Load all files ending in ".sql". Note that due to strange Win32 behavior we need to double check the
            // file name actually ends in ".sql" since suffixes like ".sqlOther" would also be included in the results
            DirectoryInfo di = new DirectoryInfo(ScriptsFolder);
            var           scriptFilepaths = from file in di.GetFiles("*" + SqlExt)
                                            where SqlExt.Equals(file.Extension, StringComparison.OrdinalIgnoreCase)
                                            select file.FullName;

            foreach (string scriptFile in scriptFilepaths)
            {
                try
                {
                    string contents = RuleTestUtils.ReadFileToString(scriptFile);
                    TestScripts.Add(Tuple.Create(contents, scriptFile));
                    Console.WriteLine("Test script file '{0}' loaded", scriptFile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(
                        "Error reading from file '{0}', message is '{1}'. Continuing processing since missing files treated as warning for test",
                        scriptFile,
                        ex.Message);
                }
            }
        }
        ScriptNode LoadAndParseFile(ScriptProgram scriptProgram, string filename)
        {
            var text = File.ReadAllText(filename);
            var rv = scriptParser.ParseScript(scriptProgram, text);

            // TODO Fix up this mess!
            TestScripts.AssignRandomGuids(rv);

            return rv;
        }
示例#4
0
        ScriptNode LoadAndParseFile(ScriptProgram scriptProgram, string filename)
        {
            var text = File.ReadAllText(filename);
            var rv   = scriptParser.ParseScript(scriptProgram, text);



            // FIXME = We shouldn't need to do this.
            TestScripts.AssignRandomIdentifiers(rv);
            // ENDFIX ME

            return(rv);
        }
        public void UpdateLockedByFlags(TestScripts testScript)
        {
            using (IDbConnection con = new SqlConnection(strConnectionString))
            {
                var parameters = new DynamicParameters();
                parameters.Add("@Id", testScript.ID);
                parameters.Add("@IsLocked", testScript.IsLocked);
                parameters.Add("@LockedByUser", testScript.LockedByUser);
                parameters.Add("@UpdatedOn", DateTime.UtcNow);

                con.Query($"{GetUpdateLockedByUserScript()}",
                          parameters,
                          commandType: CommandType.Text);
            }
        }
示例#6
0
        /// <summary>
        /// Deploys test scripts to a database and creates a model directly against this DB.
        /// Since this is a RuleTest we load the model as script backed to ensure that we have file names,
        /// source code positions, and that programmability objects (stored procedures, views) have a full SQLDOM
        /// syntax tree instead of just a snippet.
        /// </summary>
        private TSqlModel CreateDatabaseModel()
        {
            ArgumentValidation.CheckForEmptyString(DatabaseName, "DatabaseName");
            SqlTestDB db = TestUtils.CreateTestDatabase(TestUtils.DefaultInstanceInfo, DatabaseName);

            _trash.Add(db);

            TestUtils.ExecuteNonQuery(db, TestScripts.Select(t => t.Item1).SelectMany(s => TestUtils.GetBatches(s)).ToList());

            TSqlModel model = TSqlModel.LoadFromDatabase(db.BuildConnectionString(), new ModelExtractOptions {
                LoadAsScriptBackedModel = true
            });

            AssertModelValid(model);
            return(model);
        }
        public void UpdateScript(int scriptId, TestScripts script)
        {
            using (IDbConnection con = new SqlConnection(strConnectionString))
            {
                var parameters = new DynamicParameters();
                parameters.Add("@Id", scriptId);
                parameters.Add("@TestCaseID", script.TestCaseID);
                parameters.Add("@TCStepID", script.TCStepID);
                parameters.Add("@TestScriptName", script.TestScriptName);
                parameters.Add("@FunctionDescription", script.FunctionDescription);
                parameters.Add("@FunctionName", script.FunctionName);
                parameters.Add("@Run", script.Run);
                parameters.Add("@Param1", script.Param1);
                parameters.Add("@Param2", script.Param2);
                parameters.Add("@Param3", script.Param3);
                parameters.Add("@Param4", script.Param4);
                parameters.Add("@Param5", script.Param5);
                parameters.Add("@Param6", script.Param6);
                parameters.Add("@Param8", script.Param8);
                parameters.Add("@Param7", script.Param7);
                parameters.Add("@Param9", script.Param9);
                parameters.Add("@Param10", script.Param10);
                parameters.Add("@Param11", script.Param11);
                parameters.Add("@Param12", script.Param12);
                parameters.Add("@Param13", script.Param13);
                parameters.Add("@Param14", script.Param14);
                parameters.Add("@Param15", script.Param15);
                parameters.Add("@Param16", script.Param16);
                parameters.Add("@Param17", script.Param17);
                parameters.Add("@Param18", script.Param18);
                parameters.Add("@Param19", script.Param19);
                parameters.Add("@Param20", script.Param20);
                parameters.Add("@Param21", script.Param21);
                parameters.Add("@Param22", script.Param22);
                parameters.Add("@Param23", script.Param23);
                parameters.Add("@Param24", script.Param24);
                parameters.Add("@Param25", script.Param25);
                parameters.Add("@Param26", script.Param26);
                parameters.Add("@Param27", script.Param27);
                parameters.Add("@Param28", script.Param28);
                parameters.Add("@Param29", script.Param29);
                parameters.Add("@Param30", script.Param30);
                parameters.Add("@Param31", script.Param31);
                parameters.Add("@Param32", script.Param32);
                parameters.Add("@Param33", script.Param33);
                parameters.Add("@Param34", script.Param34);
                parameters.Add("@Param35", script.Param35);
                parameters.Add("@Param36", script.Param36);
                parameters.Add("@Param37", script.Param37);
                parameters.Add("@Param38", script.Param38);
                parameters.Add("@Param39", script.Param39);
                parameters.Add("@Param40", script.Param40);
                parameters.Add("@Param41", script.Param41);
                parameters.Add("@Param42", script.Param42);
                parameters.Add("@Param43", script.Param43);
                parameters.Add("@Param44", script.Param44);
                parameters.Add("@Param45", script.Param45);
                parameters.Add("@Param46", script.Param46);
                parameters.Add("@Param47", script.Param47);
                parameters.Add("@Param48", script.Param48);
                parameters.Add("@Param49", script.Param49);
                parameters.Add("@Param50", script.Param50);
                parameters.Add("@Param51", script.Param51);
                parameters.Add("@Param52", script.Param52);
                parameters.Add("@Param53", script.Param53);
                parameters.Add("@Param54", script.Param54);
                parameters.Add("@Param55", script.Param55);
                parameters.Add("@Param56", script.Param56);
                parameters.Add("@Param57", script.Param57);
                parameters.Add("@Param58", script.Param58);
                parameters.Add("@Param59", script.Param59);
                parameters.Add("@Param60", script.Param60);
                parameters.Add("@Param61", script.Param61);
                parameters.Add("@Param62", script.Param62);
                parameters.Add("@Param63", script.Param63);
                parameters.Add("@Param64", script.Param64);
                parameters.Add("@Param65", script.Param65);
                parameters.Add("@Param66", script.Param66);
                parameters.Add("@Param67", script.Param67);
                parameters.Add("@Param68", script.Param68);
                parameters.Add("@Param69", script.Param69);
                parameters.Add("@Param70", script.Param70);
                parameters.Add("@Param71", script.Param71);
                parameters.Add("@Param72", script.Param72);
                parameters.Add("@Param73", script.Param73);
                parameters.Add("@Param74", script.Param74);
                parameters.Add("@Param75", script.Param75);
                parameters.Add("@Param76", script.Param76);
                parameters.Add("@Param77", script.Param77);
                parameters.Add("@Param78", script.Param78);
                parameters.Add("@Param79", script.Param79);
                parameters.Add("@Param80", script.Param80);
                parameters.Add("@Param81", script.Param81);
                parameters.Add("@Param82", script.Param82);
                parameters.Add("@Param83", script.Param83);
                parameters.Add("@Param84", script.Param84);
                parameters.Add("@Param85", script.Param85);
                parameters.Add("@Param86", script.Param86);
                parameters.Add("@Param87", script.Param87);
                parameters.Add("@Param88", script.Param88);
                parameters.Add("@Param89", script.Param89);
                parameters.Add("@Param90", script.Param90);
                parameters.Add("@Param91", script.Param91);
                parameters.Add("@Param92", script.Param92);
                parameters.Add("@Param93", script.Param93);
                parameters.Add("@Param94", script.Param94);
                parameters.Add("@Param95", script.Param95);
                parameters.Add("@Param96", script.Param96);
                parameters.Add("@Param97", script.Param97);
                parameters.Add("@Param98", script.Param98);
                parameters.Add("@Param99", script.Param99);
                parameters.Add("@Param100", script.Param100);
                parameters.Add("@Module", script.Module);
                parameters.Add("@StatusID", (int)Status.Active);
                parameters.Add("@CUDStatusID", (int)CUDStatus.Updated);
                parameters.Add("@IsLocked", null);
                parameters.Add("@LockedByUser", null);
                parameters.Add("@UpdatedOn", DateTime.UtcNow);
                parameters.Add("@UserId", script.UserId);

                con.Query($"{GetUpdateScript()}",
                          parameters,
                          commandType: CommandType.Text);
            }
        }