private static async Task <DbContextBuilder> InitializeDatabaseAsync(BotConfigService cfg) { Log.Information("Establishing database connection"); var dbb = new DbContextBuilder(cfg.CurrentConfiguration.DatabaseConfig); Log.Information("Testing database context creation"); using (TheGodfatherDbContext db = dbb.CreateContext()) { IEnumerable <string> pendingMigrations = await db.Database.GetPendingMigrationsAsync(); if (pendingMigrations.Any()) { Log.Information("Applying pending database migrations: {PendingDbMigrations}", pendingMigrations); await db.Database.MigrateAsync(); } } return(dbb); }
public async Task CanInsertDto() { var baseDto = new TphBaseDto() { Key = 7, Value = "test" }; var result = await _dao.TryInsertOrUpdateAsync(baseDto).ConfigureAwait(false); var loadAll = _dbContextBuilder.CreateContext().Set <TphBaseEntity>().ToList(); Assert.IsTrue(loadAll.Count == 1); Assert.IsTrue(loadAll.First().Key == 7); Assert.IsTrue(loadAll.First().Value == "test"); Assert.IsTrue(result is TphBaseDto); var tph1Dto = new Tph1Dto() { Key = 8, Value = "test", SpecificPropertyTph1 = 1 }; result = await _dao.TryInsertOrUpdateAsync(tph1Dto).ConfigureAwait(false); loadAll = _dbContextBuilder.CreateContext().Set <TphBaseEntity>().ToList(); Assert.IsTrue(loadAll.Count == 2); Assert.IsTrue(loadAll.Skip(1).First().Key == 8); Assert.IsTrue(loadAll.Skip(1).First().Value == "test"); Assert.IsTrue(result is Tph1Dto); Assert.IsTrue((result as Tph1Dto) !.SpecificPropertyTph1 == 1); var tph2Dto = new Tph2Dto() { Key = 9, Value = "test", SpecificPropertyTph2 = 2 }; result = await _dao.TryInsertOrUpdateAsync(tph2Dto).ConfigureAwait(false); loadAll = _dbContextBuilder.CreateContext().Set <TphBaseEntity>().ToList(); Assert.IsTrue(loadAll.Count == 3); Assert.IsTrue(loadAll.Skip(2).First().Key == 9); Assert.IsTrue(loadAll.Skip(2).First().Value == "test"); Assert.IsTrue(result is Tph2Dto); Assert.IsTrue((result as Tph2Dto) !.SpecificPropertyTph2 == 2); }
public async Task CanInsertDto() { var simpleDto = new SimpleDto { Key = 8, Value = "test" }; await _dao.TryInsertOrUpdateAsync(simpleDto).ConfigureAwait(false); var loadAll = _dbContextBuilder.CreateContext().Set <SimpleEntity>().ToList(); Assert.IsTrue(loadAll.Count == 1); Assert.IsTrue(loadAll.First().Key == 8); Assert.IsTrue(loadAll.First().Value == "test"); }