public void TestExecuteScalar()
    {
        var options            = new UniqueDbConnectionProviderOptions("ws2012sqlexp1\\sqlexpress", "autodisposedatabase");
        var connectionProvider = new UniqueDbConnectionProvider(options);

        using (connectionProvider.ToSelfDeletingDisposable())
        {
            connectionProvider.CreateDatabase();
            connectionProvider.ExecuteScalar <int>("Select 1");
        }
    }
    public void TestExecute()
    {
        var options            = new UniqueDbConnectionProviderOptions("ws2012sqlexp1\\sqlexpress", "autodisposedatabase");
        var connectionProvider = new UniqueDbConnectionProvider(options);

        using (connectionProvider.ToSelfDeletingDisposable())
        {
            connectionProvider.CreateDatabase();
            connectionProvider.ExecuteNonDapper("Use [" + connectionProvider.DatabaseName + "]");
        }
    }
Ejemplo n.º 3
0
    public void CreateTableShouldWork()
    {
        ISqlConnectionProvider     sourceSqlConnectionProvider = null;
        UniqueDbConnectionProvider targetSqlConnectionProvider = null;
        SqlTableReference          sourceSqlTableReference     = null;
        SqlTableReference          targetSqlTableReference     = null;

        "Given a blank target database"
        ._(() =>
        {
            targetSqlConnectionProvider =
                new UniqueDbConnectionProvider(new UniqueDbConnectionProviderOptions(
                                                   "ws2012sqlexp1\\sqlexpress", "TableManipulationTests"));
            targetSqlConnectionProvider.CreateDatabase();
        });

        using (targetSqlConnectionProvider.ToSelfDeletingDisposable())
        {
            "Given a source database and a new blank database"
            ._(() =>
            {
                sourceSqlConnectionProvider = SqlConnectionProviders.AdventureWorksDb;
            });

            "Given a source table to copy"
            ._(() =>
            {
                sourceSqlTableReference = new SqlTableReference(
                    sourceSqlConnectionProvider, "Person.Person");
            });

            "When copying the source table to the target db."
            ._(() =>
            {
                targetSqlTableReference = new SqlTableReference(
                    targetSqlConnectionProvider, "dbo.Person");
                TableManipulation.CopyTableStructure(sourceSqlTableReference, targetSqlTableReference);
            });

            "Then there should be a copy of the table at the target DB"
            ._(() =>
            {
                var tableSchemas =
                    InformationSchemaMetadataExplorer.GetInformationSchemaTablesOnly(targetSqlConnectionProvider);
                tableSchemas.Count.Should().Be(1);
                tableSchemas[0].TABLE_NAME.Should().Be("Person");
            });
        }
    }
    public void ShouldDispose()
    {
        var options            = new UniqueDbConnectionProviderOptions("ws2012sqlexp1\\sqlexpress", "autodisposedatabase");
        var connectionProvider = new UniqueDbConnectionProvider(options);

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

        "Disposing of the disposable provided by the ToSelfDeletingDisposable extension method should delete the database"
        ._(() =>
        {
            using (var lifecycle = connectionProvider.ToSelfDeletingDisposable())
            {
                var result = connectionProvider.ExecuteScalar <int>("SELECT 1 ");
            }
        });
    }
Ejemplo n.º 5
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();
            });
        }
    }
Ejemplo n.º 6
0
    public void DropTableShouldWork()
    {
        ISqlConnectionProvider     sourceSqlConnectionProvider = null;
        UniqueDbConnectionProvider targetSqlConnectionProvider = null;
        SqlTableReference          sourceSqlTableReference     = null;
        SqlTableReference          targetSqlTableReference     = null;

        "Given a table to drop in the database."
        ._(() =>
        {
            targetSqlConnectionProvider =
                new UniqueDbConnectionProvider(new UniqueDbConnectionProviderOptions(
                                                   "ws2012sqlexp1\\sqlexpress", "TableManipulationTests"));
            targetSqlConnectionProvider.CreateDatabase();

            sourceSqlConnectionProvider = SqlConnectionProviders.AdventureWorksDb;
            sourceSqlTableReference     = new SqlTableReference(
                sourceSqlConnectionProvider, "Person.Person");
            targetSqlTableReference = new SqlTableReference(
                targetSqlConnectionProvider, "dbo.Person");
            TableManipulation.CopyTableStructure(sourceSqlTableReference, targetSqlTableReference);
            var tableSchemas =
                InformationSchemaMetadataExplorer.GetInformationSchemaTablesOnly(targetSqlConnectionProvider);
            tableSchemas.Count.Should().Be(1);
            tableSchemas[0].TABLE_NAME.Should().Be("Person");
        });

        using (targetSqlConnectionProvider.ToSelfDeletingDisposable())
        {
            "When dropping the target table."
            ._(() =>
            {
                TableManipulation.DropTable(targetSqlTableReference);
            });

            "Then the table should be removed from the database."
            ._(() =>
            {
                var tableSchemas =
                    InformationSchemaMetadataExplorer.GetInformationSchemaTablesOnly(targetSqlConnectionProvider);
                tableSchemas.Count.Should().Be(0);
            });
        }
    }
Ejemplo n.º 7
0
    public void IntegrationTest()
    {
        var databasePrefix = "OldDatabaseDeleterTests.IntegrationTest-" +
                             Guid.NewGuid().ToString("N").Substring(0, 8);
        UniqueDbConnectionProvider uniqueDbProvider1 = null;
        UniqueDbConnectionProvider uniqueDbProvider2 = null;

        "Given two databases created 7 seconds apart"
        ._(() =>
        {
            uniqueDbProvider1 = new UniqueDbConnectionProvider(new UniqueDbConnectionProviderOptions(
                                                                   TestingConstants.SqlServerInstance, databasePrefix));
            uniqueDbProvider1.CreateDatabase();

            Thread.Sleep(7000);

            uniqueDbProvider2 = new UniqueDbConnectionProvider(new UniqueDbConnectionProviderOptions(
                                                                   TestingConstants.SqlServerInstance, databasePrefix));
            uniqueDbProvider2.CreateDatabase();

            OldDatabaseDeleter.GetOldDatabasesFromUniqueDb(uniqueDbProvider1, TimeSpan.FromSeconds(0))
            .Count.Should()
            .Be(2);
        });


        "When we delete databases older than 7 seconds, we should delete the first of the two"
        ._(() =>
        {
            OldDatabaseDeleter.DeleteOldDatabases(uniqueDbProvider1, TimeSpan.FromSeconds(7));
            OldDatabaseDeleter.GetOldDatabasesFromUniqueDb(uniqueDbProvider2, TimeSpan.FromSeconds(0))
            .Count.Should()
            .Be(1);
        });

        "Now let's delete all the datbases to clean up"
        ._(() =>
        {
            uniqueDbProvider2.AndAutoDeleteDbOlderThan(TimeSpan.FromSeconds(0));
            OldDatabaseDeleter.GetOldDatabasesFromUniqueDb(uniqueDbProvider1, TimeSpan.FromSeconds(0))
            .Count.Should()
            .Be(0);
        });
    }
    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");
                }
            });
        }
    }