Item which computes which scripts have been run and not run
Inheritance: IMigrationTracker
Ejemplo n.º 1
0
 public void ExecutedMigrationsShouldBePopulated()
 {
     var migrations = new List<Migration> {
         new Migration("2006", "asdf", ""),
         new Migration("2006-01", "98sd98", ""),
         new Migration("2007", "fdsa", "") };
     var hash = new Dictionary<string, string>();
     foreach (var mig in migrations)
         hash.Add(mig.Version, mig.Hash);
     var db = new MigrationTracker(migrations, hash);
     Assert.AreEqual(3, db.ExecutedMigrations.Count());
 }
Ejemplo n.º 2
0
        public void MigrateToShouldExecuteDownTwice()
        {
            var migrations = new List<Migration> {
                new Migration("2006", "asdf", ""),
                new Migration("2006-01", "98sd98", ""),
                new Migration("2007", "fdsa", "") };
            var hash = new Dictionary<string, string>();
            foreach (var mig in migrations)
                hash.Add(mig.Version, mig.Hash);
            var db = new MigrationTracker(migrations, hash);
            var repoMoq = new Moq.Mock<IDatabaseRepository>();
            int y = 0;
            repoMoq.Setup(x => x.ExecuteDown(It.IsAny<Migration>())).Callback((Migration input) => { y++; });
            repoMoq.Setup(x => x.Create()).Returns(db);

            var migrator = new Migrator(db, repoMoq.Object);
            migrator.MigrateTo("2006");
            Assert.IsTrue(y== 2, "ExecuteDown should be called two times but is called " + y.ToString());
        }
Ejemplo n.º 3
0
 public void ShouldFindLastValidMigration()
 {
     var migrations = new List<Migration> { new Migration("2006", "asdf", ""), new Migration("2007", "fdsa", "") };
     var hash = new Dictionary<string, string>();
     foreach (var mig in migrations)
         hash.Add(mig.Version, mig.Hash);
     migrations.Insert(1, new Migration("2006-01", "fdsw", ""));
     var db = new MigrationTracker(migrations, hash);
     Assert.IsTrue(db.LastValidMigration.Version == "2006");
 }
Ejemplo n.º 4
0
 public void ShouldBeValidStateIfAllHashesAreTheSame()
 {
     var migrations = new[] {new Migration("2006", "asdf", ""), new Migration("2007", "fdsa", "")};
     var hash = new Dictionary<string, string>();
     foreach ( var mig in migrations)
         hash.Add(mig.Version, mig.Hash);
     var db = new MigrationTracker(migrations, hash);
     Assert.IsTrue(!db.IsHashMismatch());
     Assert.IsTrue(db.IsValidState());
 }
Ejemplo n.º 5
0
 public void AnEmptyHashListShouldReturnFalseForInvalidHash()
 {
     var migrations = new List<Migration> { new Migration("2006", "asdf", ""), new Migration("2007", "fdsa", "") };
     var db = new MigrationTracker(migrations, new Dictionary<string, string>());
     Assert.IsFalse(db.IsHashMismatch());
 }
Ejemplo n.º 6
0
 public void ShouldReturnAllMigrationsWhichResideInTheHash()
 {
     var migrations = new List<Migration> { new Migration("2006", "asdf", ""), new Migration("2007", "fdsa", "") };
     var hash = new Dictionary<string, string>();
     foreach (var mig in migrations)
         hash.Add(mig.Version, mig.Hash);
     migrations.Insert(1, new Migration("2006-01", "fdsw", ""));
     var db = new MigrationTracker(migrations, hash);
     Assert.IsTrue(db.ExecutedMigrations.Count() == 2);
 }
Ejemplo n.º 7
0
 public void ShouldNotThinkThereIsAGapWhenThereIsASingleMigration()
 {
     var migrations = new List<Migration> {
         new Migration("2006", "asdf", ""),
         new Migration("2006-01", "98sd98", ""),
         new Migration("2007", "fdsa", "") };
     var hashes = new Dictionary<string, string>();
     hashes.Add(migrations[0].Version, migrations[0].Hash);
     var db = new MigrationTracker(migrations, hashes);
     Assert.IsFalse(db.IsMigrationGap());
 }
Ejemplo n.º 8
0
 public void ShouldNotThinkThereIsAGapWhenThereAreNoMigrations()
 {
     var migrations = new List<Migration> {
         new Migration("2006", "asdf", ""),
         new Migration("2006-01", "98sd98", ""),
         new Migration("2007", "fdsa", "") };
     var db = new MigrationTracker(migrations, null);
     Assert.IsFalse(db.IsMigrationGap());
 }
Ejemplo n.º 9
0
 public void ShouldNotBeValidStateIfAnyHashIsDifferent()
 {
     var migrations = new[] { new Migration("2006", "asdf", ""), new Migration("2007", "fdsa", "") };
     var hash = new Dictionary<string, string>();
     foreach (var mig in migrations)
         hash.Add(mig.Version, mig.Hash);
     hash["2006"] = "222";
     var db = new MigrationTracker(migrations, hash);
     Assert.IsFalse(db.IsValidState());
 }
Ejemplo n.º 10
0
 public void ShouldNotBeValidIfThereIsAMigrationGap()
 {
     var migrations = new List<Migration> { new Migration("2006", "asdf", ""), new Migration("2007", "fdsa", "") };
     var hash = new Dictionary<string, string>();
     foreach (var mig in migrations)
         hash.Add(mig.Version, mig.Hash);
     migrations.Insert(1, new Migration("2006-01", "fdsw", ""));
     var db = new MigrationTracker(migrations, hash);
     Assert.IsFalse(db.IsValidState());
 }