public void CheckPolicyTest_PassWithViolationInComment()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            target.LongDescription  = selectStarLongDesc;
            target.ShortDescription = selectStarShortDesc;
            target.Arguments        = selectStarLineException;
            target.ErrorMessage     = selectStarAsErrorMessage;

            string script          = @"IF EXISTS (SELECT zyx.* FROM vw_MyTestView xyz)
BEGIN
    -- SELECT * FROM MyTable
    SELECT top 5 col FROM MyTable
END
";
            string message         = string.Empty;
            string messageExpected = string.Empty;
            bool   expected        = true;
            bool   actual;

            System.Collections.Generic.List <System.Text.RegularExpressions.Match> commentCollection = ScriptHandling.ScriptHandlingHelper.GetScriptCommentBlocks(script);
            actual = target.CheckPolicy(script, commentCollection, out message);
            Assert.AreEqual(messageExpected, message);
            Assert.AreEqual(expected, actual);
        }
        public void PolicyIdTest()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();
            string actual;

            actual = target.PolicyId;
            Assert.AreEqual(target.PolicyId, actual);
        }
        public void ShortDescriptionTest()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();
            string expected = "My Short Desc";
            string actual;

            target.ShortDescription = expected;
            actual = target.ShortDescription;
            Assert.AreEqual(expected, actual);
        }
        public void LongDescriptionTest()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();
            string expected = "This is the long description of my policy";
            string actual;

            target.LongDescription = expected;
            actual = target.LongDescription;
            Assert.AreEqual(expected, actual);
        }
        public void ArgumentsTest()
        {
            ScriptSyntaxCheckPolicy      target   = new ScriptSyntaxCheckPolicy();
            List <IScriptPolicyArgument> expected = execAsArgsWithGlobalException;
            List <IScriptPolicyArgument> actual;

            target.Arguments = expected;
            actual           = target.Arguments;
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected[1].Value, actual[1].Value);
        }
        public void ErrorMessageTest()
        {
            string expected = "Here is my error";
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            target.ErrorMessage = expected;

            string actual;

            actual = target.ErrorMessage;
            Assert.AreEqual(expected, actual);
        }
        public void CheckPolicyTest_FailWithNoLineException()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            target.LongDescription  = selectStarLongDesc;
            target.ShortDescription = selectStarShortDesc;
            target.Arguments        = selectStarNoException;
            target.ErrorMessage     = selectStarAsErrorMessage;

            string script          = @"SELECT zyx.* FROM vw_MyTestView xyz";
            string message         = string.Empty;
            string messageExpected = "A SELECT * was found on line 1. This is not allowed.";
            bool   expected        = false;
            bool   actual;

            System.Collections.Generic.List <System.Text.RegularExpressions.Match> commentCollection = ScriptHandling.ScriptHandlingHelper.GetScriptCommentBlocks(script);
            actual = target.CheckPolicy(script, commentCollection, out message);
            Assert.AreEqual(messageExpected, message);
            Assert.AreEqual(expected, actual);
        }
        public void CheckPolicyTest_Pass()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            target.LongDescription  = execAsLongDesc;
            target.ShortDescription = execAsShortDesc;
            target.Arguments        = execAsArgsNoException;
            target.ErrorMessage     = execAsErrorMessage;

            string script          = @"SELECT test FROM dbo.MyTable";
            string message         = string.Empty;
            string messageExpected = string.Empty;
            bool   expected        = true;
            bool   actual;

            System.Collections.Generic.List <System.Text.RegularExpressions.Match> commentCollection = ScriptHandling.ScriptHandlingHelper.GetScriptCommentBlocks(script);
            actual = target.CheckPolicy(script, commentCollection, out message);

            Assert.AreEqual(messageExpected, message);
            Assert.AreEqual(expected, actual);
        }
        public void CheckPolicyTest_FailWithDropTable()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            target.LongDescription  = dropTableAsLongDesc;
            target.ShortDescription = dropTableAsShortDesc;
            target.Arguments        = dropTableArgsNoException;
            target.ErrorMessage     = dropTableErrorMessage;

            string script          = @"DROP TABLE MyTable

";
            string message         = string.Empty;
            string messageExpected = "DROP TABLE directive found on line 1. Please make sure this is reviewed prior to release.";
            bool   expected        = false;
            bool   actual;

            System.Collections.Generic.List <System.Text.RegularExpressions.Match> commentCollection = ScriptHandling.ScriptHandlingHelper.GetScriptCommentBlocks(script);
            actual = target.CheckPolicy(script, commentCollection, out message);
            Assert.AreEqual(messageExpected, message);
            Assert.AreEqual(expected, actual);
        }
        public void CheckPolicyTest_PassWithExecuteAsAndGlobalException()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            target.LongDescription  = execAsLongDesc;
            target.ShortDescription = execAsShortDesc;
            target.Arguments        = execAsArgsWithGlobalException;
            target.ErrorMessage     = execAsErrorMessage;

            string script          = @"USE AdventureWorks2008R2;
GO
CREATE PROCEDURE HumanResources.uspEmployeesInDepartment 
@DeptValue int
WITH EXECUTE AS OWNER
AS
    SET NOCOUNT ON;
    SELECT e.BusinessEntityID, c.LastName, c.FirstName, e.JobTitle
    FROM Person.Person AS c 
    INNER JOIN HumanResources.Employee AS e
        ON c.BusinessEntityID = e.BusinessEntityID
    INNER JOIN HumanResources.EmployeeDepartmentHistory AS edh
        ON e.BusinessEntityID = edh.BusinessEntityID
    WHERE edh.DepartmentID = @DeptValue
    ORDER BY c.LastName, c.FirstName;
GO
--EXECUTE AS Exception: Just testing
";
            string message         = string.Empty;
            string messageExpected = string.Empty;
            bool   expected        = true;
            bool   actual;

            System.Collections.Generic.List <System.Text.RegularExpressions.Match> commentCollection = ScriptHandling.ScriptHandlingHelper.GetScriptCommentBlocks(script);
            actual = target.CheckPolicy(script, commentCollection, out message);
            Assert.AreEqual(messageExpected, message);
            Assert.AreEqual(expected, actual);
        }
        public void ScriptSyntaxCheckPolicyConstructorTest()
        {
            ScriptSyntaxCheckPolicy target = new ScriptSyntaxCheckPolicy();

            Assert.IsNotNull(target);
        }