public void BringUpToDate_RunFullUpdate_ValuesAreReplaced()
        {
            var databaseVersionSetup = GetVersionSetup();
            var mockIDatabase = new Mock<IConnection>(MockBehavior.Strict);
            var mockITransaction = new Mock<ITransaction>(MockBehavior.Strict);
            mockIDatabase.Setup(mc => mc.GetTransaction()).Returns(mockITransaction.Object);
            mockIDatabase.Setup(mc => mc.SwitchToDatabase("Intercontinental4", mockITransaction.Object));
            _mockITracker.Setup(mc => mc.GetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), mockITransaction.Object)).Returns(0);
            mockIDatabase.Setup(mc => mc.ExecuteSql("Create2 test0 test1Prof|withvar|Intercontinental4| test2|over ${test3}", mockITransaction.Object)).Returns(1);
            mockIDatabase.Setup(mc => mc.ExecuteSql("Create3 test0 test1Prof|withvar|Intercontinental4| test2|over ${test3}", mockITransaction.Object)).Returns(1);
            mockIDatabase.Setup(mc => mc.ExecuteSql("Create4 test0 test1Prof|withvar|Intercontinental4| test2|over ${test3}", mockITransaction.Object)).Returns(1);
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 2, mockITransaction.Object));
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 3, mockITransaction.Object));
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 4, mockITransaction.Object));
            mockITransaction.Setup(mc => mc.Commit());
            mockITransaction.Setup(mc => mc.Dispose());
            mockSqlServerDatabaseProfile.Setup(mc => mc.GetDatabase()).Returns(mockIDatabase.Object);

            //act
            _dvcController = new DvcController(databaseVersionSetup, DefaultProfile, false);
            _dvcController.OnUpdateExecute += ((o, a) => Console.WriteLine(a.UpdatesMetadata.Description));
            _dvcController.BringUpToDate();
            mockSqlServerDatabaseProfile.VerifyAll();
            mockIDatabase.VerifyAll();
            mockITransaction.VerifyAll();
            _mockITracker.VerifyAll();
        }
        public void BringUpToDate_RunFullUpdate_UntilLastCall()
        {
            var databaseVersionSetup = GetVersionSetup();
            var mockIDatabase = new Mock<IConnection>(MockBehavior.Strict);
            var mockITransaction = new Mock<ITransaction>(MockBehavior.Strict);
            mockIDatabase.Setup(mc => mc.GetTransaction()).Returns(mockITransaction.Object);
            mockIDatabase.Setup(mc => mc.SwitchToDatabase("Intercontinental4", mockITransaction.Object));
            _mockITracker.Setup(mc => mc.GetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), mockITransaction.Object)).Returns(0);
            //mockIDatabase.Setup(mc => mc.ExecuteSql("valie ${test0} ${test1} ${test2} ${test3} ${test4} $test ", mockITransaction.Object)).Returns(1);
            mockIDatabase.Setup(mc => mc.ExecuteSql(It.IsAny<string>(), mockITransaction.Object)).Returns(1);
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 2, mockITransaction.Object));
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 3, mockITransaction.Object));
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 4, mockITransaction.Object));
            mockITransaction.Setup(mc => mc.Commit());
            mockITransaction.Setup(mc => mc.Dispose());
            mockSqlServerDatabaseProfile.Setup(mc => mc.GetDatabase()).Returns(mockIDatabase.Object);

            //act
            _dvcController = new DvcController(databaseVersionSetup, DefaultProfile, true);
            _dvcController.BringUpToDate();
            mockSqlServerDatabaseProfile.VerifyAll();
            mockIDatabase.VerifyAll();
            mockITransaction.VerifyAll();
            _mockITracker.VerifyAll();
        }
        public void Setup()
        {
            _controller = IntegrationTests.GetDvcControlller();
                try{
                    _controller.InitializeRollBack();
                }
                catch (Exception e) {
                    Console.Out.WriteLine("no database to rollback," + e.Message);

                }
                _controller.Initialize();
        }
        private DvcController GetController()
        {
            if (_controller == null){
                var loader = new XmlConfigFileLoader(XmlError,new FileSystemAccess());
                var setup = loader.Load(GetDefaultConfigFile(AppParam.UpdateFileName));
                var profileId = GetValueOrDefault(AppParam.ProfileId, setup.DefaultProfile);
                _controller = new DvcController(setup, profileId, AppParam.IncludeTest);
                _controller.CommitAfterEveryUpdate = AppParam.CommitAfterEveryUpdate;
                if (!AppParam.SuperSilent){
                    _controller.OnUpdateExecute += OutputEvent;
                    if (!AppParam.Silent){

                        _controller.Profile.RepositoryProfile.GetDatabase().OnSqlExecute += OutputSql;
                    }
                }
            }
            return _controller;
        }
 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);
 }
        public void RollbackIndexToIndex_RunFullUpdate_ValuesAreReplacedRoleBackPartial()
        {
            var databaseVersionSetup = GetVersionSetup();
            var mockIDatabase = new Mock<IConnection>(MockBehavior.Strict);
            var mockITransaction = new Mock<ITransaction>(MockBehavior.Strict);
            mockIDatabase.Setup(mc => mc.GetTransaction()).Returns(mockITransaction.Object);
            mockIDatabase.Setup(mc => mc.SwitchToDatabase("Intercontinental4", mockITransaction.Object));
            _mockITracker.Setup(mc => mc.GetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), mockITransaction.Object)).Returns(4);
            mockIDatabase.Setup(mc => mc.ExecuteSql("RoleBack4 test0 test1Prof|withvar|Intercontinental4| test2|over ${test3}", mockITransaction.Object)).Returns(1);
            mockIDatabase.Setup(mc => mc.ExecuteSql("RoleBack3 test0 test1Prof|withvar|Intercontinental4| test2|over ${test3}", mockITransaction.Object)).Returns(1);
            _mockITracker.Setup(mc => mc.SetVersion(It.IsAny<DatabaseVersionSetup.Profile>(), 2, mockITransaction.Object));
            mockITransaction.Setup(mc => mc.Commit());
            mockITransaction.Setup(mc => mc.Dispose());
            mockSqlServerDatabaseProfile.Setup(mc => mc.GetDatabase()).Returns(mockIDatabase.Object);

            //act
            _dvcController = new DvcController(databaseVersionSetup, DefaultProfile, true);
            _dvcController.RollbackIndexToIndex(3);
            mockSqlServerDatabaseProfile.VerifyAll();
            mockIDatabase.VerifyAll();
            mockITransaction.VerifyAll();
            _mockITracker.VerifyAll();
        }
        public void Initialize_InitializeCreate_ContainsVariableReplaces()
        {
            var databaseVersionSetup = GetVersionSetup();
            var mockIDatabase = new Mock<IConnection>(MockBehavior.Strict);
            var mockITransaction = new Mock<ITransaction>(MockBehavior.Strict);
            mockIDatabase.Setup(mc => mc.ExecuteSql("CREATE DATABASE Intercontinental4;", null)).Returns(1);
            //mockIDatabase.Setup(mc => mc.ExecuteSql(It.IsAny<string>(), mockITransaction.Object)).Returns(1).Callback((string o, ITransaction t) => Console.WriteLine(o));
            _mockITracker.Setup(mc => mc.AutoInitializeNewTracker).Returns(false);
            mockSqlServerDatabaseProfile.Setup(mc => mc.GetDatabase()).Returns(mockIDatabase.Object);

            //act
            _dvcController = new DvcController(databaseVersionSetup, DefaultProfile, true);
            _dvcController.Initialize();
            mockSqlServerDatabaseProfile.VerifyAll();
            mockIDatabase.VerifyAll();
            mockITransaction.VerifyAll();
            _mockITracker.VerifyAll();
        }
        public void InitializeRollBack_InitializeCreate_ContainsVariableReplaces()
        {
            var databaseVersionSetup = GetVersionSetup();
            var mockIDatabase = new Mock<IConnection>(MockBehavior.Strict);
            var mockITransaction = new Mock<ITransaction>(MockBehavior.Strict);
            mockIDatabase.Setup(mc => mc.ExecuteSql("USE Master; DROP DATABASE Intercontinental4;", null)).Returns(1);
            mockSqlServerDatabaseProfile.Setup(mc => mc.GetDatabase()).Returns(mockIDatabase.Object);

            //act
            _dvcController = new DvcController(databaseVersionSetup, DefaultProfile, true);
            _dvcController.InitializeRollBack();
            mockSqlServerDatabaseProfile.VerifyAll();
            mockIDatabase.VerifyAll();
            mockITransaction.VerifyAll();
            _mockITracker.VerifyAll();
        }