public async Task NoFileAndWithInstanceAndNamedDb() { var instanceName = "NoFileAndWithInstanceAndNamedDb"; LocalDbApi.StopAndDelete(instanceName); LocalDbApi.CreateInstance(instanceName); DirectoryFinder.Delete(instanceName); Wrapper wrapper = new(s => new SqlConnection(s), instanceName, DirectoryFinder.Find(instanceName)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); await wrapper.CreateDatabaseFromTemplate("Simple"); Thread.Sleep(3000); DirectoryFinder.Delete(instanceName); wrapper = new(s => new SqlConnection(s), instanceName, DirectoryFinder.Find(instanceName)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); await wrapper.CreateDatabaseFromTemplate("Simple"); await Verifier.Verify(wrapper.ReadDatabaseState("Simple")); }
public async Task NoFileAndWithDb() { LocalDbApi.CreateInstance("TestDbContext_EfNoFileAndWithDb"); var directory = DirectoryFinder.Find("EfNoFileAndWithDb"); if (Directory.Exists(directory)) { Directory.Delete(directory, true); } var instance = new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), instanceSuffix: "EfNoFileAndWithDb"); var entity = new TestEntity { Property = "prop" }; using (var database = await instance.Build(new List <object> { entity })) { Assert.NotNull(database.Context.TestEntities.FindAsync(entity.Id)); } }
public async Task NoFileAndWithInstance() { LocalDbApi.CreateInstance("NoFileAndWithInstance"); DirectoryFinder.Delete("NoFileAndWithInstance"); var instance = new SqlInstance("NoFileAndWithInstance", TestDbBuilder.CreateTable); await AddAndVerifyData(instance); }
public async Task NoFileAndWithInstance() { LocalDbApi.StopAndDelete("NoFileAndWithInstance"); LocalDbApi.CreateInstance("NoFileAndWithInstance"); DirectoryFinder.Delete("NoFileAndWithInstance"); var wrapper = new Wrapper("NoFileAndWithInstance", DirectoryFinder.Find("NoFileAndWithInstance")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); await wrapper.CreateDatabaseFromTemplate("Simple"); ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("NoFileAndWithInstance"); }
void InnerStart(DateTime timestamp, Func <SqlConnection, Task> buildTemplate) { void CleanStart() { FileExtensions.FlushDirectory(Directory); LocalDbApi.CreateInstance(instance); LocalDbApi.StartInstance(instance); startupTask = CreateAndDetachTemplate( timestamp, buildTemplate, rebuild: true, optimize: true); InitRollbackTask(); } var info = LocalDbApi.GetInstance(instance); if (!info.Exists) { CleanStart(); return; } if (!info.IsRunning) { LocalDbApi.DeleteInstance(instance); CleanStart(); return; } var templateLastMod = File.GetCreationTime(TemplateDataFile); if (timestamp == templateLastMod) { LocalDbLogging.Log("Not modified so skipping rebuild"); startupTask = CreateAndDetachTemplate(timestamp, buildTemplate, false, false); } else { startupTask = CreateAndDetachTemplate(timestamp, buildTemplate, true, false); } InitRollbackTask(); }
void InnerStart(DateTime timestamp, Action <SqlConnection> buildTemplate) { void CleanStart() { FileExtensions.FlushDirectory(directory); LocalDbApi.CreateInstance(instance); LocalDbApi.StartInstance(instance); RunOnceOfOptimizations(); CreateTemplate(); ExecuteBuildTemplate(buildTemplate); DetachTemplate(timestamp); } var info = LocalDbApi.GetInstance(instance); if (!info.Exists) { CleanStart(); return; } if (!info.IsRunning) { LocalDbApi.DeleteInstance(instance); CleanStart(); return; } PurgeDbs(); DeleteNonTemplateFiles(); var templateLastMod = File.GetCreationTime(TemplateDataFile); if (timestamp == templateLastMod) { LocalDbLogging.Log("Not modified so skipping rebuild"); return; } DeleteTemplateFiles(); CreateTemplate(); ExecuteBuildTemplate(buildTemplate); DetachTemplate(timestamp); }