GetUniqueIdentifier() public static method

public static GetUniqueIdentifier ( string prefix ) : string
prefix string
return string
Beispiel #1
0
        public void FailConnectThenSucceed()
        {
            var dbName = TestUtil.GetUniqueIdentifier(nameof(FailConnectThenSucceed));

            using (var conn1 = OpenConnection())
            {
                conn1.ExecuteNonQuery($"DROP DATABASE IF EXISTS \"{dbName}\"");
                try
                {
                    var connString = new NpgsqlConnectionStringBuilder(ConnectionString)
                    {
                        Database = dbName,
                        Pooling  = false
                    }.ToString();

                    using (var conn2 = new NpgsqlConnection(connString))
                    {
                        Assert.That(() => conn2.Open(),
                                    Throws.Exception.TypeOf <PostgresException>()
                                    .With.Property(nameof(PostgresException.SqlState)).EqualTo("3D000") // database doesn't exist
                                    );
                        Assert.That(conn2.FullState, Is.EqualTo(ConnectionState.Closed));

                        conn1.ExecuteNonQuery($"CREATE DATABASE \"{dbName}\" TEMPLATE template0");

                        conn2.Open();
                        conn2.Close();
                    }
                }
                finally
                {
                    //conn1.ExecuteNonQuery($"DROP DATABASE IF EXISTS \"{dbName}\"");
                }
            }
        }
Beispiel #2
0
        public void RollbackOnClose()
        {
            var tableName = TestUtil.GetUniqueIdentifier(nameof(RollbackOnClose));

            using (var conn1 = OpenConnection())
            {
                conn1.ExecuteNonQuery($"DROP TABLE IF EXISTS {tableName}");
                conn1.ExecuteNonQuery($"CREATE TABLE {tableName} (name TEXT)");

                NpgsqlTransaction tx;
                using (var conn2 = OpenConnection())
                {
                    tx = conn2.BeginTransaction();
                    conn2.ExecuteNonQuery($"INSERT INTO {tableName} (name) VALUES ('X')", tx);
                }
                Assert.That(tx.Connection, Is.Null);
                Assert.That(conn1.ExecuteScalar($"SELECT COUNT(*) FROM {tableName}"), Is.EqualTo(0));
            }
        }
Beispiel #3
0
 public void TransactionOnRecycledConnection()
 {
     // Use application name to make sure we have our very own private connection pool
     using (var conn = new NpgsqlConnection(ConnectionString + $";Application Name={TestUtil.GetUniqueIdentifier(nameof(TransactionOnRecycledConnection))}"))
     {
         conn.Open();
         var prevConnectorId = conn.Connector.Id;
         conn.Close();
         conn.Open();
         Assert.That(conn.Connector.Id, Is.EqualTo(prevConnectorId), "Connection pool returned a different connector, can't test");
         var tx = conn.BeginTransaction();
         conn.ExecuteScalar("SELECT 1");
         tx.Commit();
         NpgsqlConnection.ClearPool(conn);
     }
 }