예제 #1
0
            private void WaitForConnection(TestDbContext.DbDriver driver, string connectionString)
            {
                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.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();
                        }
                    }
                }
            }