Exemplo n.º 1
0
        public async Task Should_throw_if_no_path_found()
        {
            var migrator_0_1 = BuildMigration(0, 1);
            var migrator_2_3 = BuildMigration(2, 3);

            var migrator = new Migrator(status, new[] { migrator_0_1, migrator_2_3 }, log);

            await Assert.ThrowsAsync <InvalidOperationException>(migrator.MigrateAsync);

            A.CallTo(() => migrator_0_1.UpdateAsync()).MustNotHaveHappened();
            A.CallTo(() => migrator_2_3.UpdateAsync()).MustNotHaveHappened();

            A.CallTo(() => status.UnlockAsync(0)).MustHaveHappened();
        }
Exemplo n.º 2
0
        public async Task Should_prevent_multiple_updates()
        {
            var migrator_0_1 = BuildMigration(0, 1);
            var migrator_1_2 = BuildMigration(1, 2);

            var migrator = new Migrator(new InMemoryStatus(), new[] { migrator_0_1, migrator_1_2 }, log)
            {
                LockWaitMs = 2
            };

            await Task.WhenAll(Enumerable.Repeat(0, 10).Select(x => Task.Run(migrator.MigrateAsync)));

            A.CallTo(() => migrator_0_1.UpdateAsync()).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => migrator_1_2.UpdateAsync()).MustHaveHappened(Repeated.Exactly.Once);
        }
Exemplo n.º 3
0
        public async Task Should_migrate_step_by_step()
        {
            var migrator_0_1 = BuildMigration(0, 1);
            var migrator_1_2 = BuildMigration(1, 2);
            var migrator_2_3 = BuildMigration(2, 3);

            var migrator = new Migrator(status, new[] { migrator_0_1, migrator_1_2, migrator_2_3 }, log);

            await migrator.MigrateAsync();

            A.CallTo(() => migrator_0_1.UpdateAsync()).MustHaveHappened();
            A.CallTo(() => migrator_1_2.UpdateAsync()).MustHaveHappened();
            A.CallTo(() => migrator_2_3.UpdateAsync()).MustHaveHappened();

            A.CallTo(() => status.UnlockAsync(3)).MustHaveHappened();
        }
Exemplo n.º 4
0
        public async Task Should_migrate_step_by_step()
        {
            var migrator_0_1 = BuildMigration(0, 1);
            var migrator_1_2 = BuildMigration(1, 2);
            var migrator_2_3 = BuildMigration(2, 3);

            var migrator = new Migrator(status, new[] { migrator_0_1, migrator_1_2, migrator_2_3 }, log);

            await migrator.MigrateAsync();

            A.CallTo(() => migrator_0_1.UpdateAsync(A <IEnumerable <IMigration> > .That.IsEmpty())).MustHaveHappened();
            A.CallTo(() => migrator_1_2.UpdateAsync(A <IEnumerable <IMigration> > .That.IsSameSequenceAs(migrator_0_1))).MustHaveHappened();
            A.CallTo(() => migrator_2_3.UpdateAsync(A <IEnumerable <IMigration> > .That.IsSameSequenceAs(migrator_0_1, migrator_1_2))).MustHaveHappened();

            A.CallTo(() => status.UnlockAsync(3)).MustHaveHappened();
        }
Exemplo n.º 5
0
        public async Task Should_unlock_when_failed()
        {
            var migrator_0_1 = BuildMigration(0, 1);
            var migrator_1_2 = BuildMigration(1, 2);
            var migrator_2_3 = BuildMigration(2, 3);

            var migrator = new Migrator(status, new[] { migrator_0_1, migrator_1_2, migrator_2_3 }, log);

            A.CallTo(() => migrator_1_2.UpdateAsync()).Throws(new ArgumentException());

            await Assert.ThrowsAsync <ArgumentException>(migrator.MigrateAsync);

            A.CallTo(() => migrator_0_1.UpdateAsync()).MustHaveHappened();
            A.CallTo(() => migrator_1_2.UpdateAsync()).MustHaveHappened();
            A.CallTo(() => migrator_2_3.UpdateAsync()).MustNotHaveHappened();

            A.CallTo(() => status.UnlockAsync(1)).MustHaveHappened();
        }