Exemplo n.º 1
0
            private void WaitForConnection(TestDbContext.DbDriver driver, string connectionString)
            {
                if (!DatabaseEngines.Contains(driver))
                {
                    return;
                }

                var options   = TestDbContext.Configure(connectionString, driver);
                var startTime = DateTime.Now;

                while (DateTime.Now.Subtract(startTime) < TimeSpan.FromSeconds(200))
                {
                    bool          isSuccess = false;
                    TestDbContext context   = null;
                    Console.WriteLine("Connecting to " + driver);
                    try
                    {
                        context = new TestDbContext(options);
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();
                        _dataContexts[driver] = options;
                        isSuccess             = true;
                        Console.WriteLine(" - Connection Successful!");
                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(" - EXCEPTION: " + ex.Message);
                        System.Threading.Thread.Sleep(1000);
                        continue;
                    }
                    finally
                    {
                        if (!isSuccess)
                        {
                            context?.Dispose();
                        }
                    }
                }
            }
Exemplo n.º 2
0
            public Contexts()
            {
                _processes    = new Dictionary <TestDbContext.DbDriver, Process>();
                _dataContexts = new Dictionary <TestDbContext.DbDriver, DbContextOptions <TestDbContext> >();

                if (IsAppVeyor)
                {
                    WaitForConnection(TestDbContext.DbDriver.Postgres, AppVeyor_Postgres_Connection);
                    WaitForConnection(TestDbContext.DbDriver.MSSQL, AppVeyor_SqlServer_Connection);
                    WaitForConnection(TestDbContext.DbDriver.MySQL, AppVeyor_MySql_Connection);
                    WaitForConnection(TestDbContext.DbDriver.InMemory, InMemory_Connection);
                    WaitForConnection(TestDbContext.DbDriver.Sqlite, Sqlite_Connection);
                }
                else
                {
                    if (DatabaseEngines.Contains(TestDbContext.DbDriver.Postgres))
                    {
                        _processes[TestDbContext.DbDriver.Postgres] = Process.Start("docker",
                                                                                    $"run --name {Postgres_ImageName} --platform linux -e POSTGRES_USER={Username} -e POSTGRES_PASSWORD={Password} -e POSTGRES_DB={Username} -p {Postgres_Port}:5432 postgres:alpine");
                    }
                    if (DatabaseEngines.Contains(TestDbContext.DbDriver.MSSQL))
                    {
                        _processes[TestDbContext.DbDriver.MSSQL] = Process.Start("docker",
                                                                                 $"run --name {SqlServer_ImageName} --platform linux -e ACCEPT_EULA=Y -e MSSQL_PID=Express -e SA_PASSWORD={Password} -p {SqlServer_Port}:1433 microsoft/mssql-server-linux");
                    }
                    if (DatabaseEngines.Contains(TestDbContext.DbDriver.MySQL))
                    {
                        _processes[TestDbContext.DbDriver.MySQL] = Process.Start("docker",
                                                                                 $"run --name {MySql_ImageName} --platform linux -e MYSQL_ROOT_PASSWORD={Password} -e MYSQL_USER={Username} -e MYSQL_PASSWORD={Password} -e MYSQL_DATABASE={Username} -p {MySql_Port}:3306 mysql");
                    }

                    WaitForConnection(TestDbContext.DbDriver.Postgres, Postgres_Connection);
                    WaitForConnection(TestDbContext.DbDriver.MSSQL, SqlServer_Connection);
                    WaitForConnection(TestDbContext.DbDriver.MySQL, MySql_Connection);
                    WaitForConnection(TestDbContext.DbDriver.InMemory, InMemory_Connection);
                    WaitForConnection(TestDbContext.DbDriver.Sqlite, Sqlite_Connection);
                }
            }
 public DatabaseEngineNotImplementedException(DatabaseEngines Engine)
     : base("The database engine selected has not yet been implemented: " + Enum.GetName(typeof(DatabaseEngines), Engine))
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Get database engine
 /// </summary>
 /// <param name="serverType">Database server type</param>
 /// <returns>Return database engine</returns>
 public static IDatabaseEngine GetDatabaseEngine(DatabaseServerType serverType)
 {
     DatabaseEngines.TryGetValue(serverType, out var databaseEngine);
     return(databaseEngine);
 }