Пример #1
0
        /// <summary>
        /// Can connect to the database?
        /// </summary>
        /// <returns></returns>
        public static bool CanConnect()
        {
            var returnValue   = TypeExtension.DefaultBoolean;
            var configuration = new ConfigurationManagerCore(ApplicationTypes.Native);

            using (var connection = new SqlConnection(configuration.ConnectionStringValue("DefaultConnection")))
            {
                returnValue = connection.CanOpen();
            }
            return(returnValue);
        }
Пример #2
0
        public static void ClassInit(TestContext context)
        {
            // Database is required for these tests
            var databaseAccess = false;
            var configuration  = new ConfigurationManagerCore(ApplicationTypes.Native);

            using (var connection = new SqlConnection(configuration.ConnectionStringValue("DefaultConnection")))
            {
                databaseAccess = connection.CanOpen();
            }
            Assert.IsTrue(databaseAccess);
        }
Пример #3
0
        /// <summary>
        /// Removes EF code-first migration history table
        /// </summary>
        /// <param name="database"></param>
        /// <param name="schema"></param>
        public static void DropMigrationHistory(string database = "[FrameworkData]", string schema = "[Activity]")
        {
            // Must remove __MigrationHistory for EF Code First objects to auto-create their tables
            var configuration = new ConfigurationManagerCore(ApplicationTypes.Native);

            try
            {
                using (var connection = new SqlConnection(configuration.ConnectionStringValue("DefaultConnection")))
                {
                    using (var command = new SqlCommand("Drop Table " + database + "." + schema + ".[__MigrationHistory]", connection))
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException)
            {
                // Ignore connection errors
            }
        }