Exemplo n.º 1
0
        /// <summary>
        /// Creates a throwaway database using the connection string provided.
        /// </summary>
        public static ThrowawayDatabase Create(string connectionString, string databaseNamePrefix = null)
        {
            if (!TryPingDatabase(connectionString))
            {
                throw new Exception("Could not connect to the database");
            }

            var database = new ThrowawayDatabase(connectionString, databaseNamePrefix);

            if (!database.CreateDatabaseIfDoesNotExist())
            {
                throw new Exception("Could not create the throwaway database");
            }

            return(database);
        }
        public static ThrowawayDatabase Create(string username, string password, string host, string databaseNamePrefix = null)
        {
            var connectionString = $"Host={host}; Username={username}; Password={password}; Port=5432; Database=postgres";

            if (!TryPingDatabase(connectionString))
            {
                throw new Exception("Could not connect to the database");
            }

            var database = new ThrowawayDatabase(connectionString, databaseNamePrefix);

            if (!database.CreateDatabaseIfDoesNotExist())
            {
                throw new Exception("Could not create the throwaway database");
            }

            return(database);
        }