Npgsql.Tests.TestUtil.MinimumPgVersion C# (CSharp) Method

MinimumPgVersion() public static method

public static MinimumPgVersion ( NpgsqlConnection conn, string minVersion, string ignoreText = null ) : void
conn NpgsqlConnection
minVersion string
ignoreText string
return void
        public static void MinimumPgVersion(NpgsqlConnection conn, string minVersion, string ignoreText=null)
        {
            var min = new Version(minVersion);
            if (conn.PostgreSqlVersion < min)
            {
                var msg = $"Postgresql backend version {conn.PostgreSqlVersion} is less than the required {min}";
                if (ignoreText != null)
                    msg += ": " + ignoreText;
                Assert.Ignore(msg);
            }
        }

Usage Example

示例#1
0
        public void DataTypeName_is_populated()
        {
            // On reading the source code for PostgreSQL9.3beta1, the only time that the
            // datatypename field is populated is when using domain types. So here we'll
            // create a domain that simply does not allow NULLs then try and cast NULL
            // to it.
            const string dropDomain    = @"DROP DOMAIN IF EXISTS public.intnotnull";
            const string createDomain  = @"CREATE DOMAIN public.intnotnull AS INT NOT NULL";
            const string castStatement = @"SELECT CAST(NULL AS public.intnotnull)";

            using var conn = OpenConnection();
            TestUtil.MinimumPgVersion(conn, "9.3.0", "5 error fields haven't been added yet");
            try
            {
                var command = new NpgsqlCommand(dropDomain, conn);
                command.ExecuteNonQuery();

                command = new NpgsqlCommand(createDomain, conn);
                command.ExecuteNonQuery();

                command = new NpgsqlCommand(castStatement, conn);
                //Cause the NOT NULL violation
                command.ExecuteNonQuery();
            }
            catch (PostgresException ex)
            {
                Assert.AreEqual("public", ex.SchemaName);
                Assert.AreEqual("intnotnull", ex.DataTypeName);
            }
        }
All Usage Examples Of Npgsql.Tests.TestUtil::MinimumPgVersion