public void SaveTestSuite(string fileName) { _testSuite.Save(fileName); if (fileName != cboTests.SelectedItem.ToString()) { cboTests.Items.Remove(cboTests.SelectedItem); UpdateTestSelection(fileName); treeTest.Nodes[0].Text = fileName; } }
public void CreateNewTestSuiteTest() { string packageFile = UnpackToFile(TestPackageResource); var target = new SsisTestSuite(); Assert.AreEqual(0, target.ConnectionList.Count); target.ConnectionList.Add("AdventureWorks", new ConnectionRef("AdventureWorks", "Provider=SQLNCLI11;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=tempdb", ConnectionRef.ConnectionTypeEnum.ConnectionString)); Assert.AreEqual(1, target.ConnectionList.Count); Assert.AreEqual("AdventureWorks", target.ConnectionList["AdventureWorks"].ReferenceName); Assert.AreEqual("Provider=SQLNCLI11;Data Source=localhost;Integrated Security=SSPI;Initial Catalog=tempdb", target.ConnectionList["AdventureWorks"].ConnectionString); Assert.AreEqual(ConnectionRef.ConnectionTypeEnum.ConnectionString, target.ConnectionList["AdventureWorks"].ConnectionType); target.PackageList.Add("UT Basic Scenario", new PackageRef("UT Basic Scenario", packageFile, PackageStorageType.FileSystem)); target.TestSuiteSetup.Commands.Add(new SqlCommand(target, "AdventureWorks", false, "CREATE TABLE dbo.Test (ID INT)")); target.TestSuiteSetup.Commands.Add(new SqlCommand(target, "AdventureWorks", false, "INSERT INTO dbo.Test VALUES (1)")); target.TestSuiteSetup.Commands.Add(new SqlCommand(target, "AdventureWorks", false, "INSERT INTO dbo.Test VALUES (2)")); var sb = new StringBuilder(); sb.AppendLine("Test Line Count 1"); sb.AppendLine("Test Line Count 2"); sb.AppendLine("Test Line Count 3"); string path = GetTempPath("FileTest", true); string lineCountFile = CreateTempFile(path, "SourceFile.tst", sb.ToString()); var lineCount2File = GetTemporaryFileName(); var lineCount3File = GetTemporaryFileName(); target.SetupCommands.Commands.Add(new FileCommand(target, "Copy", lineCountFile, lineCount2File)); Assert.AreEqual(0, target.Tests.Count); var ssisTest = new Test(target, "Test", "UT Basic Scenario", null, "SELECT COUNT"); target.Tests.Add("Test", ssisTest); Assert.AreEqual(1, target.Tests.Count); Assert.AreEqual("Test", target.Tests["Test"].Name); Assert.AreEqual("UT Basic Scenario", target.Tests["Test"].PackageLocation); Assert.AreEqual("SELECT COUNT", target.Tests["Test"].Task); target.Tests["Test"].TestSetup.Commands.Add(new FileCommand(target, "Copy", lineCountFile, lineCount3File)); var ssisAssert = new SsisAssert(target, ssisTest, "Test Count", 2, false) { Command = new SqlCommand(target, "AdventureWorks", true, "SELECT COUNT(*) FROM dbo.Test") }; ssisTest.Asserts.Add("Test Count", ssisAssert); Assert.AreEqual(1, ssisTest.Asserts.Count); Assert.AreEqual("Test Count", ssisTest.Asserts["Test Count"].Name); Assert.AreEqual(2, ssisTest.Asserts["Test Count"].ExpectedResult); Assert.AreEqual(false, ssisTest.Asserts["Test Count"].TestBefore); Assert.AreEqual("<SqlCommand name=\"\" connectionRef=\"AdventureWorks\" returnsValue=\"true\">SELECT COUNT(*) FROM dbo.Test</SqlCommand>", ssisTest.Asserts["Test Count"].Command.PersistToXml()); ssisAssert = new SsisAssert(target, ssisTest, "Test File", true, false) { Command = new FileCommand(target, "Exists", lineCount2File, string.Empty) }; ssisTest.Asserts.Add("Test File", ssisAssert); ssisAssert = new SsisAssert(target, ssisTest, "Test File 2", true, false) { Command = new FileCommand(target, "Exists", lineCount3File, string.Empty) }; ssisTest.Asserts.Add("Test File 2", ssisAssert); target.Tests["Test"].TestTeardown.Commands.Add(new FileCommand(target, "Delete", lineCount3File, string.Empty)); // TODO: Add a TestRef test target.TeardownCommands.Commands.Add(new FileCommand(target, "Delete", lineCount2File, string.Empty)); target.TestSuiteTeardown.Commands.Add(new SqlCommand(target, "AdventureWorks", false, "DROP TABLE dbo.Test")); var saveFile = GetTemporaryFileName(); target.Save(saveFile); Assert.IsTrue(File.Exists(saveFile)); int testCount = target.Execute(); Assert.AreEqual(1, testCount); Assert.AreEqual(1, target.Statistics.GetStatistic(StatisticEnum.TestPassedCount)); Assert.AreEqual(4, target.Statistics.GetStatistic(StatisticEnum.AssertPassedCount)); Assert.AreEqual(0, target.Statistics.GetStatistic(StatisticEnum.AssertFailedCount)); Assert.IsFalse(File.Exists(lineCount2File)); // TODO: add ability to gracefully handle bad package refs - right now it blows the test case out of the water - no teardown target = new SsisTestSuite(saveFile); testCount = target.Execute(); Assert.AreEqual(1, testCount); Assert.AreEqual(1, target.Statistics.GetStatistic(StatisticEnum.TestPassedCount)); Assert.AreEqual(4, target.Statistics.GetStatistic(StatisticEnum.AssertPassedCount)); Assert.AreEqual(0, target.Statistics.GetStatistic(StatisticEnum.AssertFailedCount)); Assert.IsFalse(File.Exists(lineCount2File)); }