Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 799 Bytes

File metadata and controls

31 lines (24 loc) · 799 Bytes

PostgreSQL Container

Container to start a PostgreSQL Server container.

Example code

For more detailed examples, see our integration tests.

/*
 * default image is postgres:11-alpine 
 */
 
var container = new ContainerBuilder<PostgreSqlContainer>()
    .ConfigureDatabase(myUsername, mySaPassword, myDatabaseName)
    .Build();

using (var connection = new NpgsqlConnection(container.GetConnectionString()))
{
    await connection.OpenAsync();

    return await Record.ExceptionAsync(async () =>
    {
        using (var command = connection.CreateCommand())
        {
            command.CommandText = "SELECT 1";
            await command.ExecuteScalarAsync();
        }
    });
}