Esempio n. 1
0
        public void ValidateScriptAgainstPolicyTest_WithIScriptPolicy()
        {
            string        script         = Properties.Resources.PolicyHelper_WithViolations;
            string        targetDatabase = "TestDb";
            IScriptPolicy policy         = new CommentHeaderPolicy();
            Violation     actual;

            actual = PolicyHelper.ValidateScriptAgainstPolicy(script, targetDatabase, policy);
            Assert.IsNotNull(actual);
        }
Esempio n. 2
0
        public void ValidateScriptAgainstPolicyTest_NoViolation()
        {
            string        script         = Properties.Resources.PolicyHelper_NoViolations;
            string        targetDatabase = "TestDb";
            IScriptPolicy policy         = new SelectStarPolicy();

            Violation actual;

            actual = PolicyHelper.ValidateScriptAgainstPolicy(script, targetDatabase, policy);
            Assert.IsNull(actual);
        }
Esempio n. 3
0
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!(sender is BackgroundWorker))
            {
                return;
            }

            BackgroundWorker bg = (BackgroundWorker)sender;

            if (!(e.Argument is List <IScriptPolicy>))
            {
                bg.ReportProgress(0, "Error running. Policies not selected");
                return;
            }
            List <IScriptPolicy> selectedPolices = (List <IScriptPolicy>)e.Argument;

            string message, fileName, script, targetDatabase;
            bool   passed;

            foreach (SqlSyncBuildData.ScriptRow row in this.buildData.Script)
            {
                fileName = Path.Combine(this.projectFilePath + row.FileName);
                if (File.Exists(fileName))
                {
                    script         = File.ReadAllText(fileName);
                    targetDatabase = row.Database;
                    for (int i = 0; i < selectedPolices.Count; i++)
                    {
                        passed  = false;
                        message = string.Empty;

                        if (selectedPolices[i] is CommentHeaderPolicy)
                        {
                            ((CommentHeaderPolicy)selectedPolices[i]).DayThreshold = 40;
                        }

                        Violation tmp = PolicyHelper.ValidateScriptAgainstPolicy(script, targetDatabase, selectedPolices[i]);

                        if (tmp == null)
                        {
                            passed = true;
                        }
                        else
                        {
                            message = tmp.Message;
                        }

                        PolicyMessage msg = new PolicyMessage(row.FileName, selectedPolices[i].ShortDescription, passed, message, row);
                        bg.ReportProgress(0, msg);
                    }
                }
            }
        }
Esempio n. 4
0
        public void ValidateScriptAgainstPolicyTest_WithIScriptPolicyWithArguments()
        {
            string script                     = Properties.Resources.PolicyHelper_WithViolations;
            string targetDatabase             = "TestDb";
            IScriptPolicyWithArguments policy = new StoredProcParameterPolicy();

            policy.Arguments.Add(new IScriptPolicyArgument()
            {
                Name = "Schema", Value = "dbo"
            });
            policy.Arguments.Add(new IScriptPolicyArgument()
            {
                Name = "Parameter", Value = "@MissingParameter"
            });
            policy.Arguments.Add(new IScriptPolicyArgument()
            {
                Name = "TargetDatabase", Value = "TestDb"
            });

            Violation actual;

            actual = PolicyHelper.ValidateScriptAgainstPolicy(script, targetDatabase, policy);
            Assert.IsNotNull(actual);
        }