public void MigrationCanAddPostMigration() { var logger = Mock.Of <ILogger>(); var builder = Mock.Of <IMigrationBuilder>(); Mock.Get(builder) .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>())) .Returns <Type, IMigrationContext>((t, c) => { switch (t.Name) { case nameof(NoopMigration): return(new NoopMigration()); case nameof(TestMigration): return(new TestMigration(c)); case nameof(TestPostMigration): return(new TestPostMigration()); default: throw new NotSupportedException(); } }); var database = new TestDatabase(); var scope = Mock.Of <IScope>(); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); var sqlContext = new SqlContext(new SqlCeSyntaxProvider(), DatabaseType.SQLCe, Mock.Of <IPocoDataFactory>()); var scopeProvider = new MigrationTests.TestScopeProvider(scope) { SqlContext = sqlContext }; var plan = new MigrationPlan("Test") .From(string.Empty).To <TestMigration>("done"); TestMigration.MigrateCount = 0; TestPostMigration.MigrateCount = 0; new MigrationContext(database, logger); var upgrader = new Upgrader(plan); upgrader.Execute(scopeProvider, builder, Mock.Of <IKeyValueService>(), logger); Assert.AreEqual(1, TestMigration.MigrateCount); Assert.AreEqual(1, TestPostMigration.MigrateCount); }
public void Executes_For_Any_Product_Name_When_Not_Specified() { var logger = Mock.Of <ILogger>(); var changed1 = new Args { CountExecuted = 0 }; var post1 = new TestPostMigration(changed1); var posts = new PostMigrationCollection(new [] { post1 }); var builder = Mock.Of <IMigrationBuilder>(); Mock.Get(builder) .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>())) .Returns <Type, IMigrationContext>((t, c) => { switch (t.Name) { case "NoopMigration": return(new NoopMigration()); default: throw new NotSupportedException(); } }); var database = new TestDatabase(); var scope = Mock.Of <IScope>(); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); var sqlContext = new SqlContext(new SqlCeSyntaxProvider(), DatabaseType.SQLCe, Mock.Of <IPocoDataFactory>()); var scopeProvider = new MigrationTests.TestScopeProvider(scope) { SqlContext = sqlContext }; var u1 = new MigrationTests.TestUpgraderWithPostMigrations( new MigrationPlan("Test").From(string.Empty).To("done")); u1.Execute(scopeProvider, builder, Mock.Of <IKeyValueService>(), logger, posts); Assert.AreEqual(1, changed1.CountExecuted); }
public void CanExecute() { var logger = Mock.Of <ILogger>(); var database = new TestDatabase(); var scope = Mock.Of <IScope>(); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); var sqlContext = new SqlContext(new SqlCeSyntaxProvider(), DatabaseType.SQLCe, Mock.Of <IPocoDataFactory>()); var scopeProvider = new MigrationTests.TestScopeProvider(scope) { SqlContext = sqlContext }; var migrationBuilder = Mock.Of <IMigrationBuilder>(); Mock.Get(migrationBuilder) .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>())) .Returns <Type, IMigrationContext>((t, c) => { switch (t.Name) { case "DeleteRedirectUrlTable": return(new DeleteRedirectUrlTable(c)); case "NoopMigration": return(new NoopMigration()); default: throw new NotSupportedException(); } }); var plan = new MigrationPlan("default") .From(string.Empty) .To <DeleteRedirectUrlTable>("{4A9A1A8F-0DA1-4BCF-AD06-C19D79152E35}") .To <NoopMigration>("VERSION.33"); var kvs = Mock.Of <IKeyValueService>(); Mock.Get(kvs).Setup(x => x.GetValue(It.IsAny <string>())).Returns <string>(k => k == "Umbraco.Tests.MigrationPlan" ? string.Empty : null); string state; using (var s = scopeProvider.CreateScope()) { // read current state var sourceState = kvs.GetValue("Umbraco.Tests.MigrationPlan") ?? string.Empty; // execute plan state = plan.Execute(s, sourceState, migrationBuilder, logger); // save new state kvs.SetValue("Umbraco.Tests.MigrationPlan", sourceState, state); s.Complete(); } Assert.AreEqual("VERSION.33", state); Assert.AreEqual(1, database.Operations.Count); Assert.AreEqual("DROP TABLE [umbracoRedirectUrl]", database.Operations[0].Sql); }