public void StoredProcParameterPolicy_CheckPolicyTest_PassNoMatchingTargetDb() { StoredProcParameterPolicy target = new StoredProcParameterPolicy(); target.Arguments.Add(new IScriptPolicyArgument() { Name = "Schema", Value = "TestSchema" }); target.Arguments.Add(new IScriptPolicyArgument() { Name = "Parameter", Value = "@Hobo" }); target.Arguments.Add(new IScriptPolicyArgument() { Name = "SqlType", Value = "int" }); target.Arguments.Add(new IScriptPolicyArgument() { Name = "TargetDatabase", Value = "TestDb" }); string script = @"Select test FROM dbo.ItJustDoesntMatter"; string message = string.Empty; string targetDatabase = "MisMatch"; 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, targetDatabase, commentCollection, out message); Assert.AreEqual(messageExpected, message); Assert.AreEqual(expected, actual); }
public void StoredProcParameterPolicy_CheckPolicyTest_FailNoArgumentsSet() { StoredProcParameterPolicy target = new StoredProcParameterPolicy(); string script = @"It just doesn't matter"; string message = string.Empty; string messageExpected = "Missing \"Schema\", \"Parameter\" arguments in setup. Please check your Enterprise configuration"; 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 StoredProcParameterPolicy_CheckPolicyTest_FailWithMissingParameter() { StoredProcParameterPolicy target = new StoredProcParameterPolicy(); target.Arguments.Add(new IScriptPolicyArgument() { Name = "Schema", Value = "HumanResources" }); target.Arguments.Add(new IScriptPolicyArgument() { Name = "SqlType", Value = "int" }); target.Arguments.Add(new IScriptPolicyArgument() { Name = "Parameter", Value = "@EpicFail" }); string script = @"EXEC dbo.sp_executesql @statement = N' CREATE PROCEDURE [HumanResources].[uspUpdateEmployeeHireInfo] @EmployeeID [int], @Title [nvarchar](50), @HireDate [datetime], @RateChangeDate [datetime], @Rate [money], @PayFrequency [tinyint], @CurrentFlag [dbo].[Flag] WITH EXECUTE AS CALLER AS BEGIN SET NOCOUNT ON; BEGIN TRY BEGIN TRANSACTION; " ; string message = string.Empty; string messageExpected = "The parameter \"@EpicFail\" is required for all procedures in the \"HumanResources\" schema."; 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); }