public async void RunMigrations_Works() { await DropMigrationInfoTable(); await PrepareCounterTable(new List <Counter> { new Counter { Id = 123, CounterValue = 12 } }); var db = GetDb(); var services = new ServiceCollection(); var runner = new YoloMigrationRunner( services.BuildServiceProvider(), "staging", ConnectionString, A.Fake <IDistributedAppLockProvider>(), typeof(YoloMigrationRunnerTests).GetTypeInfo().Assembly ); await runner.UpgradeAsync(); // are all the migrations marked as completed? var migrationInfos = await GetAllMigrationInfo(); Assert.Contains(migrationInfos, x => x.Name == nameof(Migration01) && x.MigrationCompleted); Assert.Contains(migrationInfos, x => x.Name == nameof(Migration02) && x.MigrationCompleted); // check the state of the db var counter999 = await db.QuerySingleAsync <Counter>("select * from __Counter where Id = 123"); Assert.Equal("sample default value", counter999.Description); }
public async void RunMigration() { EnsureEmptyCollection <MigrationDocument>(); EnsureEmptyCollection <KewlEntity>(); var db = new MongoDbConnection(GetDb()); var services = new ServiceCollection(); var runner = new YoloMigrationRunner( services.BuildServiceProvider(), "staging", ConnectionString, GetDbName(), A.Fake <IDistributedAppLockProvider>(), typeof(YoloMigrationRunnerTests).GetAssembly() ); var storage = new MongoMigrationStorage(); var connectionProvider = new ConnectionProvider(); connectionProvider.Add("x", db, true); // setup some state var five = new KewlEntity { Reference = 5 }; await db.InsertAsync <KewlEntity>(five); var seven = new KewlEntity { Reference = 7 }; await db.InsertAsync <KewlEntity>(seven); // let's say that migration01 has already been completed await storage.MarkAsCompleteAsync(new MongoMigrationContext { ConnectionProvider = connectionProvider }, new Migration01(), 123); await runner.UpgradeAsync(); // are all the migrations marked as completed? var allDocs = GetAll <MigrationDocument>(); Assert.Contains(allDocs, x => x.Name == nameof(Migration01) && x.MigrationCompleted); Assert.Contains(allDocs, x => x.Name == nameof(Migration02) && x.MigrationCompleted); Assert.Contains(allDocs, x => x.Name == nameof(Migration03) && x.MigrationCompleted); // check the state of the db var fiveUp = await db.FirstOrDefaultAsync <KewlEntityUpdated>(x => x.Id == five.Id); Assert.Equal("5", fiveUp.Reference); Assert.Equal("Ulla Henriksen", fiveUp.Mucho); var sevenUp = await db.FirstOrDefaultAsync <KewlEntityUpdated>(x => x.Id == seven.Id); Assert.Equal("7", sevenUp.Reference); Assert.Equal("Bubbly", sevenUp.Mucho); }
public async void RunMigration() { await EnsureEmptyDb(); var db = redisMuxer.GetDatabase(); var services = new ServiceCollection(); services.AddSingleton <IConnectionMultiplexer>(redisMuxer); var runner = new YoloMigrationRunner( services.BuildServiceProvider(), "staging", A.Fake <IDistributedAppLockProvider>(), typeof(YoloMigrationRunnerTests).GetTypeInfo().Assembly ); // setup some state await db.StringSetAsync("five", "5"); await db.StringSetAsync("seven", "7"); // let's say that migration01 has already been completed var storage = new RedisMigrationStorage(); await storage.MarkAsCompleteAsync(new RedisMigrationContext { Container = new ServiceProviderRapidContainerAdapter(services.BuildServiceProvider()) }, new Migration01(), 123); await runner.UpgradeAsync(); // are all the migrations marked as completed? var migrationInfos = await GetAllMigrationInfos(); Assert.Equal(3, migrationInfos.Count); Assert.Contains(migrationInfos, x => x.Name == nameof(Migration01) && x.MigrationCompleted); Assert.Contains(migrationInfos, x => x.Name == nameof(Migration02) && x.MigrationCompleted); Assert.Contains(migrationInfos, x => x.Name == nameof(Migration03) && x.MigrationCompleted); // check the state of the db Assert.Equal("5 up", await db.StringGetAsync("five")); Assert.Equal("7 up", await db.StringGetAsync("seven")); Assert.Equal("OMG OMG OMG", await db.StringGetAsync("thirteen")); }