Inheritance: IRunner
        public void SetUp()
        {
            MigrationTestHelper.Clear();
            _versionsFromDatabase = new List<long> { 0 };

            var provider = new Mock<IDataProvider>();
            provider.Setup(x => x.DatabaseKind).Returns(DatabaseKind.Oracle);

            var database = new Mock<IDatabase>();
            database.Setup(x => x.Provider).Returns(provider.Object);

            _dataClient = new Mock<IDataClient>();
            _dataClient.Setup(p => p.TableExists(VersionRepository.VERSION_TABLE_NAME)).Returns(true);
            _dataClient.Setup(x => x.Database).Returns(database.Object);

            _versionRepository = new Mock<IVersionRepository>();
            _versionRepository.Setup(x => x.GetCurrentVersion()).Returns(() => _versionsFromDatabase.Last());
            _versionRepository.Setup(x => x.GetAppliedMigrations()).Returns(() => _versionsFromDatabase);
            _versionRepository.Setup(x => x.InsertVersion(It.IsAny<MigrationInfo>()))
                .Callback<MigrationInfo>(m => _versionsFromDatabase.Add(m.Version));
            _versionRepository.Setup(x => x.RemoveVersion(It.IsAny<MigrationInfo>()))
                .Callback<MigrationInfo>(m => _versionsFromDatabase.Remove(m.Version));

            _runner = new Runner(_dataClient.Object, Assembly.GetExecutingAssembly());
            _runner.VersionRepository = _versionRepository.Object;
        }
Example #2
0
        public void SetUp()
        {
            MigrationTestHelper.Clear();

            var provider = new Mock<IDataProvider>();
            provider.Setup(x => x.DatabaseKind).Returns(DatabaseKind.Oracle);

            var database = new Mock<IDatabase>();
            database.Setup(x => x.Provider).Returns(provider.Object);

            _dataClient = new Mock<IDataClient>();
            _dataClient.Setup(p => p.TableExists(VersionRepository.VERSION_TABLE_NAME)).Returns(true);
            _dataClient.Setup(x => x.Database).Returns(database.Object);

            _version = 0;
            _versionRepository = new Mock<IVersionRepository>();
            _versionRepository.Setup(x => x.GetCurrentVersion()).Returns(() => _version);
            _versionRepository.Setup(x => x.UpdateVersion(It.IsAny<Int32>())).Callback<Int32>(v => _version = v);

            _runner = new Runner(_dataClient.Object, Assembly.GetExecutingAssembly());
            _runner.VersionRepository = _versionRepository.Object;
        }
Example #3
0
 private static void Run()
 {
     int version = _options.TargetVersion ?? -1;
     string mode = (_options.Mode ?? "manual").ToLower();
     if (mode == "script") {
         RunScript(version);
         return;
     }
     if (mode == "auto") {
         var runner = new Runner(SharpFactory.Default.CreateDataClient(), GetAssemblyWithMigrations());
         runner.MigrationGroup = _options.MigrationGroup;
         runner.Run(version);
         return;
     }
     if (mode == "seed") {
         if (String.IsNullOrEmpty(_options.SeedName)) {
             Exit("Please, set the seed name");
             return;
         }
         var seedRunner = new SeedRunner(SharpFactory.Default.CreateDataClient(), GetAssemblyWithMigrations());
         seedRunner.Run(_options.SeedName, _options.SeedArgs, _options.MigrationGroup);
         return;
     }
     var crunner = new ConsoleRunner(SharpFactory.Default.ConnectionString, SharpFactory.Default.DataProviderName);
     crunner.AssemblyWithMigrations = GetAssemblyWithMigrations();
     crunner.MigrationGroup = _options.MigrationGroup;
     crunner.Start();
 }