Esempio n. 1
0
    public void ShouldDispose()
    {
        var options            = new UniqueDbConnectionProviderOptions("ws2012sqlexp1\\sqlexpress", "autodisposedatabase");
        var connectionProvider = new UniqueDbConnectionProvider(options);

        "After creating a database"
        ._(() => connectionProvider.CreateDatabase());

        using (var lifecycle = connectionProvider.ToSelfDeletingDisposable())
        {
            "Make sure the table doesn't exist"
            ._(() =>
            {
                var doesTableExist = connectionProvider.CheckTableExistence("dbo", "SimpleClass");
                doesTableExist.Should().BeFalse();
            });
            "Create the table"
            ._(() =>
            {
                connectionProvider.EnsureTableExists <SimpleClass>("dbo", "SimpleClass");
            });
            "Make sure the table does exist"
            ._(() =>
            {
                var doesTableExist = connectionProvider.CheckTableExistence("dbo", "SimpleClass");
                doesTableExist.Should().BeTrue();
            });
            "Truncate the table"
            ._(() =>
            {
                connectionProvider.TruncateTable("dbo", "SimpleClass");
            });

            "Delete the table"
            ._(() =>
            {
                connectionProvider.DropTable("dbo", "SimpleClass");
            });
            "Make sure the table doesn't exist"
            ._(() =>
            {
                var doesTableExist = connectionProvider.CheckTableExistence("dbo", "SimpleClass");
                doesTableExist.Should().BeFalse();
            });
        }
    }
    public void InsertSimpleClass()
    {
        var options            = new UniqueDbConnectionProviderOptions("ws2012sqlexp1\\sqlexpress", "autodisposedatabase");
        var connectionProvider = new UniqueDbConnectionProvider(options);

        "After creating a database"
        ._(() => connectionProvider.CreateDatabase());

        using (var lifecycle = connectionProvider.ToSelfDeletingDisposable())
        {
            BddStringExtensions._("Create the table", () =>
            {
                connectionProvider.EnsureTableExists <SimpleClass>("dbo", "SimpleClass");
            });
            BddStringExtensions._("Insert into the table", () =>
            {
                connectionProvider.Insert(SimpleClass.GetSample(), "SimpleClass");
            });
        }
    }
    public void SlowBulkInsertSimpleClass()
    {
        var options            = new UniqueDbConnectionProviderOptions("ws2012sqlexp1\\sqlexpress", "autodisposedatabase");
        var connectionProvider = new UniqueDbConnectionProvider(options);

        "After creating a database"
        ._(() => connectionProvider.CreateDatabase());

        using (var lifecycle = connectionProvider.ToSelfDeletingDisposable())
        {
            BddStringExtensions._("Create the table", () =>
            {
                connectionProvider.EnsureTableExists <SimpleClass>("dbo", "SimpleClass");
            });
            BddStringExtensions._("Insert into the table", () =>
            {
                var listOfSimpleClass = Enumerable.Range(0, 1000).Select(i => SimpleClass.GetSample()).ToList();
                foreach (var simpleClass in listOfSimpleClass)
                {
                    connectionProvider.Insert(simpleClass, "SimpleClass");
                }
            });
        }
    }