public MySqlRepository()
 {
     _request = new MySqlRequests();
     _procedureScriptParser = new MySqlScriptParser();
     _triggerScriptParser   = new MySqlTriggerScriptParser();
     _fieldsParser          = new MySqlFieldsInfoParser();
 }
Esempio n. 2
0
        public void DeployScript(string pathToScript, TestNodes mainTestNode, DatabaseHandler db)
        {
            try
            {
                var msScriptParser = new MySqlScriptParser();
                var deployTestNode = ObjectComparator.CreateTestNode(new List <TestResult>(), ObjectType.ScriptTests,
                                                                     "Set of tests for Script");

                var scriptFromFile = File.ReadAllText(Path.Combine(pathToScript));
                var parsedScript   = msScriptParser.GetScriptArray(scriptFromFile);
                var dbCreated      = msScriptParser.ExecuteTransactionScript(parsedScript, db.Database);

                if (dbCreated)
                {
                    return;
                }

                ObjectComparator.AddTestResult($"Creation of Database objects failed. Databaes: {db.Database.ConnectionString}",
                                               ErrorTypes.CreationScriptFailed,
                                               ObjectType.Script,
                                               $"Script: {pathToScript}",
                                               deployTestNode.Results);
                ObjectComparator.SetResultLevel(deployTestNode);
                mainTestNode.Nodes.Add(deployTestNode);

                var resultPath = Settings.SettingsObject.ResultPath;
                Xml xmlCreator = new Xml();
                var xmlContent = xmlCreator.GetXml(mainTestNode);

                xmlCreator.SaveResultTree(resultPath, xmlContent);

                Environment.Exit((int)ExitCodes.ScriptFailed);
            }
            catch (IOException ex)
            {
                Logger.Error(ex, "Unable to finish script file.");
                Environment.Exit((int)ExitCodes.ScriptFailed);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error when executing script file.");
                Environment.Exit((int)ExitCodes.ScriptFailed);
            }
        }