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 RecreateWithOpenConnectionAfterStartup() { /* * could be supported by running the following in wrapper CreateDatabaseFromTemplate * but it is fairly unlikely to happen and not doing the offline saves time in tests * * if db_id('{name}') is not null * begin * alter database [{name}] set single_user with rollback immediate; * alter database [{name}] set multi_user; * alter database [{name}] set offline; * end; */ LocalDbApi.StopAndDelete("RecreateWithOpenConnectionAfterStartup"); DirectoryFinder.Delete("RecreateWithOpenConnectionAfterStartup"); var wrapper = new Wrapper("RecreateWithOpenConnectionAfterStartup", DirectoryFinder.Find("RecreateWithOpenConnectionAfterStartup")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); var connectionString = await wrapper.CreateDatabaseFromTemplate("Simple"); using (var connection = new SqlConnection(connectionString)) { await connection.OpenAsync(); await wrapper.CreateDatabaseFromTemplate("Simple"); wrapper = new Wrapper("RecreateWithOpenConnectionAfterStartup", DirectoryFinder.Find("RecreateWithOpenConnection")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); } ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("RecreateWithOpenConnectionAfterStartup"); }
public async Task NoFileAndNoDb() { LocalDbApi.StopAndDelete("TestDbContext_EfNoFileAndNoDb"); var directory = DirectoryFinder.Find("TestDbContext_EfNoFileAndNoDb"); if (Directory.Exists(directory)) { Directory.Delete(directory, true); } var instance = new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), instanceSuffix: "EfNoFileAndNoDb"); 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 RecreateWithOpenConnection() { var name = "RecreateWithOpenConnection"; LocalDbApi.StopAndDelete(name); DirectoryFinder.Delete(name); Wrapper wrapper = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); var connectionString = await wrapper.CreateDatabaseFromTemplate("Simple"); await using (SqlConnection connection = new(connectionString)) { await connection.OpenAsync(); wrapper = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); } await Verifier.Verify(wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance(name); }
static WrapperTests() { LocalDbApi.StopAndDelete("WrapperTests"); instance = new Wrapper(s => new SqlConnection(s), "WrapperTests", DirectoryFinder.Find("WrapperTests")); instance.Start(timestamp, TestDbBuilder.CreateTable); instance.AwaitStart().GetAwaiter().GetResult(); }
public async Task WithFileAndNoInstance() { new SqlInstance("WithFileAndNoInstance", TestDbBuilder.CreateTable); LocalDbApi.StopAndDelete("WithFileAndNoInstance"); var instance = new SqlInstance("WithFileAndNoInstance", TestDbBuilder.CreateTable); await AddAndVerifyData(instance); }
public void Info() { LocalDbApi.CreateAndStart("InfoTest"); var info = LocalDbApi.GetInstance("InfoTest"); ObjectApprover.VerifyWithJson(info); LocalDbApi.StopAndDelete("InfoTest"); }
public void Run() { LocalDbApi.StopAndDelete("DanglingLogWrapperTests"); var instance = new Wrapper(s => new SqlConnection(s), "WrapperTests", DirectoryFinder.Find("DanglingLogWrapperTests")); base.Dispose(); instance.Start(DateTime.Now, TestDbBuilder.CreateTable); }
public async Task NoFileAndNoInstance() { LocalDbApi.StopAndDelete("NoFileAndNoInstance"); DirectoryFinder.Delete("NoFileAndNoInstance"); var instance = new SqlInstance("NoFileAndNoInstance", TestDbBuilder.CreateTable); await AddAndVerifyData(instance); }
public void Run() { var name = "DanglingLogWrapperTests"; LocalDbApi.StopAndDelete(name); Wrapper instance = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); instance.Start(DateTime.Now, TestDbBuilder.CreateTable); }
public void Info() { LocalDbApi.CreateAndStart("InfoTest"); var info = LocalDbApi.GetInstance("InfoTest"); ObjectApprover.Verify(info); LocalDbApi.StopAndDelete("InfoTest"); Assert.False(LocalDbApi.GetInstance("InfoTest").Exists); }
public async Task Info() { LocalDbApi.CreateAndStart("InfoTest"); var info = LocalDbApi.GetInstance("InfoTest"); await Verify(info); LocalDbApi.StopAndDelete("InfoTest"); Assert.False(LocalDbApi.GetInstance("InfoTest").Exists); }
public async Task NoFileAndNoInstance() { LocalDbApi.StopAndDelete("NoFileAndNoInstance"); DirectoryFinder.Delete("NoFileAndNoInstance"); var wrapper = new Wrapper("NoFileAndNoInstance", DirectoryFinder.Find("NoFileAndNoInstance")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("NoFileAndNoInstance"); }
public async Task NoFileAndWithInstance() { LocalDbApi.StopAndDelete("NoFileAndWithInstance"); LocalDbApi.CreateInstance("NoFileAndWithInstance"); DirectoryFinder.Delete("NoFileAndWithInstance"); var wrapper = new Wrapper(s => new SqlConnection(s), "NoFileAndWithInstance", DirectoryFinder.Find("NoFileAndWithInstance")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.AwaitStart(); await wrapper.CreateDatabaseFromTemplate("Simple"); await Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("NoFileAndWithInstance"); }
public async Task NoFileAndNoInstance() { var name = "NoFileAndNoInstance"; LocalDbApi.StopAndDelete(name); DirectoryFinder.Delete(name); Wrapper wrapper = new(s => new SqlConnection(s), name, DirectoryFinder.Find(name)); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); await Verifier.Verify(wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance(name); }
public async Task Callback() { var name = "WrapperTests_Callback"; var callbackCalled = false; Wrapper wrapper = new( s => new SqlConnection(s), name, DirectoryFinder.Find(name), callback : _ => { callbackCalled = true; return(Task.CompletedTask); }); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); Assert.True(callbackCalled); LocalDbApi.StopAndDelete(name); }
public async Task RecreateWithOpenConnection() { LocalDbApi.StopAndDelete("RecreateWithOpenConnection"); DirectoryFinder.Delete("RecreateWithOpenConnection"); var wrapper = new Wrapper("RecreateWithOpenConnection", DirectoryFinder.Find("RecreateWithOpenConnection")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); var connectionString = await wrapper.CreateDatabaseFromTemplate("Simple"); using (var connection = new SqlConnection(connectionString)) { await connection.OpenAsync(); wrapper = new Wrapper("RecreateWithOpenConnection", DirectoryFinder.Find("RecreateWithOpenConnection")); wrapper.Start(timestamp, TestDbBuilder.CreateTable); await wrapper.CreateDatabaseFromTemplate("Simple"); } ObjectApprover.Verify(await wrapper.ReadDatabaseState("Simple")); LocalDbApi.StopInstance("RecreateWithOpenConnection"); }
public async Task WithFileAndNoDb() { new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), instanceSuffix: "EfWithFileAndNoDb"); LocalDbApi.StopAndDelete("TestDbContext_EfWithFileAndNoDb"); var instance = new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), instanceSuffix: "EfWithFileAndNoDb"); 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 void DeleteInstance() { LocalDbApi.StopAndDelete(instance); System.IO.Directory.Delete(Directory, true); }
public void DeleteInstance() { LocalDbApi.StopAndDelete(instance); Directory.Delete(directory, true); }
public void DeleteInstance() { LocalDbApi.CreateAndStart("DeleteInstance"); LocalDbApi.StopAndDelete("DeleteInstance"); Assert.False(LocalDbApi.GetInstance("DeleteInstance").Exists); }