private UpdatesMetadata[] ReadUpdates(XNode xNode) { var runners = new List<UpdatesMetadata>(); // Add all sql runners foreach (var sqlRunnerXMl in xNode.XPathSelectElements("sqlRunner")){ var command = sqlRunnerXMl.Element("command"); var rollback = sqlRunnerXMl.Element("rollback"); var testData = sqlRunnerXMl.Element("testData"); var runner = new SqlRunner(GetSqlElement(command), GetSqlElement(rollback), GetSqlElement(testData)); var versions = new UpdatesMetadata( Convert.ToInt32(ReadAttribute(sqlRunnerXMl, "index")), ReadAttribute(sqlRunnerXMl, "createDate"), ReadAttribute(sqlRunnerXMl, "description"), ReadAttribute(sqlRunnerXMl, "createBy"), runner) { SkipTransaction = Convert.ToBoolean(ReadAttribute(sqlRunnerXMl, "skipTransaction") ?? "False") }; runners.Add(versions); } return runners.ToArray(); }
public DatabaseVersionSetup GetVersionSetup() { var versionSetup = new DatabaseVersionSetup(); mockSqlServerDatabaseProfile = new Mock<SqlServerDatabaseProfile>(MockBehavior.Strict, "Data Source=GMV-RW-LT;Initial Catalog=Intercontinental;Integrated Security=True" , "Intercontinental4" , "Intercontinental" , _mockITracker.Object); var profile = new DatabaseVersionSetup.Profile("Default", mockSqlServerDatabaseProfile.Object); profile.AddProperties("test1", "test1Prof|withvar|${dp.DatabaseName}|"); profile.AddProperties("test2", "test2"); profile.AddProperties("test2", "test2|over"); profile.AddProperties("insert", "insert.sql"); profile.AddProperties("update", "update.sql"); profile.AddProperties("delete", "delete.sql"); versionSetup.Profiles.Add(profile); var runner = new SqlRunner("CREATE DATABASE ${dp.DatabaseName};", "USE Master; DROP DATABASE ${dp.DatabaseName};"); var repository = new DatabaseRepository("Intercontinental", new UpdatesMetadata(1, "Todau", "Initialize", "rolf", runner)); repository.AddProperties("test0", "test0"); repository.AddProperties("test1", "test1"); var versions = new UpdatesMetadata(2, "2010-04-16", "First update", "Rolf Wessels", new SqlRunner( @"Create2 ${test0} ${test1} ${test2} ${test3}", @"RoleBack2 ${test0} ${test1} ${test2} ${test3}", @"TestData2 ${test0} ${test1} ${test2} ${test3}" ) ); repository.Updates.Add(versions); versions = new UpdatesMetadata(3, "2010-04-16", "First update", "Rolf Wessels", new SqlRunner( @"Create3 ${test0} ${test1} ${test2} ${test3}", @"RoleBack3 ${test0} ${test1} ${test2} ${test3}", @"TestData3 ${test0} ${test1} ${test2} ${test3}" ) ); repository.Updates.Add(versions); File.WriteAllText(@"resources\insert.sql", @"Create4 ${test0} ${test1} ${test2} ${test3}"); File.WriteAllText(@"resources\update.sql", @"RoleBack4 ${test0} ${test1} ${test2} ${test3}"); File.WriteAllText(@"resources\delete.sql", @"TestData4 ${test0} ${test1} ${test2} ${test3}"); repository.Updates.Add(new UpdatesMetadata(4, "2010-04-16", "First update", "Rolf Wessels", new SqlRunner(new SqlFilesExecuter(new[] { @"resources\${insert}" }), new SqlFilesExecuter(new[] { @"resources\${update}" }), new SqlFilesExecuter(new[] { @"resources\${delete}" })))); versionSetup.Repository.Add(repository); return versionSetup; }