示例#1
0
        public virtual void TestFixtureSetup()
        {
            SetupLogging();

            var connStringEnvVar = "NPGSQL_TEST_DB_" + BackendVersion;

            _connectionString = Environment.GetEnvironmentVariable(connStringEnvVar);
            if (_connectionString == null)
            {
                if (BackendVersion == LatestBackendVersion)
                {
                    _connectionString = DEFAULT_CONNECTION_STRING;
                    Console.WriteLine("Using internal default connection string: " + _connectionString);
                }
                else
                {
                    Assert.Ignore("Skipping tests for backend version {0}, environment variable {1} isn't defined", BackendVersion, connStringEnvVar);
                    return;
                }
            }
            else
            {
                Console.WriteLine("Using connection string provided in env var {0}: {1}", connStringEnvVar, _connectionString);
            }

            if (!_schemaCreated)
            {
                try
                {
                    Conn = new NpgsqlConnection(ConnectionString);
                    Conn.Open();
                    CreateSchema();
                    Console.WriteLine("Schema created successfully. Backend version is " + Conn.PostgreSqlVersion);
                }
                catch (NpgsqlException e)
                {
                    try
                    {
                        if (Conn != null && Conn.State == ConnectionState.Open)
                        {
                            Conn.Close();
                        }
                    }
                    catch
                    {
                    }
                    if (e.Code == "3D000")
                    {
                        TestUtil.Inconclusive("Please create a database npgsql_tests, owned by user npgsql_tests");
                    }
                    else if (e.Code == "28P01")
                    {
                        TestUtil.Inconclusive(
                            "Please create a user npgsql_tests as follows: create user npgsql_tests with password 'npgsql_tests'");
                    }
                    else
                    {
                        throw;
                    }
                }
                catch
                {
                    try {
                        if (Conn != null && Conn.State == ConnectionState.Open)
                        {
                            Conn.Close();
                        }
                    }
                    catch {}
                    throw;
                }
            }
        }