Beispiel #1
0
        public void GetPoliciesTest_AddDynamicIScriptPolicies()
        {
            EnterpriseConfiguration cfg = new EnterpriseConfiguration();

            ScriptPolicy pol1 = new ScriptPolicy();

            pol1.PolicyId = PolicyIdKey.WithNoLockPolicy;
            pol1.Enforce  = true;

            ScriptPolicy pol2 = new ScriptPolicy();

            pol2.PolicyId = PolicyIdKey.GrantExecutePolicy;
            pol2.Enforce  = true;

            cfg.ScriptPolicy = new ScriptPolicy[] { pol1, pol2 };
            EnterpriseConfigHelper.EnterpriseConfig = cfg;

            List <IScriptPolicy> actual;

            actual = PolicyHelper.GetPolicies();

            Assert.IsTrue(actual.Count == 2, "Expected 2 policies but got " + actual.Count.ToString());
            Assert.IsTrue(actual[0] is WithNoLockPolicy);
            Assert.IsTrue(actual[1] is GrantExecutePolicy);
        }
Beispiel #2
0
        public void GetPoliciesTest_AddDynamicStoredProcParamPolicies()
        {
            EnterpriseConfiguration cfg = new EnterpriseConfiguration();

            ScriptPolicyArgument arg = new ScriptPolicyArgument();

            arg.Name  = "Schema";
            arg.Value = "dbo";

            ScriptPolicy pol1 = new ScriptPolicy();

            pol1.PolicyId = PolicyIdKey.StoredProcParameterPolicy;
            pol1.Enforce  = true;
            pol1.Argument = new ScriptPolicyArgument[] { arg };

            ScriptPolicy pol2 = new ScriptPolicy();

            pol2.PolicyId = PolicyIdKey.StoredProcParameterPolicy;
            pol2.Enforce  = true;
            pol2.Argument = new ScriptPolicyArgument[] { arg };

            cfg.ScriptPolicy = new ScriptPolicy[] { pol1, pol2 };
            EnterpriseConfigHelper.EnterpriseConfig = cfg;

            List <IScriptPolicy> actual;

            actual = PolicyHelper.GetPolicies();

            Assert.IsTrue(actual.Count == 2, "Expected 2 policies but got " + actual.Count.ToString());
            Assert.IsTrue(actual[0] is StoredProcParameterPolicy);
            Assert.IsTrue(actual[1] is StoredProcParameterPolicy);
        }
Beispiel #3
0
        public void GetPoliciesTest_GetStandardIScriptPolicy()
        {
            EnterpriseConfigHelper.EnterpriseConfig = new EnterpriseConfiguration();
            List <IScriptPolicy> actual;

            actual = PolicyHelper.GetPolicies();
            Assert.IsTrue(actual.Count == 9, "Expected 9 policies and got " + actual.Count.ToString());
            Assert.IsTrue(actual[0] is GrantExecutePolicy, "Expected GrantExecutePolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[1] is GrantExecuteToPublicPolicy, "Expected GrantExecuteToPublicPolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[2] is WithNoLockPolicy, "Expected WithNoLockPolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[3] is ReRunablePolicy, "Expected ReRunablePolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[4] is QualifiedNamesPolicy, "Expected QualifiedNamesPolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[5] is CommentHeaderPolicy, "Expected CommentHeaderPolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[6] is SelectStarPolicy, "Expected SelectStarPolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[7] is ViewAlterPolicy, "Expected ViewAlterPolicy got " + actual[0].GetType().ToString());
            Assert.IsTrue(actual[8] is ConstraintNamePolicy, "Expected ConstraintNamePolicy got " + actual[0].GetType().ToString());
        }
        private void PolicyForm_Load(object sender, EventArgs e)
        {
            if (this.buildData == null || this.buildData.Script == null)
            {
                MessageBox.Show("You need to have an open build project prior to running policy checks", "Project needed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Close();
            }

            List <IScriptPolicy> lstPol = PolicyHelper.GetPolicies();

            for (int i = 0; i < lstPol.Count; i++)
            {
                ListViewItem item = new ListViewItem(new string[] { lstPol[i].ShortDescription, lstPol[i].LongDescription });
                item.Checked = true;
                item.Tag     = lstPol[i];
                lstPolicies.Items.Add(item);
            }

            listSorter.CurrentColumn      = 2;
            listSorter.Sort               = SortOrder.Ascending;
            lstResults.ListViewItemSorter = listSorter;
            lstResults.Sort();
        }