public RecommendationTestInput( RuleTest test, ProjectDefinition projectDefinition, OrchestratorSession session) { Test = test; ProjectDefinition = projectDefinition; Session = session; }
public static void Create(Process bwxProcess, Expert bwxExpert, Message bwxMsg) { RuleTest _bwxExpert = new RuleTest(); bwxProcess.PushExpert(_bwxExpert); MentalTask bwxTask = new Method(bwxProcess, bwxMsg); bwxProcess.ScheduleTask(bwxTask, _bwxExpert.CreateProc(bwxTask)); }
public async Task ReportedInCompilationUnit() { const string code = @" [|using Alpha; using System.Collections;|] "; await RuleTest.SingleErrorTestAsync(new UsingsMustBeSortedRule(sortSystemFirst : true), code, UsingsMustBeSortedRule.DiagnosticDescriptor); }
public async Task ReportedInNamespace() { const string code = @" namespace Foo { [|using System.Text; using Alpha;|] } "; await RuleTest.SingleErrorTestAsync(new UsingsMustBeSortedRule(sortSystemFirst : false), code, UsingsMustBeSortedRule.DiagnosticDescriptor); }
public object Test(RuleTest test) { test.FlowRule.Expression = test.FlowRule.Expression.TrimEnd('"').TrimStart('"'); string dummyId = "testId" + Guid.NewGuid().ToString().Replace("-", ""); var func = FuncCreator.GenerateFunction(dummyId, "source, target", test.FlowRule.Expression); Core.RegisterFlowScript(func); var pyFunc = Core.GetFlowFunction(dummyId); pyFunc(test.Source, test.Target); return(test.Target); }
public void Analyze_OneColumnOneIdentity_NoProblem() { var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE SCHEMA [dwh]", "schema"), Tuple.Create("CREATE TABLE dwh.Customer (CustomerId int identity(1,1))", "NoProblems.sql"), }; using(RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(IdentityColumnAnchor.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(0, problems.Count, "Expect 0 problem to have been found"); }); } }
public void Analyze_OneColumnTimeBased_NoProblem() { var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE SCHEMA [dwh]", "schema"), Tuple.Create("CREATE TABLE dwh.CustomerLink (c1 int, c2 int, DateId int)\r\nGO\r\nCREATE INDEX cx ON dwh.CustomerLink(DateId)", "NoProblems.sql"), }; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(TimeBasedColumnLink.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(0, problems.Count, "Expect 0 problem to have been found"); }); } }
public void Analyze_ColumnTimeBasedMissingIndex_OneProblem() { var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE SCHEMA [dwh]", "schema"), Tuple.Create("CREATE TABLE dwh.CustomerLink (c1 int, c2 int, DateId int)", "OneProblems.sql"), }; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(TimeBasedIndexLink.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual("OneProblems.sql", problems[0].SourceName, "Expect the source name to match where the problem was found"); Assert.AreEqual(1, problems[0].StartLine, "Expect the line to match where the problem was found"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }
public void Analyze_OneClusturedNotUnique_OneProblem() { var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE SCHEMA [dwh]", "schema"), Tuple.Create("CREATE TABLE dwh.Customer (c1 int identity(1,1))\r\nGO\r\nCREATE CLUSTERED INDEX ci ON dwh.Customer(c1)", "WithProblem.sql"), }; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(ClusturedIndexAnchor.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual("WithProblem.sql", problems[0].SourceName, "Expect the source name to match where the problem was found"); Assert.AreEqual(1, problems[0].StartLine, "Expect the line to match where the problem was found"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }
public void Analyze_OneColumnNoIdentity_OneProblem() { const string expectedProblemFile = "OneProblem.sql"; var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE SCHEMA [dwh]", "schema"), Tuple.Create("CREATE TABLE dwh.Customer (c1 int)", expectedProblemFile), }; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(IdentityColumnAnchor.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual(expectedProblemFile, problems[0].SourceName, "Expect the source name to match where the problem was found"); Assert.AreEqual(1, problems[0].StartLine, "Expect the line to match where the problem was found"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }
public void Analyze_ColumnTimeBasedMissingIndexWithConfig_OneProblem() { System.IO.File.Copy("Sample.config", "Tibre.CodeAnalysisRule.dll.config"); var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE TABLE dbo.FF_CustomerLinks (c1 int, c2 int, DateId int)", "OneProblems.sql"), }; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(TimeBasedIndexLink.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual("OneProblems.sql", problems[0].SourceName, "Expect the source name to match where the problem was found"); Assert.AreEqual(1, problems[0].StartLine, "Expect the line to match where the problem was found"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }
public void Analyze_OneColumnNoIdentityWithConfig_OneProblem() { System.IO.File.Copy("Sample.config", "Tibre.CodeAnalysisRule.dll.config"); const string expectedProblemFile = "OneProblem.sql"; var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE TABLE dbo.D_CustomerAnchor (c1 int)", expectedProblemFile), }; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(IdentityColumnAnchor.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual(expectedProblemFile, problems[0].SourceName, "Expect the source name to match where the problem was found"); Assert.AreEqual(1, problems[0].StartLine, "Expect the line to match where the problem was found"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }
private void RunTableNameEndingInViewTest(Action<RuleTest> configureTest) { var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE TABLE t1 (c1 int)", "NoProblems.sql"), Tuple.Create(@"CREATE TABLE [dbo].[NotAProblem] (c2 int) GO CREATE TABLE [dbo].[NotAView] (c3 int)", "OneProblem.sql") }; // When loading from a Dacpac the top-level object's name will be the source const string expectedProblemSource = "[dbo].[NotAView]"; using (RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { if(configureTest != null) { configureTest(test); } test.RunTest(TableNameEndingInViewRule.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual(expectedProblemSource, problems[0].SourceName, "Expect the source name to match the top-level object's name when analysing a dacpac source"); Assert.AreEqual(1, problems[0].StartLine, "Expect the top-level object to start at line 1 since it has been loaded in its own source script"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }
public void TestTableNameEndingInView() { const string expectedProblemFile = "OneProblem.sql"; var testScripts = new Tuple<string, string>[] { Tuple.Create("CREATE TABLE t1 (c1 int)", "NoProblems.sql"), Tuple.Create(@"CREATE TABLE [dbo].[NotAProblem] (c2 int) GO CREATE TABLE [dbo].[NotAView] (c3 int)", expectedProblemFile) }; using(RuleTest test = new RuleTest(testScripts, new TSqlModelOptions(), SqlServerVersion.Sql120)) { test.RunTest(TableNameEndingInViewRule.RuleId, (result, problemsString) => { var problems = result.Problems; Assert.AreEqual(1, problems.Count, "Expect 1 problem to have been found"); Assert.AreEqual(expectedProblemFile, problems[0].SourceName, "Expect the source name to match where the problem was found"); Assert.AreEqual(3, problems[0].StartLine, "Expect the line to match where the problem was found"); Assert.AreEqual(1, problems[0].StartColumn, "Expect the column to match where the problem was found"); }); } }