Ejemplo n.º 1
0
        public RunnerTests()
        {
            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(), _versionRepository.Object);
        }
Ejemplo n.º 2
0
        public void Negative_target_version_means_last_version()
        {
            _runner.Run(-1);
            long maxVersion = VersionHelper.GetVersion(MigrationTestHelper.GetMigrations().Last());

            Assert.Equal(maxVersion, MigrationTestHelper.ExecutedMigrationsUp.Last().Version);
        }
Ejemplo n.º 3
0
        public void Go_up_and_down_twice()
        {
            _runner.Run(6);
            Assert.Equal(6, MigrationTestHelper.ExecutedMigrationsUp.Count);
            Assert.Equal(typeof(Migration6), MigrationTestHelper.ExecutedMigrationsUp.Last().GetType());
            MigrationTestHelper.Clear();

            _runner.Run(0);
            Assert.Equal(6, MigrationTestHelper.ExecutedMigrationsDown.Count);
            Assert.Equal(typeof(Migration1), MigrationTestHelper.ExecutedMigrationsDown.Last().GetType());
            MigrationTestHelper.Clear();

            _runner.Run(3);
            Assert.Equal(3, MigrationTestHelper.ExecutedMigrationsUp.Count);
            Assert.Equal(typeof(Migration3), MigrationTestHelper.ExecutedMigrationsUp.Last().GetType());
        }
Ejemplo n.º 4
0
        public void Should_expose_the_last_version_number()
        {
            var expectedLastVersion = VersionHelper.GetVersion(MigrationTestHelper.GetMigrations().Last());

            Assert.Equal(expectedLastVersion, _runner.LastVersionNumber);
        }
 public override void Down()
 {
     MigrationTestHelper.RegisterDown(this);
 }
 public override void Up()
 {
     MigrationTestHelper.RegisterUp(this);
 }