Example #1
0
    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"));
    }
Example #2
0
    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");
    }
Example #3
0
    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));
        }
    }
Example #4
0
    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);
    }
Example #5
0
 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();
 }
Example #6
0
    public async Task WithFileAndNoInstance()
    {
        new SqlInstance("WithFileAndNoInstance", TestDbBuilder.CreateTable);
        LocalDbApi.StopAndDelete("WithFileAndNoInstance");
        var instance = new SqlInstance("WithFileAndNoInstance", TestDbBuilder.CreateTable);

        await AddAndVerifyData(instance);
    }
Example #7
0
    public void Info()
    {
        LocalDbApi.CreateAndStart("InfoTest");
        var info = LocalDbApi.GetInstance("InfoTest");

        ObjectApprover.VerifyWithJson(info);
        LocalDbApi.StopAndDelete("InfoTest");
    }
Example #8
0
    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);
    }
Example #9
0
    public async Task NoFileAndNoInstance()
    {
        LocalDbApi.StopAndDelete("NoFileAndNoInstance");
        DirectoryFinder.Delete("NoFileAndNoInstance");

        var instance = new SqlInstance("NoFileAndNoInstance", TestDbBuilder.CreateTable);

        await AddAndVerifyData(instance);
    }
Example #10
0
    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);
    }
Example #11
0
    public void Info()
    {
        LocalDbApi.CreateAndStart("InfoTest");
        var info = LocalDbApi.GetInstance("InfoTest");

        ObjectApprover.Verify(info);
        LocalDbApi.StopAndDelete("InfoTest");
        Assert.False(LocalDbApi.GetInstance("InfoTest").Exists);
    }
Example #12
0
    public async Task Info()
    {
        LocalDbApi.CreateAndStart("InfoTest");
        var info = LocalDbApi.GetInstance("InfoTest");

        await Verify(info);

        LocalDbApi.StopAndDelete("InfoTest");
        Assert.False(LocalDbApi.GetInstance("InfoTest").Exists);
    }
Example #13
0
    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");
    }
Example #14
0
    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");
    }
Example #15
0
    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);
    }
Example #16
0
    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);
    }
Example #17
0
    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");
    }
Example #18
0
    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));
        }
    }
Example #19
0
 public void DeleteInstance()
 {
     LocalDbApi.StopAndDelete(instance);
     System.IO.Directory.Delete(Directory, true);
 }
Example #20
0
 public void DeleteInstance()
 {
     LocalDbApi.StopAndDelete(instance);
     Directory.Delete(directory, true);
 }
Example #21
0
 public void DeleteInstance()
 {
     LocalDbApi.CreateAndStart("DeleteInstance");
     LocalDbApi.StopAndDelete("DeleteInstance");
     Assert.False(LocalDbApi.GetInstance("DeleteInstance").Exists);
 }