Exemple #1
0
        private static void RecreateSchemaAndInstallObjects()
        {
            using (var connection = ConnectionUtils.CreateMasterConnection())
            {
                bool databaseExists = connection.Query <bool?>(
                    @"select true :: boolean from pg_database where datname = @databaseName;",
                    new
                {
                    databaseName = ConnectionUtils.GetDatabaseName()
                }
                    ).SingleOrDefault() ?? false;

                if (!databaseExists)
                {
                    connection.Execute($@"CREATE DATABASE ""{ConnectionUtils.GetDatabaseName()}""");
                }
            }

            using (var connection = ConnectionUtils.CreateConnection())
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }

                PostgreSqlObjectsInstaller.Install(connection);
                PostgreSqlTestObjectsInitializer.CleanTables(connection);
            }
        }
Exemple #2
0
        private static void RecreateSchemaAndInstallObjects()
        {
            using (var connection = new NpgsqlConnection(
                       ConnectionUtils.GetMasterConnectionString()))
            {
                bool databaseExists = connection.Query <bool?>(
                    @"select true :: boolean from pg_database where datname = @databaseName;",
                    new
                {
                    databaseName = ConnectionUtils.GetDatabaseName()
                }
                    ).SingleOrDefault() ?? false;

                if (!databaseExists)
                {
                    connection.Execute(String.Format(@"CREATE DATABASE ""{0}""", ConnectionUtils.GetDatabaseName()));
                }
            }

            using (var connection = new NpgsqlConnection(
                       ConnectionUtils.GetConnectionString()))
            {
                PostgreSqlObjectsInstaller.Install(connection);
                PostgreSqlTestObjectsInitializer.CleanTables(connection);
            }
        }
        public void InstallingSchemaShouldNotThrowAnException()
        {
            Assert.DoesNotThrow(() =>
            {
                UseConnection(connection =>
                {
                    string schemaName = "hangfire_tests_" + System.Guid.NewGuid().ToString().Replace("-", "_").ToLower();

                    PostgreSqlObjectsInstaller.Install(connection, schemaName);

                    connection.Execute(string.Format(@"DROP SCHEMA ""{0}"" CASCADE;", schemaName));
                });
            });
        }
        public void InstallingSchemaShouldNotThrowAnException()
        {
            var ex = Record.Exception(() =>
            {
                UseConnection(connection =>
                {
                    string schemaName = "hangfire_tests_" + Guid.NewGuid().ToString().Replace("-", "_").ToLower();

                    PostgreSqlObjectsInstaller.Install(connection, schemaName);

                    connection.Execute($@"DROP SCHEMA ""{schemaName}"" CASCADE;");
                });
            });

            Assert.Null(ex);
        }
Exemple #5
0
        public void InstallingSchemaUpdatesVersionAndShouldNotThrowAnException()
        {
            var ex = Record.Exception(() =>
            {
                UseConnection(connection =>
                {
                    string schemaName = "hangfire_tests_" + Guid.NewGuid().ToString().Replace("-", "_").ToLower();

                    PostgreSqlObjectsInstaller.Install(connection, schemaName);

                    var lastVersion = connection.Query <int>(@"select version from """ + schemaName + @""".""schema""").Single();
                    Assert.Equal(12, lastVersion);

                    connection.Execute($@"DROP SCHEMA ""{schemaName}"" CASCADE;");
                });
            });

            Assert.Null(ex);
        }