Skip to content

How to see it in action

Stan B edited this page Apr 30, 2014 · 5 revisions

A few key unit tests to run

TopRule

Illustration of the rule that TOP clause of SQL statement must have parenthesis. First calls succeeds, second fails:

[TestMethod]
public void TopRule()
{
  var rule = new TopRule();
  IList<RuleProblem> problems;
  string sql;

  sql = "SELECT TOP(10) * FROM abc";
  problems = _engine.RunRules(sql, GetRuleRequest(Constants.Namespace, Constants.TopRuleId));
  Assert.AreEqual(0, problems.Count);

  sql = "SELECT TOP 10 * FROM abc";
  problems = _engine.RunRules(sql, GetRuleRequest(Constants.Namespace, Constants.TopRuleId));
  Assert.AreEqual(1, problems.Count);
}

NoCount rule - stored procedures must have SET NOCOUNT ON statement:

[TestMethod]
public void SetNoCountOnRule2()
{ 
  IList<RuleProblem> problems;
  string sql;
  sql = @"CREATE PROCEDURE dbo._Stored_Procedure_Template ( @Parameter_1 INT ) AS RETURN;";
  problems = _engine.RunRules(sql, GetRuleRequest(Constants.Namespace, Constants.SetNoCountOnRuleId)) ;
  Assert.AreEqual(1, problems.Count);
}

Run all rules for a given TSQL

[TestMethod]
public void RunAllRules()
{
  IList<RuleProblem> problems;
  string sql = "SELECT TOP 10 * FROM abc";
  problems = _engine.RunRules(sql, null);
}
Clone this wiki locally