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 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);
        }