public void TestTableNameEndingInViewForDacpac() { 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)) { test.Target = RuleTest.AnalysisTarget.DacpacModel; test.DacpacPath = Path.Combine(TestContext.TestResultsDirectory, "TestTableNameEndingInViewForDacpac.dacpac"); 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"); }); } }
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"); }); } }