コード例 #1
0
        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();
        }
コード例 #2
0
 public OnUpdateExecuteDeligateArgs(UpdatesMetadata metadata, string executecommand)
 {
     _updatesMetadata = metadata;
     _executecommand = executecommand;
 }
コード例 #3
0
 private void ExecuteRunner(UpdatesMetadata updatesMetadata, ITransaction transaction)
 {
     using (NDC.Push(string.Format("Update:{0}|", updatesMetadata.Index)))
     {
         InvokeOnUpdateExecute(new OnUpdateExecuteDeligateArgs(updatesMetadata, "ExecuteCommand"));
         Log.Info("Running: " + updatesMetadata);
         updatesMetadata.Runner.ExecuteCommand(_profile, transaction);
         if (_runTestData && updatesMetadata.Runner.HasTestData()){
             InvokeOnUpdateExecute(new OnUpdateExecuteDeligateArgs(updatesMetadata, "ExecuteTestData"));
             updatesMetadata.Runner.ExecuteTestData(_profile, transaction);
         }
     }
 }
コード例 #4
0
 private void ExecuteRollBack(UpdatesMetadata updatesMetadata, ITransaction transaction)
 {
     using (NDC.Push(string.Format("RollBack:{0}|", updatesMetadata.Index)))
     {
         if (updatesMetadata.Runner.HasRollback()){
             InvokeOnUpdateExecute(new OnUpdateExecuteDeligateArgs(updatesMetadata, "ExecuteRollback"));
             updatesMetadata.Runner.ExecuteRollback(_profile, transaction);
         }
     }
 }
コード例 #5
0
 public void Setup()
 {
     _databaseVersionSetup = new DatabaseVersionSetup();
     _mockIRepositoryProfile = new Mock<IRepositoryProfile>(MockBehavior.Strict);
     _databaseVersionSetup.DefaultProfile = DefaultProfile;
     var profile = new DatabaseVersionSetup.Profile(DefaultProfile, _mockIRepositoryProfile.Object);
     _mockITracker = new Mock<ITracker>(MockBehavior.Strict);
     _mockIDatabase = new Mock<IConnection>(MockBehavior.Strict);
     _mockITransaction = new Mock<ITransaction>(MockBehavior.Strict);
     _databaseVersionSetup.Profiles.Add(profile);
     _mockIRunner = new Mock<IRunner>(MockBehavior.Strict);
     var runner = new UpdatesMetadata(1, DateTime.MinValue.ToShortDateString(), "FirstUpdate", "Rolf", _mockIRunner.Object);
     _databaseVersionSetup.Repository.Add(new DatabaseRepository("Repo",runner));
     _mockIRepositoryProfile.Setup(mc => mc.DatabaseRepository)
         .Returns("Repo");
     _dvcController = new DvcController(_databaseVersionSetup, DefaultProfile, true);
 }
コード例 #6
0
        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;
        }