Esempio n. 1
0
        private void CreateScratchArea()
        {
            var scratchDatabaseName = TestDatabaseNames.GetConsistentName("ScratchArea");

            DiscoveredDatabaseICanCreateRandomTablesIn = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(scratchDatabaseName);

            //if it already exists drop it
            if (DiscoveredDatabaseICanCreateRandomTablesIn.Exists())
            {
                DiscoveredDatabaseICanCreateRandomTablesIn.Drop();
            }

            //create it
            DiscoveredServerICanCreateRandomDatabasesAndTablesOn.CreateDatabase(scratchDatabaseName);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets an empty database on the test server of the appropriate DBMS
        /// </summary>
        /// <param name="type">The DBMS you want a server of (a valid connection string must exist in TestDatabases.txt)</param>
        /// <param name="dbnName">null for default test database name (recommended unless you are testing moving data from one database to another on the same test server)</param>
        /// <returns></returns>
        protected DiscoveredDatabase GetCleanedServer(DatabaseType type, string dbnName = null)
        {
            //the standard scratch area database
            var standardName = TestDatabaseNames.GetConsistentName("ScratchArea");

            //if user specified the standard name or no name
            var isStandardDb = dbnName == null || dbnName == standardName;

            //use the standard name if they haven't specified one
            dbnName ??= standardName;

            var server = type switch
            {
                DatabaseType.MicrosoftSQLServer => _discoveredSqlServer == null
                    ? null
                    : new DiscoveredServer(_discoveredSqlServer.Builder),
                DatabaseType.MySql => _discoveredMySqlServer == null
                    ? null
                    : new DiscoveredServer(_discoveredMySqlServer.Builder),
                DatabaseType.Oracle => _discoveredOracleServer == null
                    ? null
                    : new DiscoveredServer(_discoveredOracleServer.Builder),
                DatabaseType.PostgreSql => _discoveredPostgresServer == null
                    ? null
                    : new DiscoveredServer(_discoveredPostgresServer.Builder),
                _ => throw new ArgumentOutOfRangeException(nameof(type))
            };

            if (server == null)
            {
                Assert.Inconclusive();
            }

            //the microsoft one should exist! others are optional
            if (!server.Exists() && type != DatabaseType.MicrosoftSQLServer)
            {
                Assert.Inconclusive();
            }

            server.TestConnection();

            var database = server.ExpectDatabase(dbnName);

            if (database.Exists())
            {
                DeleteTables(database);
            }
            else
            {
                database.Create(true);
            }

            server.ChangeDatabase(dbnName);

            Assert.IsTrue(database.Exists());

            //if it had non standard naming mark it for deletion on cleanup
            if (!isStandardDb)
            {
                forCleanup.Add(database);
            }

            return(database);
        }